Question

Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string;...

Need to implement Account.cpp and AccountManager.cpp code

//Account.hpp

#ifndef _ACCOUNT_HPP_
#define _ACCOUNT_HPP_
#include <string>
using std::string;

class Account {
public:
Account();
Account(string, double);
void deposit(double);
bool withdraw(double);
string getName() const;
double getBalance() const;
private:
string name;
double balance;
};

#endif
//////////////////////////////////////////////

//AccountManager.hpp

#ifndef _ACCOUNT_MANAGER_HPP_
#define _ACCOUNT_MANAGER_HPP_
#include "Account.hpp"
#include <string>
using std::string;

class AccountManager {
public:
AccountManager();
AccountManager(const AccountManager&); //copy constructor
void open(string);
void close(string);
void depositByName(string,double);
bool withdrawByName(string,double);
double getBalanceByName(string);
Account getAccountByName(string);
void openSuperVipAccount(Account&);
void closeSuperVipAccount();
bool getBalanceOfSuperVipAccount(double&) const;
int getAccountNumber() const;
int getManagerNumber() const;
~AccountManager();
private:
Account accountlist[100];//Record all currently open accounts
int *accountNumber;// Record the total number of currently opened accounts
Account* SuperVipAccount; //record SuperVIP accounts, points to NULL if an account didn' t open the SuperVIP account
static int ManagerNumber; //record total number of managers
};

#endif

/////////////////////////////////////////////////////////

//main.cpp

#include "AccountManager.hpp"
#include <iostream>
using namespace std;

int main() {
AccountManager* am = new AccountManager();
string name;
double num;
string command;
while (cin >> command) {
if (command == "open") {
cin >> name;
am -> open(name);
cout << "Account " << name << " opened." << endl;
}

else if (command == "deposit") {
cin >> name >> num;
am -> depositByName(name, num);
cout << name << " deposited " << num << endl;
num = am -> getBalanceByName(name);
cout << name << " has " << num << endl;
}

else if (command == "withdraw") {
cin >> name >> num;
if (am -> withdrawByName(name, num)) {
cout << name << " withdrawed " << num << endl;
num = am -> getBalanceByName(name);
cout << name << " has " << num << endl;
} else {
cout << "Withdraw failed, check the balance." << endl;
}
}

else if (command == "check") {
cin >> name;
num = am -> getBalanceByName(name);
cout << name << " has " << num << endl;
}

else if (command == "openvip") {
cin >> name;
Account ac = am -> getAccountByName(name);
if (ac.getName() == name) {
am -> openSuperVipAccount(ac);
cout << "set " << name << " as super vip" << endl;
} else {
cout << "no such Account" << endl;
}
}

else if (command == "closevip") {
am -> closeSuperVipAccount();
cout << "super vip closed" << endl;
}

else if (command == "quit") {
delete am;
return 0;
}

else {
cout << "No such command." << endl;
}
}
delete am;
return 0;
}

SuperVIP is existing independently, if it's close or open, the Manager's acountlist or accountNumber should not be changed.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Account.hpp

#ifndef _ACCOUNT_HPP_
#define _ACCOUNT_HPP_
#include <string>
using std::string;

class Account {
public:
Account();
Account(string, double);
void deposit(double);
bool withdraw(double);
string getName() const;
double getBalance() const;
private:
string name;
double balance;
};
#endif

Account.cpp

#include "Account.hpp"
using std::string;

Account::Account()
{
   name = "";
   balance = 0.0;
}

Account::Account(string name, double balance)
{
   this->name = name; this->balance = balance;
}
void Account::deposit(double amount)
{
   balance += amount;
}
bool Account::withdraw(double amount)
{
   if(balance < amount) return false;
   balance -= amount;
   return true;
}
string Account::getName() const
{
   return name;
}
double Account::getBalance() const
{
   return balance;
}

AccountManager.hpp

#ifndef _ACCOUNT_MANAGER_HPP_
#define _ACCOUNT_MANAGER_HPP_
#include "Account.cpp"
#include <string>
using std::string;

class AccountManager {
public:
AccountManager();
AccountManager(const AccountManager&); //copy constructor
void open(string);
void close(string);
void depositByName(string,double);
bool withdrawByName(string,double);
double getBalanceByName(string);
Account getAccountByName(string);
void openSuperVipAccount(Account&);
void closeSuperVipAccount();
bool getBalanceOfSuperVipAccount(double&) const;
int getAccountNumber() const;
static int getManagerNumber(){return ManagerNumber; }
~AccountManager();
private:
Account* accountlist[100];//Record all currently open accounts
int *accountNumber;// Record the total number of currently opened accounts
Account* SuperVipAccount; //record SuperVIP accounts, points to NULL if an account didn' t open the SuperVIP account
static int ManagerNumber; //record total number of managers
};

#endif

AccountManager.cpp

#include "AccountManager.hpp"

using std::string;

AccountManager::AccountManager()
{
   for(int i=0; i<100; i++) accountlist[i] = NULL;
   accountNumber = (int*)malloc(sizeof(int));
   *accountNumber = 0;
   SuperVipAccount = NULL; //record SuperVIP accounts, points to NULL if an account didn' t open the SuperVIP account
}
AccountManager::AccountManager(const AccountManager& account)
{
  
}
void AccountManager::open(string name)
{
   for(int i=0; i<100; i++)
       if(accountlist[i]== NULL)
       {
           accountlist[i] = new Account(name, 0);
           *accountNumber = *accountNumber + 1;
           break;
       }
}

void AccountManager::close(string name)
{
   for(int i=0; i<100; i++)
       if(accountlist[i]->getName()==name)
       {
           accountlist[i] = NULL;
           *accountNumber = *accountNumber - 1;
           break;
       }
}
void AccountManager::depositByName(string name,double amount)
{
   for(int i=0; i<100; i++)
       if(accountlist[i]->getName()==name)
       {
           accountlist[i]->deposit(amount);
           break;
       }
}
bool AccountManager::withdrawByName(string name,double amount)
{
   for(int i=0; i<100; i++)
       if(accountlist[i]->getName()==name)
       {
           accountlist[i]->withdraw(amount);
           break;
       }
}
double AccountManager::getBalanceByName(string name)
{
   for(int i=0; i<100; i++)
       if(accountlist[i]->getName()==name)
       {
           return accountlist[i]->getBalance();
       }
}
Account AccountManager::getAccountByName(string name)
{
   for(int i=0; i<100 && accountlist[i]!=NULL; i++)
       if(accountlist[i]->getName()==name)
       {
           return *accountlist[i];
       }
   Account tmp;
   return tmp;
}
void AccountManager::openSuperVipAccount(Account& account)
{
   SuperVipAccount = new Account(account.getName(), account.getBalance());
}
void AccountManager::closeSuperVipAccount()
{
   if(SuperVipAccount != NULL)
       delete SuperVipAccount;
   SuperVipAccount = NULL;
}
bool AccountManager::getBalanceOfSuperVipAccount(double& amount) const
{
   if(SuperVipAccount == NULL) return false;
   amount = SuperVipAccount->getBalance();
   return true;
}
int AccountManager::getAccountNumber() const
{
   return *accountNumber;
}

AccountManager::~AccountManager()
{
   delete accountNumber;
   if(SuperVipAccount != NULL)
       delete SuperVipAccount;
}

main.cpp

#include "AccountManager.cpp"
#include <iostream>
using namespace std;

int main() {
AccountManager* am = new AccountManager();
string name;
double num;
string command;
while (cin >> command) {
if (command == "open") {
cin >> name;
am -> open(name);
cout << "Account " << name << " opened." << endl;
}

else if (command == "deposit") {
cin >> name >> num;
am -> depositByName(name, num);
cout << name << " deposited " << num << endl;
num = am -> getBalanceByName(name);
cout << name << " has " << num << endl;
}

else if (command == "withdraw") {
cin >> name >> num;
if (am -> withdrawByName(name, num)) {
cout << name << " withdrawed " << num << endl;
num = am -> getBalanceByName(name);
cout << name << " has " << num << endl;
} else {
cout << "Withdraw failed, check the balance." << endl;
}
}

else if (command == "check") {
cin >> name;
num = am -> getBalanceByName(name);
cout << name << " has " << num << endl;
}

else if (command == "openvip")
{
   cin >> name;
   Account ac = am -> getAccountByName(name);
   if (ac.getName() == name)
   {
       am -> openSuperVipAccount(ac);
       cout << "set " << name << " as super vip" << endl;
   }
   else
   {
       cout << "no such Account" << endl;
   }
}

else if (command == "closevip")
{
   am -> closeSuperVipAccount();
   cout << "super vip closed" << endl;
}

else if (command == "quit") {
delete am;
return 0;
}

else {
cout << "No such command." << endl;
}
}
delete am;
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ ***//Cat.h//*** #ifndef __Cat_h__ #define __Cat_h__ #include <string> using namespace std; struct Cat { double...

    In C++ ***//Cat.h//*** #ifndef __Cat_h__ #define __Cat_h__ #include <string> using namespace std; struct Cat { double length; double height; double tailLength; string eyeColour; string furClassification; //long, medium, short, none string furColours[5]; }; void initCat (Cat&, double, double, double, string, string, const string[]); void readCat (Cat&); void printCat (const Cat&); bool isCalico (const Cat&); bool isTaller (const Cat&, const Cat&); #endif ***//Cat.cpp//*** #include "Cat.h" #include <iostream> using namespace std; void initCat (Cat& cat, double l, double h, double tL, string eC,...

  • #ifndef PROCESSREQUESTRECORD_CLASS #define PROCESSREQUESTRECORD_CLASS #include <iostream> #include <string> using namespace std; class procReqRec { public: //...

    #ifndef PROCESSREQUESTRECORD_CLASS #define PROCESSREQUESTRECORD_CLASS #include <iostream> #include <string> using namespace std; class procReqRec { public: // default constructor procReqRec() {} // constructor procReqRec(const string& nm, int p); // access functions int getPriority(); string getName(); // update functions void setPriority(int p); void setName(const string& nm); // for maintenance of a minimum priority queue friend bool operator< (const procReqRec& left, const procReqRec& right); // output a process request record in the format // name: priority friend ostream& operator<< (ostream& ostr, const procReqRec&...

  • CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer;...

    CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...

  • #include <iostream> #include <string> #include "hashT.h" #include "stateData.h" using namespace std; void stateData::setStateInfo(string sName, string sCapital,...

    #include <iostream> #include <string> #include "hashT.h" #include "stateData.h" using namespace std; void stateData::setStateInfo(string sName, string sCapital,    double stArea, int yAdm, int oAdm) {    stateName = sName; stateCapital = sCapital; stArea = stateArea; yAdm = yearOfAdmission; oAdm = orderOfAdmission;       } void stateData::getStateInfo(string& sName, string& sCapital,    double& stArea, int& yAdm, int& oAdm) {    sName = stateName; sCapital = stateCapital; stArea = stateArea; yAdm = yearOfAdmission; oAdm = orderOfAdmission;       } string stateData::getStateName() { return stateName;...

  • #include <iostream #include <string> #ifndef ACCOUNT H #define ACCOUNT H class Account { public: Account(std::string, int);...

    #include <iostream #include <string> #ifndef ACCOUNT H #define ACCOUNT H class Account { public: Account(std::string, int); Account(){}; void deposit(int); void withdraw(int); int getBalance() const; 15 private: int balance{@}; std::string name{}; 18 19 20 Verdif - Account.cpp saved #include "Account.h" Account :: Account(std::string accountName, int startingBalance) : name{accountName) 4 5 if (startingBalance > 0) balance = startingBalance; B 10 void Account::deposit(int depositAmount) { if (depositAmount > 0) balance + depositAmount: ) 12 13 14 15 16 void Account::withdraw(int withdrawAmount) { If...

  • please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName();...

    please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...

  • lex.h ----------------- #ifndef LEX_H_ #define LEX_H_ #include <string> #include <iostream> using std::string; using std::istream; using std::ostream;...

    lex.h ----------------- #ifndef LEX_H_ #define LEX_H_ #include <string> #include <iostream> using std::string; using std::istream; using std::ostream; enum Token { // keywords PRINT, BEGIN, END, IF, THEN, // an identifier IDENT, // an integer and string constant ICONST, RCONST, SCONST, // the operators, parens, semicolon PLUS, MINUS, MULT, DIV, EQ, LPAREN, RPAREN, SCOMA, COMA, // any error returns this token ERR, // when completed (EOF), return this token DONE }; class LexItem { Token token; string lexeme; int lnum; public: LexItem()...

  • Requirements I have already build a hpp file for the class architecture, and your job is to imple...

    Requirements I have already build a hpp file for the class architecture, and your job is to implement the specific functions. In order to prevent name conflicts, I have already declared a namespace for payment system. There will be some more details: // username should be a combination of letters and numbers and the length should be in [6,20] // correct: ["Alice1995", "Heart2you", "love2you", "5201314"] // incorrect: ["222@_@222", "12306", "abc12?"] std::string username; // password should be a combination of letters...

  • #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car {...

    #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT