Question

Design a bank account class named Account that has the following private member variables:

Need help please!.. C++ program

Design a bank account class named Account that has the following private member variables:
 accountNumber of type int
 ownerName of type string
 balance of type double
 transactionHistory of type pointer to Transaction structure (structure is defined below)
 numberTransactions of type int
 totalNetDeposits of type static double.The totalNetDeposits is the cumulative sum of all deposits (at account creation and at deposits) minus the cumulative sum of all withdrawals.
 numberAccounts of type static int


and the following public member functions:
 Account(number, name, amount, month, day, year) is the constructor that initializes the account’s member variables with number, name and amount. amount is the amount deposited when the account is created. The “account creation” transaction is recorded in the transaction history by calling recordTransaction. numberTransactions is set to 1, and amount is added to totalNetDeposits. numberAccounts is incremented.
 withdraw(amount, month, day, year) 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. If the withdrawal is made, the withdrawal amount is deducted from balance and from totalNetDeposits. The transaction is recorded in the transaction history. numberTransactions is incremented.
 deposit(amount, month, day, year) 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. If the deposit is made, the amount is added to balance and to totalNetDeposits, and the transaction is recorded in the transaction history. numberTransactions is incremented.
 getAccountNumber(): An accessor function that returns the account number. This function is later called by the displayAccountInfo() function.
 getName(): 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.
 printTransactions: prints the history of transactions: date (month, year, day), amount and type for each transaction
 getTotalNetDeposit(): A static member function that returns totalNetDeposits.


Demonstrate the class in a program.
2. Transaction structure
Transaction structure has the following members:
transactionMonth of type Month
transactionDay of type int
transactionYear of type int
transactionAmount of type double
transactionType of type Operation
Operation is of type enum, and the possible values are CREATION, DEPOSIT, WITHDRAWAL.


3. Record a Transaction in history
To record a transaction, you should implement recordTransaction, a private member function, which takes as argument a Transaction to be recorded.
The transaction history is implemented as an array of Transaction structures. Initially, the history is empty and no array is allocated. The first transaction is recorded in the history (account creation is the first transaction) by dynamically allocating an array of size 1, and populating with the transaction to be recorded.

/* This function takes as argument a Transaction structure and adds it to the transaction history. The transaction history
is implemented as an array of Transaction structures. A new array is dynamically allocated, of size equal to (size of old array)+1, to hold the added transaction. The values of the old array are copied into the new array,and the transaction to be added is copied into the last element of the new array.The old array is released through delete. The address returned from dynamic array allocation is assigned to transactionHistory.

*/
void Account::recordTransaction(Transaction transact)
{
// Function body
}

4. Additional Requirements
a) What to turn in
Your code should be structured into the following files:
 Account.h which 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.
b) Outline of main
Define a global array of pointers to Account, of size NUM_ACCOUNT (set NUM_ACCOUNT to 5).
Loop on displaying the following menu of choices:
1. Create account (user will be prompted for account number, name, amount, month, day and year)
2. Deposit to account (user will be prompted for account number, amount, month, day and year)
3. Withdraw from account (user will be prompted for account number, amount, month, day and year)
4. Print transaction history (user will be prompted for account number)
5. Display information for all accounts (including the transaction history)
6. Display totalNetDeposits
7. Exit the program.

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

Here is the code for the question. Sample output is also attached. Please dont forget to rate the answer if it helped. Thank you very much.

Account.h

#include
using namespace std;
//enum for months starting from 1
enum Month
{
   JANUARY=1,FEBRUARY,MARCH,APRIL,MAY,JUNE,JULY,AUGUST,SEPTEMBER,OCTOBER,NOVEMBER,DECEMBER
};
enum Operation
{
   CREATION,DEPOSIT,WITHDRAWAL
};
struct Transaction
{
   Month transactionMonth;
   int transactionDay;
   int transactionYear;
   double transactionAmount;
   Operation transactionType;
   Transaction(){}
   Transaction(Operation type,Month month,int day,int year,double amount)
   {
       transactionMonth=month;
       transactionDay=day;
       transactionYear=year;
       transactionType=type;
       transactionAmount=amount;
      
   }
  
};


class Account
{
   private:
       int accountNumber;
       string ownerName;
       double balance;
       Transaction *transactionHistory;
       int numberTransactions;
       static double totalNetDeposits;
       static int numberAccounts;
       void recordTransaction(Operation op,Month m,int d,int y,double amount);//records a transaction
   public:
       //constructor
       Account(int number,string name,double amount,Month month,int day, int year);
       bool withdraw(double amount,Month month,int day,int year); //function for withdrawal
       bool deposit(double amount,Month month ,int day, int year);//function to deposit
       int getAccountNumber();//return the accoutn number
       string getName();//return the ownerName
       double getBalance();//return the balance amount
       void printTransactions();//prints transaction history
       void display(); //display full details of account including trasactoin history
       static double getTotalNetDeposits();//return the totalNetDeposit value
      
      
};

Account.cpp

#include "Account.h"
double Account::totalNetDeposits=0;
int Account::numberAccounts=0;
string MonthName(int num)
{
   switch(num)
   {
       case JANUARY: return "Jan";
           break;
       case FEBRUARY: return "Feb";
           break;
       case MARCH: return "Mar";
           break;
       case APRIL: return "Apr";
           break;
       case MAY: return "May";
           break;
       case JUNE: return "Jun";
           break;
       case JULY: return "Jul";
           break;
       case AUGUST: return "Aug";
           break;
       case SEPTEMBER: return "Sep";
           break;
       case OCTOBER: return "Oct";
           break;
      
       case NOVEMBER: return "Nov";

           break;
       case DECEMBER: return "Dec";
           break;
       default:
           return "";
   }
}

string OperationName(int num)
{
   switch(num)
   {
       case CREATION:return "Creation";
       case DEPOSIT: return "Deposit";
       case WITHDRAWAL: return "Withdraw";
       default: return "";
   }
}
void Account::recordTransaction(Operation type,Month month,int day,int year,double amount)//records a transaction
{
   Transaction t(type,month,day,year,amount);
   Transaction *temp=new Transaction[numberTransactions+1]; //allocate a bigger array
  
   for(int i=0;i        temp[i]=transactionHistory[i];
  
   temp[numberTransactions]=t; //store in last location
   numberTransactions++; //increment number of transaction
  
   delete []transactionHistory; //deallocate old array
   transactionHistory=temp; //save the newly allocated  
}
     
//constructor
Account::Account(int number,string name,double amount,Month month,int day, int year)
{
   accountNumber=number;
   ownerName=name;
   balance=amount;
   numberTransactions=0;
   recordTransaction(CREATION,month,day,year,amount);
   totalNetDeposits+=amount;
   numberAccounts++;
}
bool Account::withdraw(double amount,Month month,int day,int year) //function for withdrawal
{
   if(amount<=balance)//check if enough balance
   {
       balance-=amount;
       totalNetDeposits-=amount;
       recordTransaction(WITHDRAWAL,month,day,year,amount);
       return true;
   }
   else //not enough balance
   {
       return false;
   }
}
bool Account::deposit(double amount,Month month ,int day, int year)//function to deposit
{
   if(amount>0) //check if positive
   {
       balance+=amount;
       totalNetDeposits+=amount;
       recordTransaction(DEPOSIT,month,day,year,amount);
       return true;
   }
   else //not a +ve number
   {
       return false;
   }
}
int Account::getAccountNumber()//return the accoutn number
{
   return accountNumber;
}
string Account::getName()//return the ownerName
{
   return ownerName;
}
double Account::getBalance()//return the balance amount
{
   return balance;
}
void Account::printTransactions()//prints transaction history
{
   cout<<"Transaction history for Account "<    cout<<"__________________________________________________"<    cout<<"Date\t\tAmount\t\tType"<    cout<<"__________________________________________________"<    Transaction t;
   for(int i=0;i    {
       t=transactionHistory[i];
       cout<    }
}
void Account::display()
{
   cout<<"Account Number: "<    cout<<"Name: "<    cout<<"Balance: "<    printTransactions();
}
double Account::getTotalNetDeposits()//return the totalNetDeposit value
{
   return Account::totalNetDeposits;
}

Main.cpp

#include
#include "Account.h"
using namespace std;
const int NUM_ACCOUNT=5;
Account *accounts[NUM_ACCOUNT];
int NUM_RECORDS=0; //the current number of records in the array
//returns the record for the given accNum
Account* getAccount(int accNum)
{
   for(int i=0;i    {
       if(accounts[i]->getAccountNumber()==accNum) //found a matching record
           return accounts[i];
   }
   return NULL; //if record not found , return NULL
}

int main()
{
   int choice;
   int accNum,amount,day,year;
   string name;
   int month;
   Account *acc;
     
   do
   {
       //display menu
       cout<<"1. Create Account"<        cout<<"2. Deposit Amount"<        cout<<"3. Withdraw Amount"<        cout<<"4. Print transaction history"<        cout<<"5. Display all accounts"<        cout<<"6. Display totalNetDeposits"<        cout<<"7. Exit"<        cout<<"Enter your choice: ";
       cin>>choice;
       switch(choice)
       {
           case 1:
               if(NUM_RECORDS                {
                   cout<<"Enter details for new account"<                    cout<<"Account Number: " ;
                   cin>>accNum;
                   cout<<"Name: " ;
                   cin>>name;
                   cout<<"Amount: " ;
                   cin>>amount;
                   cout<<"Day: " ;
                   cin>>day;
                   cout<<"Month(1-12): " ;
                   cin>>month;
                   cout<<"Year: ";
                   cin>>year;
                   accounts[NUM_RECORDS]=new Account(accNum,name,amount,Month(month),day,year);
                   NUM_RECORDS++;
               }
               else
               {
                   cout<<"Array already full!"<                }
               break;
           case 2:
               cout<<"Enter details for depositing amount"<                cout<<"Account Number: ";
               cin>>accNum;
               acc=getAccount(accNum); //get record for given account number;
              
               if(acc==NULL)// if not present
               {
                   cout<<"No such account!"<                    break;
               }
               cout<<"Amount: " ;
               cin>>amount;
               cout<<"Day: " ;
               cin>>day;
               cout<<"Month(1-12): " ;
               cin>>month;
               cout<<"Year: " ;
               cin>>year;
               if(acc->deposit(amount,Month(month),day,year))
               {
                   cout<<"Amount "<getAccountNumber()<                }
               else
               {
                   cout<<"Cannot deposit amount "<getAccountNumber()<                }
               break;
           case 3:
               cout<<"Enter details for withdrawing amount"<                cout<<"Account Number: " ;
               cin>>accNum;
               acc=getAccount(accNum); //get record for given account number;
              
               if(acc==NULL)// if not present
               {
                   cout<<"No such account!"<                    break;
               }
               cout<<"Amount: " ;
               cin>>amount;
               cout<<"Day: " ;
               cin>>day;
               cout<<"Month(1-12): " ;
               cin>>month;
               cout<<"Year: " ;
               cin>>year;
               if(acc->withdraw(amount,Month(month),day,year))
               {
                   cout<<"Amount "<getAccountNumber()<                }
               else
               {
                   cout<<"Cannot withdraw amount "<getAccountNumber()<                }
               break;
           case 4:
                 
              
               cout<<"Account Number: " ;
               cin>>accNum;
               acc=getAccount(accNum); //get record for given account number;
              
               if(acc==NULL)// if not present
               {
                   cout<<"No such account!"<                    break;
               }
               else
               {
                   acc->printTransactions();
               }
               break;
           case 5:
               cout<<"Details of all records"<                cout<<"_____________________________________"<               
               for(int i=0;i                    accounts[i]->display();
                  
               cout<<"_____________________________________"<                break;
           case 6:
               cout<<"Total Net Deposits = "<                break;
           case 7:
               break;
           default:
               cout<<"Invalid menu choice!"<        }
      
       cout<<"**********************************************"<               
      
   }while(choice!=7);
  
}

Output

1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 1
Enter details for new account
Account Number: 1
Name: Alice
Amount: 1000
Day: 23
Month(1-12): 1
Year: 2017
**********************************************
1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 2
Enter details for depositing amount
Account Number: 2
No such account!
**********************************************
1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 2
Enter details for depositing amount
Account Number: 1
Amount: 500
Day: 5
Month(1-12): 2
Year: 2017
Amount 500 deposited to account 1
**********************************************
1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 5
Details of all records
_____________________________________
Account Number: 1
Name: Alice
Balance: 1500
Transaction history for Account 1
__________________________________________________
Date       Amount       Type
__________________________________________________
23-Jan-2017   1000   Creation
5-Feb-2017   500   Deposit
_____________________________________
**********************************************
1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 6
Total Net Deposits = 1500
**********************************************
1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 1
Enter details for new account
Account Number: 2
Name: John
Amount: 400
Day: 10
Month(1-12): 2
Year: 2017
**********************************************
1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 1
Enter details for new account
Account Number: 3
Name: Henry
Amount: 500
Day: 15
Month(1-12): 2
Year: 2017
**********************************************
1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 1
Enter details for new account
Account Number: 4
Name: Angel
Amount: 600
Day: 20
Month(1-12): 2
Year: 2017
**********************************************
1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 5
Details of all records
_____________________________________
Account Number: 1
Name: Alice
Balance: 1500
Transaction history for Account 1
__________________________________________________
Date       Amount       Type
__________________________________________________
23-Jan-2017   1000   Creation
5-Feb-2017   500   Deposit
Account Number: 2
Name: John
Balance: 400
Transaction history for Account 2
__________________________________________________
Date       Amount       Type
__________________________________________________
10-Feb-2017   400   Creation
Account Number: 3
Name: Henry
Balance: 500
Transaction history for Account 3
__________________________________________________
Date       Amount       Type
__________________________________________________
15-Feb-2017   500   Creation
Account Number: 4
Name: Angel
Balance: 600
Transaction history for Account 4
__________________________________________________
Date       Amount       Type
__________________________________________________
20-Feb-2017   600   Creation
_____________________________________
**********************************************
1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 1
Enter details for new account
Account Number: 5
Name: Peter
Amount: 800
Day: 25
Month(1-12): 2
Year: 2017
**********************************************
1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 1
Array already full!
**********************************************
1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 3
Enter details for withdrawing amount
Account Number: 2
Amount: 700
Day: 1
Month(1-12): 3
Year: 2017
Cannot withdraw amount 700 from account 2
**********************************************
1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 4
Account Number: 2
Transaction history for Account 2
__________________________________________________
Date       Amount       Type
__________________________________________________
10-Feb-2017   400   Creation
**********************************************
1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 3
Enter details for withdrawing amount
Account Number: 2
Amount: 200
Day: 1
Month(1-12): 3
Year: 2017
Amount 200 withdrawn from account 2
**********************************************
1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 5
Details of all records
_____________________________________
Account Number: 1
Name: Alice
Balance: 1500
Transaction history for Account 1
__________________________________________________
Date       Amount       Type
__________________________________________________
23-Jan-2017   1000   Creation
5-Feb-2017   500   Deposit
Account Number: 2
Name: John
Balance: 200
Transaction history for Account 2
__________________________________________________
Date       Amount       Type
__________________________________________________
10-Feb-2017   400   Creation
1-Mar-2017   200   Withdraw
Account Number: 3
Name: Henry
Balance: 500
Transaction history for Account 3
__________________________________________________
Date       Amount       Type
__________________________________________________
15-Feb-2017   500   Creation
Account Number: 4
Name: Angel
Balance: 600
Transaction history for Account 4
__________________________________________________
Date       Amount       Type
__________________________________________________
20-Feb-2017   600   Creation
Account Number: 5
Name: Peter
Balance: 800
Transaction history for Account 5
__________________________________________________
Date       Amount       Type
__________________________________________________
25-Feb-2017   800   Creation
_____________________________________
**********************************************
1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 6
Total Net Deposits = 3600
**********************************************
1. Create Account
2. Deposit Amount
3. Withdraw Amount
4. Print transaction history
5. Display all accounts
6. Display totalNetDeposits
7. Exit
Enter your choice: 7

Add a comment
Know the answer?
Add Answer to:
Design a bank account class named Account that has the following private member variables:
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
  • Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type...

    Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type int Name of type String Balance of type float Public members void Init) method to enter the values of data members void Show) method to display the values of data members void Deposit(int Amt) method to increase Balance by Amt void Withdraw(int Amt) method to reduce Balance by Amt (only if required balance exists in account) float RBalance() member function that returns the value...

  • c++ please    Define the class bankAccount to implement the basic properties of a bank account....

    c++ please    Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member func- tions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 compo- nents of...

  • (The Account class) Design a class named Account that contains: A private int data field named...

    (The Account class) Design a class named Account that contains: A private int data field named id for the account (default 0). A private double data field named balance for the account (default 0). A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default...

  • 9.7 (The Account class) Design a class named Account that contains: • A private int data...

    9.7 (The Account class) Design a class named Account that contains: • A private int data field named id for the account (default o). • A private double data field named balance for the account (default o). • A private double data field named annualInterestRate that stores the current interest rate (default o). Assume that all accounts have the same interest rate. • A private Date data field named dateCreated that stores the date when the account was created. •...

  • C++ Design a class bankAccount that defines a bank account as an ADT and implements the...

    C++ Design a class bankAccount that defines a bank account as an ADT and implements the basic properties of a bank account. The program will be an interactive, menu-driven program. a. Each object of the class bankAccount will hold the following information about an account: account holder’s name account number balance interest rate The data members MUST be private. Create an array of the bankAccount class that can hold up to 20 class objects. b. Include the member functions to...

  • PYTHON PROGRAMMING LANGUAGE Design a class named Savings Account that contains: A private int data field...

    PYTHON PROGRAMMING LANGUAGE Design a class named Savings Account that contains: A private int data field named id for the savings account. A private float data field named balance for the savings account. A private float data field named annuallnterestRate that stores the current interest rate. A_init_ that creates an account with the specified id (default 0), initial balance (default 100), and annual interest rate (default 0). . The accessor and mutator methods for id, balance, and annuallnterestRate. A method...

  • Design a class named BankAccount that contains: 1. A private int data field named accountId for...

    Design a class named BankAccount that contains: 1. A private int data field named accountId for the account. 2. A private double data field named accountBalance for the account (default 0). 3. A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. 4. A private Date data field named dateCreated that stores the date when the account was created. 5. A private int data field named numberOfDeposits...

  • Design a class named BankAccount containing the following data field and methods. • One double data...

    Design a class named BankAccount containing the following data field and methods. • One double data field named balance with default values 0.0 to denote the balance of the account. • A no-arg constructor that creates a default bank account. • A constructor that creates a bank account with the specified balance.  throw an IllegalArgumentException when constructing an account with a negative balance • The accessor method for the data field. • A method named deposit(double amount) that deposits...

  • the programing language is C++ TIC PEO. Design a generic class to hold the following information...

    the programing language is C++ TIC PEO. Design a generic class to hold the following information about a bank account! Balance Number of deposits this month Number of withdrawals Annual interest rate Monthly service charges The class should have the following member functions: Constructor: Accepts arguments for the balance and annual interest rate. deposit: A virtual function that accepts an argument for the amount of the deposit. The function should add the argument to the account balance. It should also...

  • Design and implement a C++ class called Date that has the following private member variables month...

    Design and implement a C++ class called Date that has the following private member variables month (int) day (nt) . year (int Add the following public member functions to the class. Default Constructor with all default parameters: The constructors should use the values of the month, day, and year arguments passed by the client program to set the month, day, and year member variables. The constructor should check if the values of the parameters are valid (that is day is...

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
ADVERTISEMENT