Name your source code as cpp replace the text with with your

Name your source code as .cpp (replace the text with with your last name and first name, in that order) and upload to blackboard. The goal of this assignment is to design and implement classes. We will continue the lesson from the 2/27 lecture on the banking model. Write a program that implements a class model for storing and managing the following data: Test Data: Create a customer using your name and address. Create two accounts for yourself, a Checking and a Savings. Start with a $100 Credit balance in each account. Fill in the other required data as you like (date opened, time stamp). The customer should be able to perform the following actions: Get the current balance of funds in a specific account identified by the account ID value. Get the total amount of funds across ALL accounts Add money to an account specified by the ID Retrieve money from an account specified by an ID Once you have built your Class Model, write your program to implement your class by outputting to standard output the following transactions: Get balance info for your checking account. Add $10 to both checking and savings account. Retrieve $50 from your checking account Get the total available balance you now have in both accounts.

Solution


LakshmnaRao.CPP :

#include<iostream.h>
#include<conio.h>
enum Enum{Credit,Debit};
class Transaction
{
   public:
   int ID;
   Enum type;
   float Amount;

};
class Account
{
   public:
   int ID;
   char Name[20];
   char DateOpened[20];
   Transaction Transactions[5];
};
class Customer
{
   public:

   int ID;
   char Name[20];
   char Address[40];
   Account Accounts[2];
   int p,i,j;
   Customer(){
       p = 0;
   }
   float getBalance(int accountID){
       Account ac;
       for(j=0;j<2;j++)
       if(accountID==Accounts[j].ID){
           ac = Accounts[j];
       }
       float balance = 0;
       for(i=0;i<5;i++)
           balance += ac.Transactions[i].Amount;
       return balance;
   }
   float getTotalAmount(){
       float total_fund = 0;
       for(i=0;i<2;i++){
           for(j=0;j<5;j++)
               total_fund += Accounts[i].Transactions[j].Amount;
       }
       return total_fund;
   }
   void addMoney(int accountID,int amount){
       Account ac;
       for(i=0;i<2;j++)
       if(accountID==Accounts[i].ID){
           ac = Accounts[i];
       }
       ac.Transactions[p].type = Credit;
       ac.Transactions[p].Amount = amount;
       double total = 0;
       for(j=0;j<5;j++)
               total += ac.Transactions[j].Amount;
       total = total + amount;
       p++;
   }
   void removeMoney(int accountID,int amount){
       Account ac;
       for(j=0;j<2;j++)
       if(accountID==Accounts[j].ID){
           ac = Accounts[j];
       }
       ac.Transactions[p].type = Debit;
       ac.Transactions[p].Amount = amount;
       double total = 0;
       for(j=0;j<5;j++)
               total += ac.Transactions[j].Amount;
       total = total - amount;
       p++;
   }
};
void main(){
   clrscr();
   Customer cust;
   int CID = 23858;
   cout<<\"Account ID: \"<<CID<<\"Balance:\"<<cust.getBalance(CID)<<endl;
   cust.addMoney(CID,10);
   int SID = 23575;
   cust.addMoney(SID,10);
   cust.removeMoney(CID,50);
   cout<<\"Total Balance:\"<<cust.getTotalAmount()<<endl;
   getch();
}

 Name your source code as .cpp (replace the text with with your last name and first name, in that order) and upload to blackboard. The goal of this assignment i
 Name your source code as .cpp (replace the text with with your last name and first name, in that order) and upload to blackboard. The goal of this assignment i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site