Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- // 3.9
- class Account {
- public:
- Account(std::string accountName, int initialBalance)
- : name{accountName} {
- if (initialBalance > 0) {
- balance = initialBalance;
- }
- }
- void deposit(int depositAmount) {
- if (depositAmount > 0) {
- balance = balance + depositAmount;
- }
- }
- void withdraw(int withdrawAmount){
- if (withdrawAmount <= balance)
- balance = balance - withdrawAmount;
- if (withdrawAmount > balance)
- std::cout << "\nWithdrawal amount exceeded account balance."<< std::endl;
- }
- int getBalance() const {
- return balance;
- }
- void setName(std::string accountName) {
- name = accountName;
- }
- std::string getName() const {
- return name;
- }
- private:
- std::string name;
- int balance{0};
- };
- //3.10
- #include <string>
- class Invoice {
- public:
- Invoice (std::string number_, std::string description_, int quantity_, int price_){
- : number{number_}, description{description_}, quantity{quantity_}, price{price_}
- }
- int getnumber() const{
- return number;
- }
- int getdescription() const{
- return description;
- }
- int getQuantity() const{
- return quantity;
- }
- int getPrice() const{
- return price;
- }
- int getInvoiceAmount() const {
- getInvoiceAmount = quantity * price;
- return value;
- }
- private:
- int quantity{0};
- int price{0};
- std::string number;
- std::string description
- int value{0};
- int InvoiceAmount{0};
- };
- //3.12
- #include <string>
- class Date {
- public:
- Date(int initialMonth, int initialDay, int initialYear)
- : month{initialMonth}, day{initialDay}, year{initialYear}{
- if(initialMonth > 12 ){
- month = 1;
- }
- }
- void displayDate(){
- std::cout << getMonth() <<"/" << getDay() << "/" << getYear() << std::endl;
- }
- int getMonth() const{
- return month;
- }
- int getDay() const{
- return day;
- }
- int getYear() const{
- return year;
- }
- void setMonth(int initialMonth){
- month = initialMonth;
- }
- void setDay(int initialDay){
- day = initialDay;
- }
- void setYear(int initialYear){
- year = initialYear;
- }
- private:
- int month{0};
- int day{0};
- int year{0};
- };
- //3.13
- #include <iostream>
- #include "count.h"
- using namespace std;
- void displayAccount(Account accountone, accounttwo ){
- cout << "account: " << accountone.getName() << "balance is $" << accountone.getBalance()<< "\n";
- cout << "account: " << accounttwo.getName() << "balance is $" << accounttwo.getBalance()<< "\n";
- }
- int main()
- {
- Account account1{"Jane Green", 50};
- Account account2{"John Blue", -7};
- displayAccount(account1, account2);
- cout << "\n\nEnter deposit amount for account1: ";
- int depositAmount;
- cin >> depositAmount;
- cout << "adding " << depositAmount << " to account1 balance"<< endl;
- account1.deposit(depositAmount);
- displayAccount(account1, account2);
- cout << "\n\nEnter deposit amount for account2
- : ";
- cin >> depositAmount;
- cout << "adding " << depositAmount << " to account2 balance" << endl;
- account2.deposit(depositAmount);
- displayAccount(account1, account2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement