1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <iostream>
#include <cmath>
using namespace std;
const int NUMBEROFMONTHS = 12;
void readValue (int a[], int currentMonth); //input for the current month
void inputData (int a[], int lastMonth); //the previous month data. Also user can enter the current month rainfall
void scale (int a[], int size);
void graph (const int asteriskCount[], int lastMonth);
void getTotal (int& sum);
void printAsterisks (int n);
int main ()
{
int produce[NUMBEROFMONTHS];
cout << "This program displays the average rainfall for "
<<"current month and previous months" << endl;
cout << "The user will go by number for the months." << endl;
cout << "Rainfall data will be enter by whole numbers." << endl;
cout << "For example, the 7th month will be July. The user will only type in the average rainfall for month number 7." << endl;
readValue (produce, NUMBEROFMONTHS);
inputData (produce, NUMBEROFMONTHS);
scale (produce, NUMBEROFMONTHS);
graph (produce, NUMBEROFMONTHS);
return 0;
}
void readValue (int a[], int currentMonth)
{
if (currentMonth = 1)
{
cout << endl;
cout << "You will enter rainfall for current month later on." << endl;
cout << "Enter current month's number: ";
cin >> currentMonth;
}
}
void inputData (int a[], int lastMonth)
{
for(int month = 1; month <= lastMonth; month++)
{
cout << endl;
cout <<"Enter average rainfall in inches for Month #" << month << endl;
getTotal(a[month - 1]);
}
}
void getTotal (int& sum)
{
cout << "Append a negative number to go to the next month.\n";
sum = 0;
int next;
cin >> next;
while (next >= 0)
{
sum += next;
cin >> next;
}
}
void scale (int a[], int size)
{
for (int index = 0; index < size; index++);
}
void graph (const int asteriskCount[], int lastMonth)
{
char ans = 0;
cout << "Enter 'T' to see table or 'G' for graph: " << endl;
cin >> ans;
if ((ans == 'G' || ans == 'g'))
{
cout << " Average Rainfall in Inches: ";
for (int month = 1; month <= lastMonth; month++)
{
cout << "Month #" << month << " ";
printAsterisks(asteriskCount[month - 1]);
cout << endl;
}
}
else{
cout << "Table: " << endl;
}
}
void printAsterisks(int n)
{
for (int count = 1; count <= n; count++)
cout << "*";
}
| |