Question

In: Computer Science

c++ The above Account class was created to model a bank account. An account has the...

c++

The above Account class was created to model a bank account. An account has the properties (keep the properties private) account number, balance, and annual interest rate, date created, and functions to deposit and withdraw. Create two derived classes for checking and saving accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn. Define a constant virtual toString() function in the Account class and override it in the derived classes to return the account number and balance as a string.
Implement the classes. Write a test program that creates objects of Account, SavingsAccount, and CheckingAccount and invokes their toString() functions.

Solutions

Expert Solution

#include <iostream>
#include<sstream>
using namespace std;

class Account{ //account class having all details of account
int AccNo=0; //variable
double balance=0;//variable
double interest=0;//variable
string date=""; //variable
public:
Account(){ //constructor
}
Account(double a,double b){ //constructor
  
AccNo=a; //private member assign value
balance=b; //private member assign value
}
void deposit(double amt){ //function for deposit
balance=balance+amt;
}
void withdraw(double amt){ //function for withdraw
if(amt<=balance){ //checking if amount is sufficient for withdrawal
balance=balance-amt;}
else{
cout<<"Insufficient amount"<<endl;
}
}
int getAcc(){ //getting AccNo
return AccNo;
}
void setAcc(double AccNo1){ //setting AccNo
AccNo=AccNo1;
}
int getbalance(){ ///getting balance
//cout<<balance;
return balance;
}
void setbalance(double balance1){ //setting balance
  
balance=balance1;
}
virtual string toString(){ //function that to display the details of Account
stringstream ss; //stringstream object
ss<<AccNo;//streaming the intger to object
string a;
ss>>a;//output to a string
stringstream ss1; //stringstream object
ss1<<balance; //streaming the intger to object
string b;
ss1>>b; //output to a string
string c="Account number: "+a+" and balance: "+b+" ";
return c;
}
};
class Checking:public Account{//inheritance
double overdraft=0;
public:
Checking(double a,double b){//constructor
setAcc(a);//setter
setbalance(b); //setter
}
string toString(){
//cout<<getbalance();
stringstream ss; //stringstream object
ss<<getAcc(); //streaming the intger to object
string a;
ss>>a; //output to a string
stringstream ss1; //stringstream object
ss1<<getbalance(); //streaming the intger to object
string b;
ss1>>b; //output to a string
//cout<<b;
string c="Account number: "+a+" and balance: "+b+" ";
return c;
}
};
class Saving:public Account{ //saving account
public:
Saving(double a,double b){ //constructor
setAcc(a); //setting AccNo.
setbalance(b); //settin balance
}
string toString(){ //display details of account
stringstream ss;
ss<<getAcc();
string a;
ss>>a;
stringstream ss1;
string b;
ss1<<getbalance();
ss1>>b;
//cout<<b;
string c="Account number: "+a+" balance: "+b+" ";
return c;
}
};
int main()
{
Saving s(639745,5000);//instance of saving class
Checking d(7146372,6000); //instance of checking class
Account c(724642,10000); //instance of Account class
cout<<s.toString()<<endl;
cout<<d.toString()<<endl;
cout<<c.toString()<<endl;
return 0;
}

If you found this answer helpful please give a thumbs up.


Related Solutions

(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
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 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...
A business process model was created by a staff member at BISMoB bank and it is...
A business process model was created by a staff member at BISMoB bank and it is believed to have many BPMN syntax errors (BPMN modelling errors). As an experienced business analyst, you are asked to read the process model carefully and find the BPMN syntax errors. This document will be used to educate novice business analysts and future staff so they can improve their process modelling techniques. What you need to do • Find 10 errors on the process model...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the data fields private): a) An int data field named id for the account. b) A double data field named balance for the account. c) A double data field named annualInterestRate that stores the current interest rate. d) A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. e) The accessor and mutator functions for id, balance, and annualInterestRate....
Form a separate model from that created in question 7 above, but using the same LS...
Form a separate model from that created in question 7 above, but using the same LS and LD equations, and show how worker and employer surpluses change based on the imposition of a wage ceiling at $17 – be sure to represent the area for dead weight loss and all values needed to calculate these changed areas and values. Again, it is not necessary to calculate the values for ES, WS, etc. but you must show the areas of these...
JAVA PROGRAM: Creates a Bank Account class with one checking account and methods to withdraw and...
JAVA PROGRAM: Creates a Bank Account class with one checking account and methods to withdraw and deposit. Test the methods in the main function.
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...
With PHP Create a class called Account that a bank might use to represent customers' bank...
With PHP Create a class called Account that a bank might use to represent customers' bank accounts. Your class should include one data member of type int to represent the account balance. Your class should provide a constructor that receives an initial balance and uses it to initialize the data member. The constructor should validate the initial balance to ensure that it is greater than or equal to 0. If not, the balance should be set to 0 and the...
*********C++ Program************ Enhance the Account class to compute the interest on the current balance. An account...
*********C++ Program************ Enhance the Account class to compute the interest on the current balance. An account has initial balance of $10,000.00, and 6% percent annual interest is compounded monthly until the investment is double. Write a main function to determine the number of months to double the initial investment. Create function name "double investment" for this project. Create a menu to allow the user to enter the initial investment and the annual interest rate. Please create a header file(bank.h) and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT