33,311
社区成员
发帖
与我相关
我的任务
分享
//Fig 6.7 sales
//member functions for class SalesPerson
#include<iostream> // ----------------------------现在一般都用using namespace std
#include<iomanip>
#include"salesp.h"
using namespace std;
//constructor functioninitializes array
SalesPerson::SalesPerson()
{
for( int i = 0; i < 12; i++)
sales[i] = 0.0;
}
//Function to get 12 sales figures from the user
//at the key board
void SalesPerson::GetSalesFromUser()
{
double salesFigure;
for (int i = 0; i<12; i++)
{
cout<< "Enter sales amount for month"
<< i + 1 <<":";
cin >> salesFigure;
SetSales(i,salesFigure); //--------------------------------- 不是setSales
}
}
//function to set one of the 12 mothly sales figures.
// note that the month value must be from 0 to 11
void SalesPerson::SetSales( int month, double amount )
{
if ( month >= 0 && month < 12 && amount >0 )
sales[month] = amount;
else cout << "Invalid month or sales figure" << endl;
}
// print the total annual sales
void SalesPerson:: printAnnualSales()
{
cout << setprecision(2)
<< setiosflags (ios::fixed | ios::showpoint )
<< "\nThe total annual sales are:$"
<< totalAnnualSales() << endl;
}
//private utility function to total annual sales
double SalesPerson::totalAnnualSales() // 不是---------------------totalannualSales
{
double total = 0.0;
for ( int i = 0; i < 12; i++ )
total += sales[i];
return total;
}