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 ;}