15th Week OJ Brush problem--problem i:c++ Exercise Compare size-class template

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.