Question

C++ Simple code please Thank you in advanceB. Write a C++ program as per the following specifications: a. Define the class BankAccount to store a bank customers accoun

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please refer below for the code with the screenshot of the output, feel free to comment for any doubts.

Code;

#include <iostream>
using namespace std;

class BankAccount{
public:
int accountNumber;
double balance;
  
void setAccountNumber(int a)
{
accountNumber = a;
}
int getAccountNumber()
{
return accountNumber;
}
double getBalance()
{
return balance;
}
void depositMoney(double a)
{
balance = balance + a;
}
void withdrawMoney(double e)
{
if(balance == 0)
{
cout<<"You have zero balance";
}
else if(balance < e)
{
cout<<"Your balance is less than the amount you want to withdraw";
}
else
{
balance = balance - e;
}
}
void printDetails()
{
cout<<"Your Account Number is: "<<accountNumber;
cout<<"\nYour balance is: "<<balance;
}
BankAccount()
{
accountNumber = 0;
balance = 0.0;
}
BankAccount(int accNumber, double bal)
{
accountNumber = accNumber;
balance = bal;
}
};

class CurrentAccount: public BankAccount{
public:
float interestRate;
double minBalance;
double ServiceCharge;
  
void setInterestRate(float a)
{
interestRate = a;
}
float getInterestRate()
{
return interestRate;
}
void setMinBalance(double a)
{
minBalance = a;
}
double getMinBalance()
{
return minBalance;
}
void setServiceCharge(double a)
{
ServiceCharge = a;
}
double getServiceCharge()
{
return ServiceCharge;
}
void postInterest()
{
double interest= 0.0;
interest = (balance*interestRate)/100;
balance = balance + interest;
if (balance<minBalance)
{
cout<<"Your balance is less than the minimum balance";
}
}
CurrentAccount()
{
interestRate = 0.0;
minBalance = 0.0;
ServiceCharge = 0.0;
}
CurrentAccount(int accNumber, double bal, float interest, double minBal,double SerChar):BankAccount(accNumber,bal)
{
interestRate = interest;
minBalance = minBal;
ServiceCharge = SerChar;
}
void withdrawMoney(double e)
{
if(balance==0)
{
cout<<"You have zero balance";
}
else if(balance < e)
{
cout<<"You balanc is less than the amount You want to withdraw";
}
else
{
balance = balance - e;
if(balance<minBalance)
{
cout<<"after withdrawal, your balance is less than the minimum balance";
}
}
BankAccount::printDetails();
}
void depositMoney(double a)
{
balance = balance + a;
}
};

class SavingAccount: public BankAccount
{
public:
float interestRate;
void setInterestRate(float a)
{
interestRate = a;
}
float getInterestRate()
{
return interestRate;
}
void postInterest()
{
double interest= 0.0;
interest = (balance*interestRate)/100;
balance = balance + interest;
}
void withdrawMoney(double e)
{
if(balance==0)
{
cout<<"You have zero balance";
}
else if(balance < e)
{
cout<<"You balanc is less than the amount you want to withdraw";
}
else
{
balance = balance - e;
}
BankAccount::printDetails();
}
SavingAccount()
{
interestRate = 0.0;
}
SavingAccount(int accNumber, double bal, float interest):BankAccount(accNumber,bal)
{
interestRate = interest;
}
};
int main()
{
BankAccount b(100,10000.5);
b.printDetails();
//CurrentAccount c(121,100,5,50,20);
//c.printDetails();
//SavingAccount s(121,100.5,6);
//c.printDetails();
return 0;
}

screenshot:

Your Account Number is: 100 - Your balance is: 10000.5

Add a comment
Know the answer?
Add Answer to:
C++ Simple code please Thank you in advance B. Write a C++ program as per the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is in C++ (using IDE Visual Studio). I am seeking assistance ASAP. Please include a...

    This is in C++ (using IDE Visual Studio). I am seeking assistance ASAP. Please include a static member in the class to automatically assign account numbers (used to process up to 10 accounts) and have the user include their first and last name. Thank you! 13. 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...

  • 14 b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount...

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

  • Q3

    A)Define the class bankAccount to store a bank customer's account number and balance .Suppose that account number is of type int m and balance is of type double . Your class should at least , provide the account number m retrive the balance , depositand withdraw money , and print account information. Add appropriate constructors.B) Every bank offers a checking account . Drive the class checkingAccount from the class bankAccount( design in part (a).This class inherits member to store theaccount...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • c++ help please. Savings accounts: Suppose that the bank offers two types of savings accounts: one...

    c++ help please. Savings accounts: Suppose that the bank offers two types of savings accounts: one that has no minimum balance and a lower interest rate and another that requires a minimum balance but has a higher interest rate (the benefit here being larger growth in this type of account). Checking accounts: Suppose that the bank offers three types of checking accounts: one with a monthly service charge, limited check writing, no minimum balance, and no interest; another with no...

  • c++ please    Define the class bankAccount to implement the basic properties of a bank account....

    c++ please    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 func- tions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 compo- nents of...

  • please rewrite this code as Pseudo-Code,.. basically rewrite the code but in english language , Thank...

    please rewrite this code as Pseudo-Code,.. basically rewrite the code but in english language , Thank you so much! public abstract class BankAccount {    //declare the required class variables    private double balance;    private int num_deposits;    private int num_withdraws;    private double annualInterest;    private double serviceCharges;       //constructor that takes two arguments    // one is to initialize the balance and other    // to initialize the annual interest rate       public BankAccount(double balance,...

  • C++ Design a class bankAccount that defines a bank account as an ADT and implements the...

    C++ Design a class bankAccount that defines a bank account as an ADT and implements the basic properties of a bank account. The program will be an interactive, menu-driven program. a. Each object of the class bankAccount will hold the following information about an account: account holder’s name account number balance interest rate The data members MUST be private. Create an array of the bankAccount class that can hold up to 20 class objects. b. Include the member functions to...

  • In this, you will create a bank account management system according to the following specifications: BankAccount...

    In this, you will create a bank account management system according to the following specifications: BankAccount Abstract Class contains the following constructors and functions: BankAccount(name, balance): a constructor that creates a new account with a name and starting balance. getBalance(): a function that returns the balance of a specific account. deposit(amount): abstract function to be implemented in both Checking and SavingAccount classes. withdraw(amount): abstract function to be implemented in both Checking and SavingAccount classes. messageTo Client (message): used to print...

  • Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the...

    Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT