目录:
1、created your own classes and member functions
2、create UML class diagrams that model the member functions, attributes and constructors of classes
Account.h
#ifndef UNTITLED1_ACCOUNT_H
#define UNTITLED1_ACCOUNT_H
#include <string>
#include <utility>
class Account{
public:
explicit Account(std::string accountName, int initialBalance): name{std::move(accountName)}{
if (initialBalance > 0) {
balance = initialBalance;
}
}
void deposit(int depositAmount) {
if (depositAmount > 0) {
balance = balance + depositAmount;
}
}
int getBalance() const {
return balance;
}
void setName(std::string accountName){
name = std::move(accountName);
}
std::string getName() const {
return name;
}
private:
std::string name;
int balance{0};
};
#endif //UNTITLED1_ACCOUNT_H
main.cpp
#include <iostream>
#include "Account.h"
using namespace std;
int main() {
Account account1{"Jane Green", 50};
Account account2{"John Blue", -7};
cout << "account1: " << account1.getName() << " balance is $" << account1.getBalance() << endl;
cout << "account2: " << account2.getName() << " balance is $" << account2.getBalance() << endl;
cout << "Enter deposit amount for account1: ";
int depositAmount;
cin >> depositAmount;
cout << "adding " << depositAmount << " to account1 balance" << endl;
account1.deposit(depositAmount);
cout << "account1: " << account1.getName() << " balance is $" << account1.getBalance() << endl;
}