bwukki

Untitled

Jan 28th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.99 KB | None | 0 0
  1. //3.9 main file
  2. #include <iostream>
  3. #include "account.h";
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     Account test1("Jones", 400);
  9.     cout << "Current balance is.... " << test1.getBalance() << endl;
  10.     cout << test1.withdraw(500) << endl;
  11.     cout << test1.getBalance();
  12.     return 0;
  13. }
  14.  
  15. //3.9 account.h file
  16. #include <string>
  17. #include <iostream>
  18.  
  19. class Account {
  20. public:
  21.     Account(std::string accountName, int initialBalance)
  22.         : name{accountName} {
  23.  
  24.         if (initialBalance > 0) {
  25.             balance = initialBalance;
  26.     }
  27.     }
  28.     void deposit(int depositAmount) {
  29.     if (depositAmount > 0) {
  30.         balance = balance + depositAmount;
  31.     }
  32.     }
  33.  
  34.     int getBalance() const {
  35.     return balance;
  36.     }
  37.  
  38.     void setName(std::string accountName) {
  39.     name = accountName;
  40.     }
  41.  
  42.     std::string getName() const {
  43.     return name;
  44.     }
  45.  
  46.     std::string withdraw(int withdrawAmount) {
  47.     if (withdrawAmount > balance) {
  48.         return("You do not have enough money in your account to do that.");
  49.     }
  50.     else {
  51.         balance = balance - withdrawAmount;
  52.         return("Money withdrawn succesfully.");
  53.     }
  54.     }
  55.  
  56. private:
  57.     std::string name;
  58.     int balance{0};
  59. };
  60.  
  61. //3.10 main file
  62. #include <iostream>
  63. #include "invoice.h";
  64. using namespace std;
  65.  
  66. void test();
  67.  
  68. int main()
  69. {
  70.     test();
  71.     return 0;
  72. }
  73.  
  74. void test() {
  75.     Invoice test1("1234","ChainsawOil",2,4);
  76.     cout << "description: " << test1.getDescript() << " Part num: " << test1.getPartNum() << " Price: " << test1.getPrice() << " Quanitity: " << test1.getQuantity() << endl;
  77.     test1.setDescript("Chain");
  78.     test1.setPartNum("4321");
  79.     test1.setPrice(3);
  80.     test1.setQuantity(8);
  81.     cout << "description: " << test1.getDescript() << " Part num: " << test1.getPartNum() << " Price: " << test1.getPrice() << " Quanitity: " << test1.getQuantity() << endl;
  82.     cout << "Total invoice amount: $" << test1.getInvoiceAmount() << endl;
  83.     test1.setPrice(-3);
  84.     test1.setQuantity(-8);
  85.     cout << "description: " << test1.getDescript() << " Part num: " << test1.getPartNum() << " Price: " << test1.getPrice() << " Quanitity: " << test1.getQuantity() << endl;
  86. }
  87.  
  88. //3.10 header file
  89. #include <string>
  90. #include <iostream>
  91.  
  92. class Invoice {
  93.  
  94.  public:
  95.      Invoice(std::string initNum, std::string initDescript, int initPrice, int initQuantity)
  96.      : partNum{initNum}, partDescription{initDescript}  {
  97.          if ( initPrice < 0) {
  98.             partPrice = 0;
  99.          }
  100.  
  101.          else {
  102.             partPrice = initPrice;
  103.          }
  104.  
  105.          if ( initQuantity < 0) {
  106.             partQuantity = 0;
  107.          }
  108.          else {
  109.             partQuantity = initQuantity;
  110.          }
  111.  
  112. }
  113.  
  114.     std::string getPartNum() const {
  115.         return(partNum);
  116.     }
  117.  
  118.     void setPartNum(std::string newPartNum) {
  119.         partNum = newPartNum;
  120.     }
  121.  
  122.     std::string getDescript() const {
  123.         return(partDescription);
  124.     }
  125.  
  126.     void setDescript(std::string newDescript) {
  127.         partDescription = newDescript;
  128.     }
  129.  
  130.     int getPrice() const  {
  131.         return(partPrice);
  132.     }
  133.  
  134.     void setPrice(int newPrice) {
  135.             if ( newPrice < 0) {
  136.         partPrice = 0;
  137.         }
  138.                  else {
  139.             partPrice = newPrice;
  140.          }
  141.     }
  142.  
  143.     int getQuantity() const {
  144.         return(partQuantity);
  145.     }
  146.  
  147.     void setQuantity(int newQuantity) {
  148.         if ( newQuantity < 0) {
  149.             partQuantity = 0;
  150.          }
  151.          else {
  152.             partQuantity = newQuantity;
  153.          }
  154.     }
  155.  
  156.     int getInvoiceAmount() {
  157.     return (partPrice * partQuantity);
  158.     }
  159.  
  160.  private:
  161.     std::string partNum;
  162.     std::string partDescription;
  163.     int partPrice;
  164.     int partQuantity;
  165. };
  166.  
  167. //3.12 main
  168. #include <iostream>
  169. #include "date.h"
  170. using namespace std;
  171.  
  172. void test();
  173.  
  174. int main()
  175. {
  176.     test();
  177.     return 0;
  178. }
  179.  
  180. void test() {
  181.     Date test2(11,24,1991);
  182.     test2.displayDate();
  183.     test2.setDay(22);
  184.     test2.setMonth(22);
  185.     test2.setYear(2002);
  186.     test2.displayDate();
  187. }
  188.  
  189. //3.12 header
  190. #include <iostream>
  191. #include <string>
  192.  
  193. class Date {
  194.     public:
  195.         Date (int initMonth, int initDay, int initYear)
  196.         : month{initMonth}, day{initDay}, year{initYear} {}
  197.  
  198.         int getMonth() {
  199.             return month;
  200.         }
  201.  
  202.         int getDay() {
  203.             return day;
  204.         }
  205.  
  206.         int getYear() {
  207.             return year;
  208.         }
  209.  
  210.         void setMonth(int newMonth) {
  211.             if ( newMonth > 12 || newMonth < 1) {
  212.                 month = 1;
  213.             }
  214.             else {
  215.                 month = newMonth;
  216.             }
  217.         }
  218.  
  219.         void setDay(int newDay) {
  220.             day = newDay;
  221.         }
  222.  
  223.         void setYear(int newYear) {
  224.             year = newYear;
  225.         }
  226.  
  227.         void displayDate() {
  228.             std::cout << month << "/" << day << "/" << year << std::endl;
  229.         }
  230.  
  231.     private:
  232.         int month;
  233.         int day;
  234.         int year;
  235. };
Add Comment
Please, Sign In to add comment