using namespace std ;
const int NumberOfPlants = 4;
void inputData(int a[],int lastPlantNUmber);
void scale(int a[],int size);
void graph(const int asteriskCount[],int lastPlantNumber);
void getTotal(int &sum);
double round(double number);
void printAsterisks(int n);
int main()
{
using namespace std;
int production[NumberOfPlants];
cout << "This program displays a graph showing\n"<< "production for each plant in the company. \n";
inputData(production , NumberOfPlants);
scale(production , NumberOfPlants);
graph(production, NumberOfPlants);
return 0;
}
void inputData(int a[], int lastPlantNumber)
{
for (int plantNumber = 1;plantNumber <= lastPlantNumber ; plantNumber ++)
{
cout << endl
<< "Enter production data for plant number "
<< plantNumber << endl ;
getTotal(a[plantNumber - 1]);
}
}
void getTotal(int &sum)
{
cout << "Enter number of units produced by each department.\n"
<< "append a negative number to the list.\n";
sum = 0;
int next;
cin >> next;
while (next >= 0)
{sum = sum +next;cin >> next;
}
cout << "Total = " << sum << endl;
}
void scale(int a[], int size)
{
for (int index = 0; index < size ;index++)
{
a[index] = round(a[index]/ 1000.0);
}
}
double round(double number)
{
return static_cast
}
void graph (const int asteriskCount[], int lastPlantNumber)
{
cout << "\nUnits produced in thousands of units:\n";
for (int plantNumber = 1 ; plantNumber <= lastPlantNumber ; plantNumber ++)
{
cout << "Plant #" << plantNumber << " ";
printAsterisks (asteriskCount[plantNumber - 1]);
cout << endl ;
}
}
void printAsterisks (int n)
{
for (int count = 1; count <= n; count ++)
{
cout << "*";
}研究一下,经常回来看看,函数可以直接将数组改变。