Re: function, fstream

Beginners
Need answers urgently for my revision as exams is tomorrow ...PLEASE!
Read the materials but still don't get it

[code + question]
rainfall.txt
12, 30, 10, 5, 17, 15, 22, 12, 11, 16, 0, 21

const int ARRAYSIZE=12;
int main()
{
int rain[ARRAYSIZE];
double sum, average, stddev;
int min=0;
ifstream infile;

TellUser();//tell user what program does
infile.open("C:\\rainfall.txt");
if (infile.fail())
cout <<"Bad file" << endl;
else
{
getRain(infile, rain); //read input file & populate array

sum = calc_Total_Rain(rain);
cout << "The total rainfall for the year is: " << sum << endl;

min = computeMin(rain);
cout << "The minimum rainfall for the year is: " << min << endl;

average = find_AveRainfall(rain);
cout << "Average rainfall= " << average << endl;

stddev = standardDeviation(average, rain);
cout << "Standard Deviation = " << stddev << endl;
}

return 0;
}

Question 1
Write the missing code to compute the function getRainfall(), that reads in the
twelve values from the file rainfall.txt and stores it in the array rain.
rainfall.txt
12, 30, 10, 5, 17, 15, 22, 12, 11, 16, 0, 21
---
void getRainfall(ifstream &infile, int rain)
{
xxxxx
}

Question 2
write the missing code to complete the function calc-Total_Rain(), that sums up
the twelve values stored in the array rain

double calc_Total_Rain(int rain[]){
xxxxxxx
}

Question 3
Write the missing code to complete the function computeMin() that finds the minimum value that stored in the array rain

int computeMin(int rain[]){
xxxxxx
}
Can someone help me out please...
1. while loop with getline using a delimiter
http://www.cplusplus.com/reference/string/string/getline/

2. for loop 0 to size of the array
Convert an int to a double by multiplying with 1.0

3. for loop 0 to size of the array
keep the smallest value in a local variable
return the local variable
Topic archived. No new replies allowed.