A very simple file written by C ++

Source: Internet
Author: User

In the future, my position will be to use C/C ++ development in Linux. Now I have started to review C ++. Although I have learned this before, in addition, I learned a little bit in the second semester of my freshman year, but it was full of fur. I learned a little bit of STL last summer and I felt pretty good, the result is that the C ++ exam in the first semester of the sophomore year is very bad. I did not learn things in the first semester of my sophomore year.Algorithm, But still weak;

Header file Declaration

// Header file declaration # ifndef sale_h # define sale_hclass sale {public: Sale () {} sale (int p, int N): price (P), num (N) {} int cost (); int getprice (); int setnum (int n); int setprice (int p); Private: int price; int num ;}; # endif

Header file implementation

# Include "sale. H "int sale: cost () {return this-> num * This-> price;} int sale: getprice () {return this-> price;} int sale:: setnum (int n) {This-> num = N; return N;} int sale: setprice (INT p) {return this-> price = P ;}

The main function is very watery:

# Include <iostream> # include "sale. H "# include <algorithm> using namespace STD; int main () {sale m; int price; cout <" Enter the product price: "<ends; cin> price; M. setprice (price); cout <"Enter the number of items:" <ends; int num; CIN> num; M. setnum (Num); cout <"total cost $:" <ends; cout <m. cost () <Endl; return 0 ;}

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.