Question: C++ Help! Please fix code so test driver works! #include #include using namespace std; //class Account class Account { //Data members declared private: string name;
C++ Help! Please fix code so test driver works!
#include
using namespace std;
//class Account class Account { //Data members declared private: string name; string occupation; double balance; double rate;
//Member functions public: Account(string name = "John Doe", string occupation = "Unemployed", double balance = 0.0, double rate = 0.0); void withdraw(double amount); void deposit(double amount); void applyInterest(); string getName(); string getOccupation(); double getBalance(); double getRate(); void setName(string name); void setOccupation(string occupation); void setBalance(double balance); void setRate(double rate); void printData();
//Overload stream insertion operator for class friend ostream& operator<<(ostream &out, Account &cAccount); };
Account::Account(string name, string occupataion, double balance, double rate) { setName(name); setOccupation(occupation); setBalance(balance); setRate(rate); }
void Account::withdraw(double amount) { if (amount <= balance) balance = balance - amount; else cout << "Insufficient Funds." << endl; }
void Account::deposit(double amount) { if (amount > 0) balance = balance + amount; else cout << "Invalid Amount." << endl; }
void Account::applyInterest() { balance = balance + balance * rate; }
string Account::getName() { return name; }
string Account::getOccupation() { return occupation; }
double Account::getBalance() { return balance; }
double Account::getRate() { return rate; }
void Account::setName(string name) { this->name = name; }
void Account::setOccupation(string occupation) { this->occupation = occupation; }
void Account::setBalance(double balance) { this->balance = balance; }
void Account::setRate(double rate) { this->rate = rate; }
void Account::printData() { return data; }
//can access account member's directly through friend bc of operator ostream& operator<<(ostream *out, Account &cAccount) { count < cAccount.getName << "has an account balance of " << cAccount.getBalance; return cout; }
//Provided Test Driver int main() { Account acct1, acct2("Susan Francis", "Physical Therapist", 93000.0, 0.01), acct3("Thomas Thompson", "IT Professional", 125000.0, 0.01);
acct1.withdraw(130000.0); acct2.deposit(40000); acct3.deposit(4000); acct1.applyInterest(); acct2.applyInterest(); acct3.applyInterest(); acct1.print(); acct2.print(); acct3.print(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
