Advertisement
lokhun

Untitled

Feb 4th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.39 KB | None | 0 0
  1. #include <string>
  2.  
  3. // 3.9
  4. class Account {
  5. public:
  6.  
  7.    Account(std::string accountName, int initialBalance)
  8.       : name{accountName} {
  9.  
  10.       if (initialBalance > 0) {
  11.          balance = initialBalance;
  12.       }
  13.    }
  14.  
  15.    void deposit(int depositAmount) {
  16.       if (depositAmount > 0) {
  17.          balance = balance + depositAmount;
  18.       }
  19.    }
  20.  
  21.    void withdraw(int withdrawAmount){
  22.       if (withdrawAmount <= balance)
  23.          balance = balance - withdrawAmount;
  24.  
  25.       if (withdrawAmount > balance)
  26.       std::cout << "\nWithdrawal amount exceeded account balance."<< std::endl;
  27.  
  28.    }
  29.  
  30.    int getBalance() const {
  31.       return balance;
  32.    }
  33.  
  34.    void setName(std::string accountName) {
  35.       name = accountName;
  36.    }
  37.  
  38.    std::string getName() const {
  39.       return name;
  40.    }
  41. private:
  42.    std::string name;
  43.    int balance{0};
  44. };
  45.  
  46. //3.10
  47. #include <string>
  48.  
  49. class Invoice {
  50.  
  51. public:
  52.     Invoice (std::string number_, std::string description_, int quantity_, int price_){
  53.         : number{number_}, description{description_}, quantity{quantity_}, price{price_}
  54.     }
  55.    
  56.     int getnumber() const{
  57.         return number;
  58.     }
  59.     int getdescription() const{
  60.         return description;
  61.     }
  62.    
  63.     int getQuantity() const{
  64.         return quantity;
  65.     }
  66.  
  67.     int getPrice() const{
  68.         return price;
  69.     }
  70.  
  71.     int getInvoiceAmount() const {
  72.       getInvoiceAmount = quantity * price;
  73.       return value;
  74.     }
  75.  
  76. private:
  77.     int quantity{0};
  78.     int price{0};
  79.     std::string number;
  80.     std::string description
  81.     int value{0};
  82.     int InvoiceAmount{0};
  83. };
  84.  
  85. //3.12
  86.  
  87. #include <string>
  88.  
  89. class Date {
  90.  
  91. public:
  92.     Date(int initialMonth, int initialDay, int initialYear)
  93.         : month{initialMonth}, day{initialDay}, year{initialYear}{
  94.  
  95.         if(initialMonth > 12 ){
  96.            month = 1;
  97.         }
  98.  
  99.     }
  100.     void displayDate(){
  101.         std::cout << getMonth() <<"/" << getDay() << "/" << getYear() << std::endl;
  102.     }
  103.  
  104.  
  105.     int getMonth() const{
  106.         return month;
  107.     }
  108.  
  109.     int getDay() const{
  110.         return day;
  111.     }
  112.  
  113.     int getYear() const{
  114.         return year;
  115.     }
  116.  
  117.     void setMonth(int initialMonth){
  118.         month = initialMonth;
  119.     }
  120.  
  121.     void setDay(int initialDay){
  122.         day = initialDay;
  123.     }
  124.  
  125.     void setYear(int initialYear){
  126.         year = initialYear;
  127.     }
  128. private:
  129.     int month{0};
  130.     int day{0};
  131.     int year{0};
  132. };
  133.  
  134. //3.13
  135. #include <iostream>
  136. #include "count.h"
  137.  
  138. using namespace std;
  139.  
  140. void displayAccount(Account accountone, accounttwo ){
  141.     cout << "account: " << accountone.getName() << "balance is $" << accountone.getBalance()<< "\n";
  142.     cout << "account: " << accounttwo.getName() << "balance is $" << accounttwo.getBalance()<< "\n";
  143.  
  144. }
  145.  
  146.  
  147. int main()
  148. {
  149.    Account account1{"Jane Green", 50};
  150.    Account account2{"John Blue", -7};
  151.  
  152.    displayAccount(account1, account2);
  153.  
  154.    cout << "\n\nEnter deposit amount for account1: ";
  155.    int depositAmount;
  156.    cin >> depositAmount;
  157.    cout << "adding " << depositAmount << " to account1 balance"<< endl;
  158.    account1.deposit(depositAmount);
  159.  
  160.    displayAccount(account1, account2);
  161.  
  162.    cout << "\n\nEnter deposit amount for account2
  163.   : ";
  164.    cin >> depositAmount;
  165.    cout << "adding " << depositAmount << " to account2 balance" << endl;
  166.    account2.deposit(depositAmount);
  167.  
  168.    displayAccount(account1, account2);
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement