Design a bank account class named Account that has the following private member
ID: 3839038 • Letter: D
Question
Design a bank account class named Account that has the following private member variables: account Number of type int ownerName of type string balance of type double and the following public member functions: Account constructor with no arguments, that creates a bank account with a default account Number as 9999, a name of an empty string, and balance value of zero. An Account object is dynamically allocated Account (number name, bal) constructor with three parameters, that creates a bank account with a specified accountNumber, name and balance. An Account object is dynamically allocated withdraw (amount) function to withdraw a specified amount from the account. The function should first check if there is sufficient balance in the account. If the balance is sufficient, withdrawal is processed. Otherwise the withdrawal is not made. deposit (amount) function to deposit a specified amount of money to the account. The function should first check if the deposit amount is positive. If it is positive, deposit is processed. Otherwise the deposit is not made. get Account Number An accessor function that returns the account number. This function is later called by the displayAccount Info function getName 0: An accessor function that returns the name on the account. getBalance An accessor function that returns the account balance. This function is later called by the displayAccountInfo function. Demonstrate the class in a program. 1. Additional Requirements a) What to turn in Your code should be structured into the following files: Account.hwhich contains the class definition and the function prototypes of all the member functions Account.cpp which contains the function description of all the member functions Main .cpp file which contains the main function.Explanation / Answer
//=======================Account.h=================================
#include <iostream>
using namespace std;
class Account{
private:
int accountNumber;
string ownerName;
double balance;
public:
Account();
Account(int ac,string name , double bal);
void setAccount(int ac);
int getAccount();
void setName(string name);
string getName();
void setBalance(double bal);
double getBalance();
};
//=======================Account.cpp=================================
#include <iostream>
void Account::setAccount(int ac){
accountNumber = ac;
}
int Account::getAccount(){
return accountNumber;
}
void Account::setName(string name){
ownerName = name;
}
string Account::getName(){
return ownerName;
}
void Account::setBalance(double bal){
balance = bal;
}
double Account::getBalance(){
return balance;
}
Account::Account(int ac,string name , double bal){
accountNumber = ac;
ownerName = name;
balance = bal;
}
Account::Account(){
accountNumber = 0;
ownerName = "";
balance = 0.0;
}
Account* find(Account* acs[],int acNum,int s){
Account* ac = NULL;
for(int i=0;i<s;i++){
Account* a = acs[i];
if(a->getAccount()==acNum){
ac = a;
}
}
return ac;
}
int main()
{
cout << "Hello World" << endl;
Account* accounts[100];
int count=0;
accounts[0] = new Account();
while(true){
cout << ""<<endl;
cout << "1 Crete Account wiht complete information:"<<endl;
cout << "2 Create default Account"<<endl;
cout << "3 Deposit to account"<<endl;
cout << "4 Withdraw from account"<<endl;
cout << "5 Display All account information"<<endl;
cout << "6 Exit"<<endl;
int choice;
cin>>choice;
int acnum;
string name;
double bal;
Account* ac;
switch(choice){
case 1:
cout << "Enter account number:"<<endl;
cin>>acnum;
cout << "Enter ownar's Name:"<<endl;
cin>>name;
cout << "Enter balance:"<<endl;
cin>>bal;
accounts[count] = new Account(acnum,name,bal);
count++;
break;
case 2:
accounts[count] = new Account();
count++;
break;
case 3:
//int acnum;
cout << "Enter account number:"<<endl;
cin>>acnum;
ac = find(accounts,acnum,count);
if(ac!=NULL){
int amt;
cout << "Enter amount:"<<endl;
cin >>amt;
amt+=ac->getBalance();
ac->setBalance(amt);
cout << "Final Balance:"<<ac->getBalance()<<endl;
}
break;
case 4:
cout << "Enter account number:"<<endl;
cin>>acnum;
ac = find(accounts,acnum,count);
if(ac!=NULL){
int amt;
cout << "Enter amount:"<<endl;
cin >>amt;
amt-=ac->getBalance();
ac->setBalance(amt);
cout << "Final Balance:"<<ac->getBalance()<<endl;
}
break;
case 5:
for(int i=0;i<count;i++){
ac = accounts[i];
cout <<"Accoutn Number :"<<ac->getAccount()<<endl;
cout <<"Name :"<<ac->getName()<<endl;
cout <<"Balance :"<<ac->getBalance()<<endl;
}
}
if(choice==6)break;
if(choice>6){
cout<<"Invalid Choice"<<endl;
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.