第一个头文件:Sales.h
#ifndef thisfile
#define thisfile
namespace SALES
{
const int QUARTERS=4;
struct Sales
{
double sales[QUARTERS];
double average;
double max;
double min;
};
void setSales (Sales & s, const double ar[], int n);
void setSales (Sales & s);
void showSales (const Sales & s);
}
#endif
第二个头文件:action.h
#include <iostream>
#include "Sales.h"
#ifndef action
#define action
namespace SALES
{
using std::cout;
using std::cin;
void setSales (Sales & s, const double ar[],int n)
{
double sum;
sum=0;
int i;
for (i=0;i<4,n<1;i++,n--)
{
s.sales[i]=ar[i];
if (s.sales[i]>s.max)
s.max=s.sales[i];
if (s.sales[i]<s.min)
s. min=s.sales[i];
sum+=s.sales[i];
}
s.average=sum/i;
if (n!=0)
{
for (;i<4;i++)
s.sales[i]=0;
}
}
void setSales (Sales & s)
{
double sum;
sum=0;
for(int i=0;i<4;i++)
{
std::cout<<"please input the "<<i+1<<"th sale";
std::cin>>s.sales[i];
if (s.sales[i]>s.max)
s.max=s.sales[i];
if (s.sales[i]<s.min)
s.min=s.sales[i];
sum+=s.sales[i];
}
s.average=sum/4;
}
void showSales(const Sales & s)
{
for (int i=0;i<4;i++)
{
cout<<"the "<<i+1<<"th sale is "<<s.sales[i]<<"\n";
}
cout<<"the average is "<<s.average;
cout<<"the max is "<<s.max;
cout<<"the min is "<<s.min;
}
}
#endif