Description
Declares a class template that uses it to compare two integers, floating-point numbers, and characters, and to find large and fractional numbers. Description: Defines the member functions outside of the class template.
Input
Enter two integers, two floating-point numbers, and two characters
Output
Output two integers, two floating-point numbers, and two characters from large to small
Sample Input
3 745.78 93.6a A
Sample Output
7 393.60 45.78a A
/* All rights reserved. * File name: Test.cpp * Chen Dani * Completion date: June 21, 2015 * Version number: v1.0 * * #include <iostream> #include <iomanip>using namespac e 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;}
Experience: class template, now finally able to master, brush the question is very useful, not only can consolidate knowledge, can also help us to check the gaps, such a review way I like, continue to work!!
15th Week OJ Brush problem--problem i:c++ Exercise Compare size-class template