Advertisement
TheWhiteFang

Tutorial 5 secA

Nov 23rd, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. // http://pastebin.com/u/TheWhiteFang
  2. #include <iostream>
  3. #include <string>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. class Purchase
  9. {  
  10. //any member var in the class can be access by the class whether public or private
  11. private:
  12.     int qty;
  13.     float price;
  14.     string itemName;
  15.     float total;
  16.  
  17. public:
  18.     Purchase(){ //Default non parameterized constructor
  19.         qty = 0; price =0.0; itemName = ""; total = 0.0;
  20.    
  21.     }
  22.  
  23.  
  24. public:
  25.     //setter function
  26.     void set_data(int inQty, float inPrice, string inItemName){
  27.    
  28.         qty = inQty;
  29.         price = inPrice;
  30.         itemName = inItemName;
  31.        
  32.    
  33.    
  34.     }
  35.  
  36.     void Calculate(){
  37.    
  38.         total = qty*price;
  39.     }
  40.  
  41.     void Print(){
  42.    
  43.         cout << "Name: "<< itemName << endl;
  44.         cout << "Price: "<< price <<endl;
  45.         cout << "qty: " << qty<< endl;
  46.         cout << "Total: "<< total <<endl;
  47.    
  48.    
  49.     }
  50.     /*int getQty(){
  51.         return qty;
  52.     }*/
  53.  
  54.     //getter function
  55.  
  56.     /*void getData(int &outQty, float &outPrice, string &outItemName, float &outTotal){
  57.        
  58.         outQty = qty;
  59.         outPrice = price;
  60.         outItemName = itemName;
  61.         outTotal = total;
  62.         return;
  63.    
  64.     }*/
  65.  
  66.  
  67. };
  68.  
  69.  
  70. int main(){
  71.  
  72.         Purchase p1; //F10 step over //F11 step into
  73.         string myItemName;
  74.         int myQty;
  75.         float myPrice;
  76.  
  77.  
  78.  
  79.         cout << "Welcome!\n\n";
  80.         cout << "Enter item: ";
  81.         cin >> myItemName;
  82.         cout <<"Enter price: ";
  83.         cin >> myPrice;
  84.         cout << "Enter item quantity: ";
  85.         cin >>myQty;
  86.  
  87.         p1.set_data(myQty, myPrice, myItemName);
  88.         p1.Calculate();
  89.  
  90.         cout << "Receipt!\n\n";
  91.  
  92.         p1.Print();
  93.  
  94.  
  95. return 0;
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement