Advertisement
kylehannon

chapter 3

Feb 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.92 KB | None | 0 0
  1. //3.13
  2.  
  3. void displayAccount(Account accountToDisplay) {
  4.     cout << accountToDisplay.getName() << "Balance is $" << accountToDisplay.getBalance();
  5. }
  6.  
  7. int main() {
  8.     Account accA{ "Jane Green", 58};
  9.     Account accB{ "Jogn Blue", 85};
  10.    
  11.     displayAccount(accA);
  12.    
  13. }
  14.  
  15. //3.12
  16.  
  17. class Date {
  18. public:
  19.    
  20.     Date ( int iday, int imonth, int iyear) {
  21.         day = iday;
  22.         month = imonth;
  23.         year = iyear;
  24.        
  25.     }
  26.    
  27.     //set day
  28.     void setDay(int iday) {
  29.         day = iday;
  30.     }
  31.    
  32.     //set month
  33.     void setMonth(int imonth) {
  34.         month = imonth;
  35.     }
  36.    
  37.     //set year
  38.     void setYear(int iyear) {
  39.         year = iyear;
  40.     }
  41.  
  42.     // get day
  43.     int getDay()const {
  44.         return day;
  45.     }
  46.    
  47.     //get month
  48.     int getMonth() {
  49.         return month;
  50.     }
  51.    
  52.     //get year
  53.     int getYear() {
  54.         return year;
  55.     }
  56.    
  57.    
  58.    
  59.    
  60. private:
  61.     int day;
  62.     int month;
  63.     int year;
  64. };
  65.  
  66. int main() {
  67.    
  68.     Date itemtest (2, 5, 12);
  69.    
  70.     cout << "The date is: " << itemtest.getDay() << "/" << itemtest.getMonth() << "/" << itemtest.getYear();
  71. }
  72.  
  73. //3.10
  74.  
  75. class Invoice {
  76.    
  77. public:
  78.    
  79.     Invoice(string partnumber, string partdescription, int quantity, int priceperitem) {
  80.         partnum = partnumber;
  81.         partdesc = partdescription;
  82.         quant = quantity;
  83.         price = priceperitem;
  84.        
  85.     }
  86.    
  87.     //setter for partnum
  88.     void setPartnum(string partnumber) {
  89.         partnum = partnumber;
  90.     }
  91.    
  92.     //setter for partdesc
  93.     void setPartdesc(string partdescription) {
  94.         partdesc = partdescription;
  95.     }
  96.    
  97.     //setter for quant
  98.     void setQuant(int quantity) {
  99.         quant = quantity;
  100.     }
  101.    
  102.     //setter for price
  103.     void setPrice(int priceperitem) {
  104.         price = priceperitem;
  105.     }
  106.    
  107.     //getter for quant
  108.     int getQuant() const {
  109.         return quant;
  110.     }
  111.    
  112.     //getter for price
  113.     int getPrice()const {
  114.         return price;
  115.     }
  116.    
  117.     //getter for partnum
  118.     string getPartnum()const {
  119.         return partnum;
  120.     }
  121.    
  122.     //getter for partdesc
  123.     string getPartdesc()const {
  124.         return partdesc;
  125.     }
  126.    
  127.     //getter of invoice
  128.     int getInvoiceAmount() {
  129.         if (quant < 0) {
  130.             quant = 0;
  131.         }
  132.         else if (price < 0) {
  133.             price = 0;
  134.         }
  135.         return quant*price;
  136.     }
  137.  
  138. private:
  139.     string partnum, partdesc;
  140.     int quant, price;
  141. };
  142.  
  143. int main() {
  144.     Invoice testItem( "GTX1080", "GPU", 10, 700);
  145.    
  146.     cout <<"\n Part Number: " << testItem.getPartnum() << endl;
  147.     cout << "\n Part Description: " << testItem.getPartdesc() << endl;
  148.     cout << "\n Quantity: " << testItem.getQuant() << endl;
  149.     cout << "\n Price Per item: " << testItem.getPrice() << endl;
  150.     cout << "\n Invoice Amount: $" << testItem.getInvoiceAmount() << endl;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement