I need to create a bankAccount class checkingAccount class a
I need to create a bankAccount class, checkingAccount class, and a savingsAccount class. I understand how to create the base class for the most part, but I\'m having trouble creating the derived classes. I\'d appreciate any help I can get!
What I need to do:
a) Define the class bankAccount to store a bank customer\'s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors.
b) Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class inherits members to store the account number and the balance from the base class. A customer with a checking account typically receives interest, maintains a minimum balance, and pays service charges if the balance falls below the minimum balance. Add member variables to store this additional information. In addition to the operations inherited from the base class, this class should provide the following operations: set interest rate, retrieve interest rate, set minimum balance, retrieve minimum balance, set service charges, retrieve service charges, post interest, verify if the balance is less than the minimum balance, write a check, withdraw (override the method of the base class), and print account information. Add appropriate constructors.
c) Every bank offers a savings account. Derive the class savingsAccount from the class bankAccount (designed in part (a)). This class inherits members to store the account number and the balance from the base class. A customer with a savings account typically receives interest, makes deposits, and withdraws money. In addition to the operations inherited from the base class, this class should provide the following operations: set interest rate, retrieve interest rate, post interest, withdraw (override the method of the base class), and print account information. Add appropriate constructors.
d) Write a program to test your classes designed in parts (b) and (c)
Also, I need to create this class:
In C++, the largest int value is 2147483647. So, an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an array. Design a class named largeIntegers such that an object of this class can store an integer of any number of digits. Add operations to add, subtract, multiply, and compare integers stored in two objects. Also add constructors to properly initialize objects and functions to set, retrieve, and print the values of objects.
Thanks in advance!
Solution
The following program is the answer to all your questions in a a very well defined manner and has comments for self understanding. It is compiled using dev c++ and runs smooth.
A cheque structure variable has been created for smooth transactions of cheques and encapsulation of cheque balance and number and passing and returning to and from functions.
#include<stdio.h>
#include<conio.h>
#include<iostream>
using namespace std;
struct cheque //to create a cheque structure for cheques handling
{
public :
int num;
double bal;
};
class bankAccount //the base class
{
protected:
int accNum;
double balance;
public:
bankAccount() //the constructor
{
accNum=0;
balance=0;
}
void setaccNum() //function to set account number
{
int a;
cout<<\"\ Please enter the account number\";
cin>>a;
accNum=a;
}
int getaccNum() //to retrieve the account number
{
cout<<\"\ Account Number :\"<<accNum;
return accNum;
}
double getbalance() //to retrieve the balance
{
cout<<\"\ Account balance\"<<balance;
return balance;
}
void deposit(int a,double b) //deposit function
{
if(accNum==a)
{
balance=balance+b;
cout<<\"\ Balance Updated\";
}
else
{
cout<<\"\ Account numbers dont match\";
}
}
void withdraw(int a, double b)//withdraw function
{
if(accNum==a)
{
if(b<=balance)
{
balance=balance-b;
cout<<\"\ Balance withdrawn\";
}
else
{
cout<<\"\ Not enough balance left in account\";
}
}
else{
cout<<\"\ Account Numbers dont match\";
}
}
void printinfo() //printing function
{
cout<<\"\ \ Account Information :-\";
cout<<\"\ Account Number :\"<<accNum;
cout<<\"\ Account Balance :\"<<balance;
}
};
class checkingAccount: public bankAccount //creating the derived class
{
protected:
float interestRate;
double minBal;
float serviceCharge;
public:
checkingAccount() //Constructor
{
interestRate=0;
minBal=0;
serviceCharge=0;
}
void setinterestRate()//function to set the interest rate
{
cout<<\"\ Please enter the Interest Rate\";
cin>>interestRate;
}
void setminBalance()//function to set the minimum Balance
{
cout<<\"\ Please enter the minimum balance required per account :\";
cin>>minBal;
}
double getminBalance()//function to get minimum balance
{
cout<<\"\ The minimum balance allowed int he account is :\";
cout<<minBal;
return minBal;
}
void setserviceCharge()//function to set the service charge
{
cout<<\"\ Please enter the service charge per account :\";
cin>>serviceCharge;
}
float getserviceCharge()//function to retrieve service Charge
{
cout<<\"\ The service charge per account is :\";
cout<<serviceCharge;
return serviceCharge;
}
void postInterest()//function to calculate and update account with the interest
{
float time;
cout<<\"\ Calculating Interest rate and updating the account\";
cout<<\"\ Please enter time (required to calculate interest)\";
cin>>time;
double r;
r=(interestRate/100)*time*balance;
balance=balance+r;
cout<<\"\ The interest paid :\"<<r;
cout<<\"The updated balance with interest :\"<<balance;
}
int verifyBalance()
{
if(balance<minBal)
{
cout<<\"\ Not enough balance please add money to your account\";
cout<<\"\ Minimum balance is :\"<<minBal;
return 0;
}
else{
cout<<\"\ Balance is over minimum balance\";
return 1;
}
}
cheque writeCheque() //function to write a cheque
{
cheque a;
cout<<\"\ ENter the cheque number\";
cin>>a.num;
cout<<\"\ Enter the cheque amount :\";
cin>>a.bal;
if(a.bal<=balance)
{
cout<<\"\ Cheque has been written\";
cout<<\"\ CHeque No :\"<<a.num;
cout<<\"\ Cheque amount\"<<a.bal;
return a;
}
else
{
cout<<\"\ Not enough funds to write the cheque\";
a.bal=0;
a.num=0;
return a;
}
}
void withdrawCheque(cheque a) //function to withdraw a cheque
{
cout<<\"\ CHeque Withdraw in process...\";
if(a.bal<=balance)
if(a.bal<balance)
{
cout<<\"\ CHeque No :\"<<a.num;
cout<<\"\ Cheque amount\"<<a.bal;
balance=balance-a.bal;
cout<<\"\ CHeque Withdrawn\";
cout<<\"\ New Balance :\"<<balance;
}
else
{
cout<<\"\ Cheque Bounced\";
}
}
void printinfo() //printing function overidden
{
cout<<\"\ \ Account Information :-\";
cout<<\"\ Account Number :\"<<accNum;
cout<<\"\ Account Balance :\"<<balance;
}
};
class savingsAccount: public bankAccount //another derived class
{
protected:
float interestRate;
public:
savingsAccount() //Constructor
{
interestRate=0;
}
void setinterestRate()//function to set the interest rate
{
cout<<\"\ Please enter the Interest Rate for Savings Account\";
cin>>interestRate;
}
void retrieveInterest()//function to see the interest rate
{
cout<<\"\ The interest rate is :\"<<interestRate;
}
void postInterest()//function to calculate and update account with the interest
{
float time;
cout<<\"\ Savings Account Interest rate calculation :-\";
cout<<\"\ Calculating Interest rate and updating the account\";
cout<<\"\ Please enter time (required to calculate interest)\";
cin>>time;
double r;
r=(interestRate/100)*time*balance;
balance=balance+r;
cout<<\"\ The interest paid :\"<<r;
cout<<\"The updated balance with interest :\"<<balance;
}
void printinfo() //printing function overidden
{
cout<<\"\ \ Account Information :-\";
cout<<\"\ Account Number :\"<<accNum;
cout<<\"\ Account Balance :\"<<balance;
}
};
int main(void)
{
int a;
double b;
cheque chq;
checkingAccount acc1;
savingsAccount acc2;
acc1.setaccNum();
acc1.getbalance();
acc1.printinfo();
cout<<\"\ Please enter account number :\"; //balance deposit
cin>>a;
cout<<\"\ Please enter deposit balance :\";
cin>>b;
acc1.deposit(a,b);
acc1.printinfo();
cout<<\"\ Please enter account number :\";//balance withdraw
cin>>a;
cout<<\"\ Please enter withdraw balance :\";
cin>>b;
acc1.withdraw(a,b);
acc1.printinfo();
acc1.setminBalance();
acc1.setinterestRate();
acc1.setserviceCharge();
acc1.getminBalance();
acc1.verifyBalance();
acc1.postInterest();
acc1.printinfo();
acc1.writeCheque();
cout<<\"\ Please enter cheque number :\";
cin>>chq.num;
cout<<\"\ Please enter deposit balance :\";
cin>>chq.bal;
acc1.withdrawCheque(chq);
acc1.printinfo();
//Now for account 2 savings account
acc2.setaccNum();
acc2.getbalance();
acc2.printinfo();
cout<<\"\ Please enter account number :\"; //balance deposit
cin>>a;
cout<<\"\ Please enter deposit balance :\";
cin>>b;
acc2.deposit(a,b);
acc2.printinfo();
cout<<\"\ Please enter account number :\";//balance withdraw
cin>>a;
cout<<\"\ Please enter withdraw balance :\";
cin>>b;
acc2.withdraw(a,b);
acc2.printinfo();
acc2.setinterestRate();
acc2.postInterest();
acc2.printinfo();
return 0;
}
_______________________________________________________________________________________________
New Edited Program with Overidden Functions :-
#include<stdio.h>
#include<conio.h>
#include<iostream>
using namespace std;
struct cheque //to create a cheque structure for cheques handling
{
public :
int num;
double bal;
};
class bankAccount //the base class
{
protected:
int accNum;
double balance;
public:
bankAccount() //the constructor
{
accNum=0;
balance=0;
}
void setaccNum() //function to set account number
{
int a;
cout<<\"\ Please enter the account number\";
cin>>a;
accNum=a;
}
int getaccNum() //to retrieve the account number
{
cout<<\"\ Account Number :\"<<accNum;
return accNum;
}
double getbalance() //to retrieve the balance
{
cout<<\"\ Account balance\"<<balance;
return balance;
}
void deposit(int a,double b) //deposit function
{
if(accNum==a)
{
balance=balance+b;
cout<<\"\ Balance Updated\";
}
else
{
cout<<\"\ Account numbers dont match\";
}
}
void withdraw(int a, double b)//withdraw function
{
if(accNum==a)
{
if(b<=balance)
{
balance=balance-b;
cout<<\"\ Balance withdrawn\";
}
else
{
cout<<\"\ Not enough balance left in account\";
}
}
else{
cout<<\"\ Account Numbers dont match\";
}
}
void printinfo() //printing function
{
cout<<\"\ \ Account Information :-\";
cout<<\"\ Account Number :\"<<accNum;
cout<<\"\ Account Balance :\"<<balance;
}
};
class checkingAccount: public bankAccount //creating the derived class
{
protected:
float interestRate;
double minBal;
float serviceCharge;
public:
checkingAccount() //Constructor
{
interestRate=0;
minBal=0;
serviceCharge=0;
}
void setinterestRate(float a)//function to set the interest rate
{
interestRate=a;
cout<<\"\ Interest rate is set\";
}
void setminBalance(double a)//function to set the minimum Balance
{
minBal=a;
cout<<\"\ Min Balance is set\";
}
double getminBalance()//function to get minimum balance
{
cout<<\"\ The minimum balance allowed int he account is :\";
cout<<minBal;
return minBal;
}
void setserviceCharge(float a)//function to set the service charge
{
serviceCharge=a;
cout<<\"\ Service CHarge is Set\";
}
float getserviceCharge()//function to retrieve service Charge
{
cout<<\"\ The service charge per account is :\";
cout<<serviceCharge;
return serviceCharge;
}
void postInterest()//function to calculate and update account with the interest
{
float time;
cout<<\"\ Calculating Interest rate and updating the account\";
cout<<\"\ Please enter time (required to calculate interest)\";
cin>>time;
double r;
r=(interestRate/100)*time*balance;
balance=balance+r;
cout<<\"\ The interest paid :\"<<r;
cout<<\"The updated balance with interest :\"<<balance;
}
int verifyBalance()
{
if(balance<minBal)
{
cout<<\"\ Not enough balance please add money to your account\";
cout<<\"\ Minimum balance is :\"<<minBal;
return 0;
}
else{
cout<<\"\ Balance is over minimum balance\";
return 1;
}
}
cheque writeCheque() //function to write a cheque
{
cheque a;
cout<<\"\ ENter the cheque number\";
cin>>a.num;
cout<<\"\ Enter the cheque amount :\";
cin>>a.bal;
if(a.bal<=balance)
{
cout<<\"\ Cheque has been written\";
cout<<\"\ CHeque No :\"<<a.num;
cout<<\"\ Cheque amount\"<<a.bal;
return a;
}
else
{
cout<<\"\ Not enough funds to write the cheque\";
a.bal=0;
a.num=0;
return a;
}
}
void withdraw(int a, double b)//withdraw function overidden
{
if(accNum==a)
{
if(b<=balance)
{
balance=balance-b;
cout<<\"\ Balance withdrawn\";
}
else
{
cout<<\"\ Not enough balance left in account\";
}
}
else{
cout<<\"\ Account Numbers dont match\";
}
}
void withdrawCheque(cheque a) //function to withdraw a cheque
{
cout<<\"\ CHeque Withdraw in process...\";
if(a.bal<=balance)
if(a.bal<balance)
{
cout<<\"\ CHeque No :\"<<a.num;
cout<<\"\ Cheque amount\"<<a.bal;
balance=balance-a.bal;
cout<<\"\ CHeque Withdrawn\";
cout<<\"\ New Balance :\"<<balance;
}
else
{
cout<<\"\ Cheque Bounced\";
}
}
void printinfo() //printing function overidden
{
cout<<\"\ \ Account Information :-\";
cout<<\"\ Account Number :\"<<accNum;
cout<<\"\ Account Balance :\"<<balance;
}
};
class savingsAccount: public bankAccount //another derived class
{
protected:
float interestRate;
public:
savingsAccount() //Constructor
{
interestRate=0;
}
void setinterestRate(float a)//function to set the interest rate
{
interestRate=a;
cout<<\"\ Interest Rate is Set\";
}
void retrieveInterest()//function to see the interest rate
{
cout<<\"\ The interest rate is :\"<<interestRate;
}
void postInterest()//function to calculate and update account with the interest
{
float time;
cout<<\"\ Savings Account Interest rate calculation :-\";
cout<<\"\ Calculating Interest rate and updating the account\";
cout<<\"\ Please enter time (required to calculate interest)\";
cin>>time;
double r;
r=(interestRate/100)*time*balance;
balance=balance+r;
cout<<\"\ The interest paid :\"<<r;
cout<<\"The updated balance with interest :\"<<balance;
}
void withdraw(int a, double b)//withdraw function overidden
{
if(accNum==a)
{
if(b<=balance)
{
balance=balance-b;
cout<<\"\ Balance withdrawn\";
}
else
{
cout<<\"\ Not enough balance left in account\";
}
}
else{
cout<<\"\ Account Numbers dont match\";
}
}
void printinfo() //printing function overidden
{
cout<<\"\ \ Account Information :-\";
cout<<\"\ Account Number :\"<<accNum;
cout<<\"\ Account Balance :\"<<balance;
}
};
int main(void)
{
int a;
double b;
cheque chq;
checkingAccount acc1;
savingsAccount acc2;
acc1.setaccNum();
acc1.getbalance();
acc1.printinfo();
cout<<\"\ Please enter account number :\"; //balance deposit
cin>>a;
cout<<\"\ Please enter deposit balance :\";
cin>>b;
acc1.deposit(a,b);
acc1.printinfo();
cout<<\"\ Please enter account number :\";//balance withdraw
cin>>a;
cout<<\"\ Please enter withdraw balance :\";
cin>>b;
acc1.withdraw(a,b);
acc1.printinfo();
acc1.setminBalance(1000);
acc1.setinterestRate(5);
acc1.setserviceCharge(2);
acc1.getminBalance();
acc1.verifyBalance();
acc1.postInterest();
acc1.printinfo();
acc1.writeCheque();
cout<<\"\ Please enter cheque number :\";
cin>>chq.num;
cout<<\"\ Please enter deposit balance :\";
cin>>chq.bal;
acc1.withdrawCheque(chq);
acc1.printinfo();
//Now for account 2 savings account
acc2.setaccNum();
acc2.getbalance();
acc2.printinfo();
cout<<\"\ Please enter account number :\"; //balance deposit
cin>>a;
cout<<\"\ Please enter deposit balance :\";
cin>>b;
acc2.deposit(a,b);
acc2.printinfo();
cout<<\"\ Please enter account number :\";//balance withdraw
cin>>a;
cout<<\"\ Please enter withdraw balance :\";
cin>>b;
acc2.withdraw(a,b);
acc2.printinfo();
acc2.setinterestRate(8);
acc2.postInterest();
acc2.printinfo();
return 0;
}














