Question

In: Computer Science

Solve this problem using pointer variables for parameter passing, where appropriate and pointer arithmetic when working...

Solve this problem using pointer variables for parameter passing, where appropriate and pointer arithmetic when working with arrays

Please use the "C" program toProduce the EXACT output shown at the end of the document.

1.Generate a graph that compares, on a month-by-month basis, the monthly rainfall for Kamloops for the first half of 2018 (i.e. Jan – June) versus the normal (30 year average) rainfall for Kamloops for the same months.

  1. In main( ), create the 2 data arrays using initializations lists, and also create this array char *months[6] = { "January", "February", "March", "April", "May", "June" };   
  2. Create and call ONE function to print one line of symbols.
    • call it the first time to print the line of *
    • call it a second time to print the line of !
    • no if statement is needed or allowed in this function
    • Think very carefully about the parameter list for this function

  1. Call a function to print the scale and the legend as shown below.
  1. Call a function to find and print the total rainfall for each data set, and also the comparison of the two totals. The function will state whether 2018 was wetter, drier, or equal to a normal 6 month rainfall and by how much.
  1. Call a function to determine which month in 2018 had the highest rainfall, and print the month name (using the function described in #2), the rainfall amount and how that amount compares to the normal amount for that month.

Input will consist of 6 pairs of numbers representing the normal rainfall for the month and the 2018 rainfall amount for the same month. Use the exact data shown below when you run your program, (Note: the data and output below are for illustration purposes only. Your program must be able to work with any data that has this format)

  1. 3.1 5.4       ¬ January data (normal first, then 2018)
  2. 4.7 4.4      ¬ February data
  3. 4.2 4.1
  4. 5.0   6.0
  5. 4.0   5.6
  6. 6.3    4.5

Rainfall comparison for January to June 2018

       January    |***********

|!!!!!!!!!!!!!!!!!!!!!!!!!

|  

   February |***************

|!!!!!!!!!!!!!!!!!!!!!

|

   March | etc for the rest of the months

|  

       

June |*****************

|!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

|----1----2----3----4----5----6----7----8

LEGEND:

* - normal rainfall for a given month

! - 2018 rainfall for a given month

Total normal rainfall was xx.x mm.

Total rainfall for 2018 was yy.y mm.

2018 was a drier year than normal by z.z mm. (or print wetter or equal if that is appropriate)

The month in 2018 with the highest rainfall was …

Solutions

Expert Solution

IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE THERE TO HELP YOU

ANSWER:

CODE:

#include<stdio.h>

// one function to print the lines of symbols
void oneFunction(double *rainAmt, char c) {
int size=(*rainAmt)/0.2;
for (int i = 0; i < size; i++) {
printf("%c", c);
}
}

// Function to call scale and legend
void scaleAndLegend() {

//Generates the ruler at the bottom of the scale.
printf("%-19s|----1----2----3---4----5----6----7----8 ", "");

//Generates legend at the end of scale.
printf(" Legend ");
printf(" ");
printf(" * - Normal rainfall for a given month. ");
printf(" ");
printf(" ! - 2018 rainfall for a given month. ");


}

double total(double *a, int *size) {
double sum = 0;
for (int i = 0; i < (*size); i++) {
sum += *(a + i);
}
return sum;
}

//printing the comparison of the two totals
void printComparison(double *monthlyRainF, double *rainAmount2018, int *size) {

//calculating the total normal rainfall
double previousYear = total(monthlyRainF, size);

//Calculating the total 2018 rainfall
double currentYear = total(rainAmount2018, size);
printf(" Total normal rainfall was %.2lfmm. ", previousYear);
printf(" ");
printf(" Total rainfall for 2018 was %.2lfmm. ", currentYear);
printf(" ");
//Finding the wetter or drier year with if else statement
double wetterOrDrier = previousYear - currentYear;
if (wetterOrDrier < 0) {
printf(" 2018 was the drier year than normal by %.2lfmm. ", (-1 * wetterOrDrier));
} else {
printf(" 2018 was a wetter year than normal by %.2lfmm. ", wetterOrDrier);
}
}
//calculation of the highest rainfall
int highestRainfall(double *a, int *size) {
int hRF = 0;
for (int i = 1; i < (*size); i++) {
if (a[i] > a[hRF]) {
hRF = i;
}
}
return hRF;
}
//========================

int main() {

// Variable for total rainfall
double rainAmt2018;

//initialization lists for the normal rainfall, total rainfall and months.
double monthlyRainF[] = {3.1, 4.7, 4.2, 5.0, 4.0, 6.3};
double rainAmount2018[] = {5.4, 4.4, 4.1, 6.0, 5.6, 4.5};
char month[6][10] = {"January", "February", "March", "April", "May", "June"};

double previousYear = 0;
double currentYear = 0;

//size
int s = 6;

//Title for the beginning of the graph
printf(" Rainfall comparison for January to June 2018 ");
printf(" ");

//graph generating the rainfall comparison
for (int i = 0; i < s; i++) {
printf("%10s", month[i]);
printf("%10c", '|');

//representing the indentation for graph format and given rainfall for months
oneFunction(monthlyRainF + i, '*');
printf(" ");
printf("%20c", '|');
oneFunction(rainAmount2018 + i, '!');
printf(" ");
printf("%20c", '|');
printf(" ");
}

//Displaying the legend by calling the functions made at the beginning
scaleAndLegend();
printf(" ");
printComparison(monthlyRainF, rainAmount2018, &s);
printf(" ");

//Calculating the month with the highest rain fall
int highestRF;
float highest;
highestRF = highestRainfall(rainAmount2018, &s);
highest = rainAmount2018[highestRF];

//Displaying the normal rainfall and 2018 rainfall
printf(" The month with the highest rainfall was %s at %.1fmm", month[highestRF], highest);
printf(" ");
printf(" ");


}

RATE THUMBSUP PLEASE


Related Solutions

Purpose Review and reinforcement of pointers, dynamic memory allocation, pointer arithmetic, passing pointers to a function,...
Purpose Review and reinforcement of pointers, dynamic memory allocation, pointer arithmetic, passing pointers to a function, returning a pointer by a function, dangling pointer, and memory deallocation, pointer initialization, and struct data type. Project description In this project, you will create a database of employees of an organization while meeting the requirements described below. Your program MUST NOT interact with the user to receive inputs, so that the instructor and/or the teaching assistant can save a big time in testing...
Discuss what we mean by pointer arithmetic and give some examples. Discuss the relationship between passing...
Discuss what we mean by pointer arithmetic and give some examples. Discuss the relationship between passing arrays to a function and using pointers to pass an array to a function.
Create and solve a population proportion for this parameter. Gather appropriate data and post your problem....
Create and solve a population proportion for this parameter. Gather appropriate data and post your problem. Include the null and alternative hypothesis, alpha value, p-value, and a conclusion. Make sure that you use appropriate terminology, specify whether you are using the classical method or the p-value method, and fully explain your solution. “A survey at a local school has revealed that 223 of its students own a smartphone, and that 90 of those 223 students own an iPhone. Test this...
For each problem below, state the distribution, list the parameter values and then solve the problem....
For each problem below, state the distribution, list the parameter values and then solve the problem. You may use Excel to solve but you still need to list the distribution name and parameter value(s). For example: Poisson distribution, x=5, ?=0.24, P(5; 0.24) = 0.78 a) A skeet shooter hits a target with probability 0.5. What is the probability that they will hit at least four of the next five targets? b) You draw a random sample of 15 first graders...
Solve the LP problem using graphical method. Determine the optimal values of the decision variables and...
Solve the LP problem using graphical method. Determine the optimal values of the decision variables and compute the objective function. Maximize Z = 2A + 10B Subject to 10A + 4B ≥ 40    A + 6B ≥ 24                A + 2B ≤ 14    A, B  ≥ 0 with soln pls thank you!
Using the method of separation of variables and Fourier series, solve the following heat conduction problem...
Using the method of separation of variables and Fourier series, solve the following heat conduction problem in a rod. ∂u/∂t =∂2u/∂x2 , u(0, t) = 0, u(π, t) = 3π, u(x, 0) = 0
Using C++ Use dynamic allocation and functions (using pointer variables only) to read the names from...
Using C++ Use dynamic allocation and functions (using pointer variables only) to read the names from the .txt file and sort the names in lexical order Grumpy Dopey Doc Happy Bashful Sneezy Sleepy
For each of the following studies, identify both the parameter and the statistic using the appropriate...
For each of the following studies, identify both the parameter and the statistic using the appropriate notation. a. A sociologist wants to know the proportion of adults with children under the age of 18 that eat dinner together 7 nights a week. A simple random sample of 1122 adults with children under the age of 18 was obtained, and 337 of those adults reported eating dinner together with their families 7 nights a week. b. A school administrator wants to...
Give two examples explaining where using conservation of energy to solve a problem is easier than...
Give two examples explaining where using conservation of energy to solve a problem is easier than other the methods. Explain how you would use energy to solve the problem and why it is easier. 75-150
Some languages support many modes of parameter passing. Provide 2 examples using two different programming languages...
Some languages support many modes of parameter passing. Provide 2 examples using two different programming languages which support the user of the programming language deciding which to use when creating their method. (Programming Languages)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT