Question

In: Computer Science

a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...

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;
}
}
}

Solutions

Expert Solution

#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.


Related Solutions

13. The class bankAccount stores a bank customer’s account number and balance. Suppose that account number...
13. The class bankAccount stores a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. This class provides the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. b. 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...
In C++, define the class bankAccount to implement the basic properties of a bank account. An...
In C++, 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 functions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 components of type bankAccount to...
Write a program to create a bank account and to process transactions. Call this class bankAccount...
Write a program to create a bank account and to process transactions. Call this class bankAccount A bank account can only be given an initial balance when it is instantiated. By default, a new bank account should have a balance of 0. A bank account should have a public get method, but no public set method. A bank account should have a process method with a double parameter to perform deposits and withdrawals. A negative parameter represents a withdrawal. It...
c++ programming 1.1 Class definition Define a class bankAccount to implement the basic properties of a...
c++ programming 1.1 Class definition Define a 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, check/savings/business)  Balance (double)  Interest rate (double) – store interest rate as a decimal number.  Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. 1.2 Implement...
Write a class to keep track of a balance in a bank account with a varying...
Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not allow more money to...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance:...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance: balance held in the account interestRate: annual interest rate. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount count: A static data member to track the count of the number of BankAccount objects created. Member Functions void withdraw(double amount): function which withdraws an amount from accountBalance void deposit(double...
Create a class BankAccount to hold at least the following data / information about a bank...
Create a class BankAccount to hold at least the following data / information about a bank account: Account balance Total number of deposits Total number of withdrawals Interest rate e.g., annual rate = 0.05 Service charges per month The class should have the following member functions: Constructor To set the required data. It may be parameterized or user’s input. depositAmount A virtual function used to accept an argument for the amount to be deposited. It should add the argument (amount)...
Write in Java the following: A.  A bank account class that has three protected attributes: account number...
Write in Java the following: A.  A bank account class that has three protected attributes: account number (string), customer name (string), and balance (float). The class also has a parameterized constructor and a method public void withDraw (float amount) which subtracts the amount provided as a parameter from the balance. B. A saving account class that is a child class of the bank account class with a private attribute: penality rate (float). This class also has a parameterized constructor and a...
In java, I have problem how to declare BankAccount Account = new BasicAccount(100.00); Given the class...
In java, I have problem how to declare BankAccount Account = new BasicAccount(100.00); Given the class BankAccount , implement a subclass of BankAccount called BasicAccount whose withdraw method will only withdraw money if there is enough money currently in the account (no overdrafts allowed). Assume all inputs to withdraw and the constructor will be valid non-negative doubles. public class BankAccount {     private double balance;     public BankAccount() {         balance = 0;     }     public BankAccount(double initialBalance) {         balance = initialBalance;     }     public...
java code ============ public class BankAccount { private String accountID; private double balance; /** Constructs a...
java code ============ public class BankAccount { private String accountID; private double balance; /** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount(String accountID) { balance = 0; this.accountID = accountID; } /** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount(double initialBalance, String accountID) { this.accountID = accountID; balance = initialBalance; } /** * Returns the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT