Define the class bankAccount to implement the basic properties of a bank account
ID: 3857267 • Letter: D
Question
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 process up to 10 customers and write a program to illustrate how to use your class. i. The construct ii. Set the data (name, account type, balance, interest rate) iii. Deposit - receives amount of deposit iv. Withdraw - receives amount of withdraw v. Get the Interest Rate - returns the interest rate vi. Get Account Number - returns the account number vii. Get the Account Holders Name -returns the name viii. Get the Account - Type returns the account type ix. Get the balance - returns the balance x. Print - nice output of one account and all of its informationExplanation / Answer
#include <iostream>
using namespace std;
class bannkAccount {
private:
string name;
string accountType;
double balance;
int accountNumber;
double interest;
public:
static int a;
bannkAccount() {
a++;
}
void setAccountNumber() {
accountNumber = a;
}
void setName(string n) {
name =n;
}
void setAccountType(string t) {
accountType=t;
}
void setInterest(double i){
interest = i;
}
void setBalance(double b){
balance = b;
}
void deposite(double b) {
balance+=b;
}
void withdrawal(double b) {
balance-=b;
}
string getName() {
return name;
}
string getAccountType() {
return accountType;
}
double getBalance() {
return balance;
}
double getInterest() {
return interest;
}
int getAccountNumber() {
return accountNumber;
}
void print() {
cout<<"Name: "<<name<<" Account Number: "<<getAccountNumber()<<" Account Type: "<<accountType<<" Balance:"<<balance<<" Interest: "<<interest<<endl;
}
};
// Initialize static member of class Box
int bannkAccount::a = 0;
int main()
{
int size = 2; //need to change this to 10 to hold 10 account. i am testing with 2 accounts.
bannkAccount acc[size];
string name, accountType;
double balance, interest;
for(int i=0;i<size;i++){
cout<<"Enter the account name: ";
cin >> name;
cout<<"Enter the account type: ";
cin >> accountType;
cout<<"Enter account balance: ";
cin >> balance;
cout<<"Enter account interest: ";
cin >> interest;
acc[i].setName(name);
acc[i].setAccountType(accountType);
acc[i].setBalance(balance);
acc[i].setInterest(interest);
acc[i].setAccountNumber();
acc[i].deposite(100);
acc[i].withdrawal(50);
}
for(int i=0;i<size;i++){
acc[i].print();
}
return 0;
}
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Enter the account name: Suresh
Enter the account type: savings
Enter account balance: 1000
Enter account interest: 2
Enter the account name: Sekhar
Enter the account type: checking
Enter account balance: 2000
Enter account interest: 5
Name: Suresh Account Number: 1 Account Type: savings Balance:1050 Interest: 2
Name: Sekhar Account Number: 2 Account Type: checking Balance:2050 Interest: 5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.