In: Computer Science
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).
Here is what i have so far:
#include <iostream>
#include <string>
using namespace std;
class bankAccount{ // bank class
private: //private data members
string holderName;
string accountType;
int accountNumber;
float balance;
float interestRate;
float round(float valuee) // private function to round off
value
{
float num = (int)(valuee * 100 + .5);
return (float)num/ 100;
}
public:
bankAccount(){ //default cnstructor
accountNumber=0;
balance=0.00;
interestRate=0.00;
}
// mutator function of the data members
void setHolderName(string h){
holderName=h;
}
void setAccountType(string a){
accountType=a;
}
void setAccountNumber(int n){
accountNumber=n;
}
void setBalance(float bal){
round(bal);
balance=bal;
}
void setIntersetRate(float rat){
interestRate =rat;
}
// accessor function for the data members (private)
string getHolderName(){
return holderName;
}
string getAccountType(){
return accountType;
}
int getAccountNumber(){
return accountNumber;
}
float getBalance(){
return balance;
}
float getInterestRate(){
return interestRate;
}
};
void menu(){ // menu to display functions
cout<<endl;
cout<<"1: Enter 1 to add a new customer. "<<endl;
cout<<"2: Enter 2 for an existing
customer."<<endl;
cout<<"3: Enter 3 to print customers data.
"<<endl;
cout<<"9: Enter 9 to exit the program. "<<endl;
}
int main() {
string name;
string type;
int num = 0;
float balance;
float rate;
bankAccount customer[10]; // array of size 10
int count=0; // will let us know the record and will only show the
record that have data stored
int choice;
while(1){ // until user presses 9
menu();
cin>>choice;
if(choice==1){ // insert data
num=num % 10000+100; // get random account number
cout<<"Enter customer's name: ";
cin.ignore();
getline(cin,name);
cout<<"Enter account type (checking/savings): ";
getline(cin,type);
cout<<"Enter amount to be deposited to open account: ";
cin>>balance;
cout<<"Enter interest rate (as a percent): ";
cin>>rate;
// store data into the array
customer[count].setHolderName(name);
customer[count].setAccountType(type);
customer[count].setAccountNumber(num);
customer[count].setBalance(balance);
customer[count].setIntersetRate(rate);
count++;
}
else if(choice==2){
// search function for existing users to update and view
record
cout<<"Enter Account Name to update record: ";
cin>>name;
for(int i=0;i<count;i++){
if(name==customer[i].getHolderName()){
cout<<"---------- RECORD FOUND
---------"<<endl;
cout<<"Account Number:
"<<customer[i].getAccountNumber()<<endl;
cout<<"Account Holder Name:
"<<customer[i].getHolderName()<<endl;
cout<<"Account Type:
"<<customer[i].getAccountType()<<endl;
cout<<"Account Balance:
"<<customer[i].getBalance()<<endl;
cout<<"Account Interest Rate:
"<<customer[i].getInterestRate()<<endl;
cout<<"--------------------------"<<endl;
cout<<"Enter data to update "<<endl<<endl;
cout<<"Enter customer's name: ";
cin.ignore();
getline(cin,name);
cout<<"Enter account type (checking/savings): ";
getline(cin,type);
cout<<"Enter amount to be deposited to open account: ";
cin>>balance;
cout<<"Enter interest rate (as a percent): ";
cin>>rate;
customer[i].setHolderName(name);
customer[i].setAccountType(type);
customer[i].setAccountNumber(num);
customer[i].setBalance(balance);
customer[i].setIntersetRate(rate);
}
}
}
else if(choice==3){
//.. view all record of bank
cout<<endl<<"*********** ACCOUNT RECORDS
***********"<<endl;
for(int i=0;i<count;i++){
cout<<endl<<"-------------------------------"<<endl;
cout<<"Account Number:
"<<customer[i].getAccountNumber()<<endl;
cout<<"Account Holder Name:
"<<customer[i].getHolderName()<<endl;
cout<<"Account Type:
"<<customer[i].getAccountType()<<endl;
cout<<"Account Balance:
$"<<customer[i].getBalance()<<endl;
cout<<"Account Interest Rate:
"<<customer[i].getInterestRate()<<"%"<<endl;
}
}
else if(choice==9){ //.. exit function
return 0;
}
else{
cout<<"Invalid choice"<<endl;
break;
}
}
}
#include <iostream>
#include <string>
using namespace std;
class bankAccount{ // bank class
private: //private data members
string holderName;
string accountType;
int accountNumber;
float balance;
float interestRate;
float round(float valuee) // private function to round off
value
{
float num = (int)(valuee * 100 + .5);
return (float)num/ 100;
}
public:
bankAccount(){ //default cnstructor
accountNumber=0;
balance=0.00;
interestRate=0.00;
}
// mutator function of the data members
void setHolderName(string h){
holderName=h;
}
void setAccountType(string a){
accountType=a;
}
void setAccountNumber(int n){
accountNumber=n;
}
void setBalance(float bal){
round(bal);
balance=bal;
}
void setIntersetRate(float rat){
interestRate =rat;
}
// accessor function for the data members (private)
string getHolderName(){
return holderName;
}
string getAccountType(){
return accountType;
}
int getAccountNumber(){
return accountNumber;
}
float getBalance(){
return balance;
}
float getInterestRate(){
return interestRate;
}
};
void menu(){ // menu to display functions
cout<<endl;
cout<<"1: Enter 1 to add a new customer. "<<endl;
cout<<"2: Enter 2 for an existing
customer."<<endl;
cout<<"3: Enter 3 to print customers data.
"<<endl;
cout<<"9: Enter 9 to exit the program. "<<endl;
}
int main() {
string name;
string type;
int num = 0;
float balance;
float rate;
bankAccount customer[10]; // array of size 10
int count=0; // will let us know the record and will only show the
record that have data stored
int choice;
while(1){ // until user presses 9
menu();
cin>>choice;
if(choice==1){ // insert data
num=num % 10000+100; // get random account number
cout<<"Enter customer's name: ";
cin.ignore();
getline(cin,name);
cout<<"Enter account type (checking/savings): ";
getline(cin,type);
cout<<"Enter amount to be deposited to open account: ";
cin>>balance;
cout<<"Enter interest rate (as a percent): ";
cin>>rate;
// store data into the array
customer[count].setHolderName(name);
customer[count].setAccountType(type);
customer[count].setAccountNumber(num);
customer[count].setBalance(balance);
customer[count].setIntersetRate(rate);
count++;
}
else if(choice==2){
// search function for existing users to update and view
record
cout<<"Enter Account Name to update record: ";
cin>>name;
for(int i=0;i<count;i++){
if(name==customer[i].getHolderName()){
cout<<"---------- RECORD FOUND
---------"<<endl;
cout<<"Account Number:
"<<customer[i].getAccountNumber()<<endl;
cout<<"Account Holder Name:
"<<customer[i].getHolderName()<<endl;
cout<<"Account Type:
"<<customer[i].getAccountType()<<endl;
cout<<"Account Balance:
"<<customer[i].getBalance()<<endl;
cout<<"Account Interest Rate:
"<<customer[i].getInterestRate()<<endl;
cout<<"--------------------------"<<endl;
cout<<"Enter data to update "<<endl<<endl;
cout<<"Enter customer's name: ";
cin.ignore();
getline(cin,name);
cout<<"Enter account type (checking/savings): ";
getline(cin,type);
cout<<"Enter amount to be deposited to open account: ";
cin>>balance;
cout<<"Enter interest rate (as a percent): ";
cin>>rate;
customer[i].setHolderName(name);
customer[i].setAccountType(type);
customer[i].setAccountNumber(num);
customer[i].setBalance(balance);
customer[i].setIntersetRate(rate);
}
}
}
else if(choice==3){
//.. view all record of bank
cout<<endl<<"*********** ACCOUNT RECORDS
***********"<<endl;
for(int i=0;i<count;i++){
cout<<endl<<"-------------------------------"<<endl;
cout<<"Account Number:
"<<customer[i].getAccountNumber()<<endl;
cout<<"Account Holder Name:
"<<customer[i].getHolderName()<<endl;
cout<<"Account Type:
"<<customer[i].getAccountType()<<endl;
cout<<"Account Balance:
$"<<customer[i].getBalance()<<endl;
cout<<"Account Interest Rate:
"<<customer[i].getInterestRate()<<"%"<<endl;
}
}
else if(choice==9){ //.. exit function
return 0;
}
else{
cout<<"Invalid choice"<<endl;
break;
}
}
}
//all things are good what you want to add more can you elaborate please.