Description
A store sells a product and publishes a uniform discount (discount) every day. At the same time allow sales staff in the sale of flexible prices (price), on this basis, a purchase of more than 10 people, you can also enjoy 98 percent discount. It is now known that the sale of M sales members on the day
Sales number (num) (quantity) Sales price
101 5 23.5
102 12 24.56
103 100 21.5
Please write a program that calculates the sum of the total sales of the item and the average price of each item for that day. Static data members and static member functions are required.
(Hint: Discount the discount, the total sales sum and the total number of items sold as static data members, and then define the static member function average (for average selling price) and display (output result).
Input
Sales of M and m salesman
Output
Total sales sum and average price of each item
Sample Input
3101 5 23.5102 12 24.56103 100 21.5
Sample Output
2387.6620.41
/* All rights reserved. * File name: Test.cpp * Chen Dani * Completion date: June 21, 2015 * Version number: v1.0 */#include <iostream> #include <iomanip>using nam Espace std;class product{private:int num; int quantity; float price; static float discount; static float sum; static int n;public:product (int nu,int q,float p): num (nu), quantity (Q), Price (p) {} Product () {} double total (); static void display (); Static double average ();}; Float Product::d iscount=0.05;float product::sum=0;int product::n=0;double product::total () {n=quantity+n; if (quantity>10) sum=sum+quantity*price* (1-discount) *0.98; else sum=sum+quantity*price* (1-discount); return sum;} Double Product::average () {double A; a=sum/n; return A;} void Product::d isplay () {cout<<sum<<endl; Cout<<average () <<endl;} 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::d isplay (); return 0;}
Learning experience: When this problem began to write, I did not according to the requirements of the data members and the main function to write the same, but why? Ask someone tomorrow, keep working on it!
15th Week OJ Brush problem--problem f:c++ Exercise Product Sales