Write a class Account with following parameters: accountTitle (string), accountHolder (string), accountNumber(string), amount(double). Write public getters and setters for each class variable. You are also required to write following functions
1. withdrawAmount The user should be able to withdraw amount from his/her account. The withdrawAmount member function.
2. deductTax At every withdrawal, The program should be able to deduct tax (2.5%) from user amount.
Write main() function where program should provide following options to the user:
a. create account
b. set account title
c. set account holder name
d. set account number
e. set amount
f. get account title
g. get account holder name
h. get account number
i. get amount
j. withdraw amount
k. deduct taxes
#include <iostream>
#include <string>
using namespace std;
class Account
{
private:
string accountTitle;
string accountHolder;
string accountNumber;
double amount;
public:
Account() {};
Account(string _accountTitle, string _accountHolder, string _accountNumber, double _amount)
{
accountTitle = _accountTitle;
accountHolder = _accountHolder;
accountNumber = _accountNumber;
amount = _amount;
}
string getAccountTitle();
string getAccountHolder();
string getAccountNumber();
double getAmount();
void setAccountTitle();
void setAccountHolder();
void setAccountNumber();
void setAmount();
void withdrawAmount();
void deductTax();
};
string Account::getAccountTitle()
{
cout << "\nAccount title: " << accountTitle << "\n";
return accountTitle;
}
string Account::getAccountHolder()
{
cout << "\nAccount holder: " << accountHolder << "\n";
return accountHolder;
}
string Account::getAccountNumber()
{
cout << "\nAccount number: " << accountNumber << "\n";
return accountNumber;
}
double Account::getAmount()
{
cout << "\nAmount: " << amount << "\n";
return amount;
}
void Account::setAccountTitle()
{
string _accountTitle;
cout << "\nInput the account title: ";
cin >> _accountTitle;
accountTitle = _accountTitle;
}
void Account::setAccountHolder()
{
string _accountHolder;
cout << "\nInput the account holder: ";
cin >> _accountHolder;
accountHolder = _accountHolder;
}
void Account::setAccountNumber()
{
string _accountNumber;
cout << "\nInput the account number: ";
cin >> _accountNumber;
accountNumber = _accountNumber;
}
void Account::setAmount()
{
double _amount;
cout << "\nInput the amount: ";
cin >> _amount;
amount = _amount;
}
void Account::withdrawAmount()
{
double newAmount;
double withdrawAmount;
double tax;
cout << "\nChoose amount to withdraw: ";
cin >> withdrawAmount;
tax = (withdrawAmount * 2.5) / 100;
cout << "\n\nTax: " << tax;
newAmount = amount - (withdrawAmount + tax);
amount = newAmount;
cout << "\nNew amount: " << amount << "\n";
}
int main()
{
Account acc;
cout << "\nAccount created!" << "\n";
char choice;
do
{
cout << "\n------Menu------" << "\n";
cout << "a. Set account title" << "\n";
cout << "b. Set account holder name" << "\n";
cout << "c. Set account number" << "\n";
cout << "d. Set amount" << "\n";
cout << "e. Get account title" << "\n";
cout << "f. Get account holder name" << "\n";
cout << "g. Get account number" << "\n";
cout << "h. Get amount" << "\n";
cout << "i. Withdraw amount" << "\n";
cout << "j. Exit" << "\n";
cout << "\nChoose the operation: ";
cin >> choice;
switch (choice)
{
case 'a':
{
acc.setAccountTitle();
break;
}
case 'b':
{
acc.setAccountHolder();
break;
}
case 'c':
{
acc.setAccountNumber();
break;
}
case 'd':
{
acc.setAmount();
break;
}
case 'e':
{
acc.getAccountTitle();
break;
}
case 'f':
{
acc.getAccountHolder();
break;
}
case 'g':
{
acc.getAccountNumber();
break;
}
case 'h':
{
acc.getAmount();
break;
}
case 'i':
{
acc.withdrawAmount();
break;
}
case 'j':
{
exit(0);
}
default:
{
cout << "\nIncorrect operation, please try again" << "\n";
}
}
} while (choice != 'j');
return 0;
}
Comments
Leave a comment