# C++习题 商品销售

C++习题 商品销售

销货员号(num)            销货件数(quantity)       销货单价(price)

101                                              5                            23.5

102                                            12                            24.56

103                                           100                           21.5

(提示: 将折扣discount，总销售款sum和商品销售总件数n声明为静态数据成员，再定义静态成员函数average(求平均售价)和display(输出结果)。

m和m个销货员销售情况

``````3
101 5 23.5
102 12 24.56
103 100 21.5``````

``````2387.66
20.41``````

``````#include<stdio.h>
int main()
{
int n,i,j,sum1=0;
scanf("%d",&n);
int a[99],c[99];
float b[99],max=0.0,sum2=0.0;
for(i=1;i<=n;i++)
{
scanf("%d%d%f",&a[i],&c[i],&b[i]);
if(c[i]>10){b[i]*=0.98;}
sum1+=c[i];
sum2+=c[i]*b[i];

}
{printf("%.2f\n%.2f\n",sum2*0.95,sum2*0.95/sum1);}
return 0;
}``````

``````#include <iostream>
#include <iomanip>
using namespace std;

class Product{
public:
Product(){}
Product(int n,int q,float p):num(n),quantity(q),price(p){}
void total()
{
n+=quantity;
if(quantity>10)
sum+=quantity*price*(1-discount)*0.98;
else
sum+=quantity*price*(1-discount);
}
static float average()
{
return sum/n;
}
static void display()
{
cout<<sum<<endl;
cout<<average()<<endl;
}
private:
int num;
int quantity;
float price;
static float discount;
static float sum;
static int n;
};

float Product::discount=0.05;
float Product::sum=0;
int Product::n=0;

int main()
{
const int NUM =10;
Product Prod[10];
int m,i;
cin>>m;
int num;
int quantity;
float price;
for(i=0; i<m; i++)
{
cin>>num>>quantity>>price;
Product temp(num,quantity,price);
Prod[i]=temp;
}
for(i=0; i<m; i++)
Prod[i].total();
cout<<setiosflags(ios::fixed);
cout<<setprecision(2);
Product::display();
return 0;
}

``````