Question :Create a class Account with the following private member variablesData TypeVariable Namechar[]accountNumberdoubleamountchar[]accountHolderUse appropriate Get and Put function to get and display the values for Account classCreate a function calc() to calculate the interest amount as interest_amount=amount*n*r/100, where n is fixed as 5 and r as 3
#include <iostream>
using namespace std;
class Account {
char accountNumber[15];
double amount;
char accountHolder[32];
public:
void Get();
void Put();
double calc();
};
void Account::Get() {
cout << "Enter an account Number: ";
cin.getline(accountNumber, sizeof(accountNumber));
cout << "Enter an account Holder: ";
cin.getline(accountHolder, sizeof(accountHolder));
cout << "Enter an account amount: ";
cin >> amount;
}
void Account::Put() {
cout << "Account Number: " << accountNumber << endl;
cout << "Accoutn Holder: " << accountHolder << endl;
cout << "Account amount: $" << amount << endl;
}
double Account::calc() {
const int n = 5;
const int r = 3;
double interest_amount;
interest_amount = amount * n * r / 100;
amount += interest_amount;
return interest_amount;
}
int main() {
Account account;
account.Get();
cout << endl;
account.calc();
account.Put();
return 0;
}
Comments
Leave a comment