2. Define a class called CreditCardAccount that will track a credit card account
ID: 670763 • Letter: 2
Question
2. Define a class called CreditCardAccount that will track a credit card account activity for a customer.
The class should have member variables to track the balance, interest charged, and the annual percentage rate
(APR). Add member functions to handle transaction activities like the following:
View principle balance and interest; Add purchase amount to balance; Subtract payment amount from
balance; Change APR and update interest and balance. Write menu-driven testing code in the main().
Note: You must recalculate the balance whenever there is a new purchase, new payment and new APR
change (APR change will change the amount of interest). The balance reflects the amount of payment in
the next billing cycle (1 month).
I have attached a running page for your reference. The default APR is 12% and at the end of the testing,
the APR is set to 24%. Use the same testing data when you run your program.
Credit Card Transaction
1. View Balance
2. Purchase
3. Make Payment
4. Change APR
5. Exit
CURRENT BALANCE: $0.00
INTEREST CHARGE: $0.00
Credit Transaction
1. View Balance
2. Purchase
3. Make Payment
4. Change APR
5. Exit
Explanation / Answer
#include<iostream>
using namespace std;
class CreditCardAccount{
double balance;
double interest;
double annualPercentage;
public:
double getBalance(){
return balance;
}
double getInterest(){
return interest;
}
double addPurchase(double amount){
balance += amount;
interest = annualPercentage/100 * balance;
}
double payment(double amount){
balance -= amount;
}
void changeAPR(double apr){
annualPercentage = apr;
interest = annualPercentage/100 * balance;
}
};
int main(){
int choice;
CreditCardAccount c;
while(1){
cout<<"Credit card Transaction:"<<endl;
cout<<"1. View Balance"<<endl;
cout<<"2. Purchase"<<endl;
cout<<"3. Make Payment"<<endl;
cout<<"4. Change APR"<<endl;
cout<<"5. Exit"<<endl;
cin>>choice;
if(choice == 5)
break;
switch(choice){
case 1:
cout<<c.getBalance();
break;
case 2:
double purchaseAmount;
cin>>purchaseAmount;
c.addPurchase(purchaseAmount);
break;
case 3:
double makePayment;
cin>>makePayment;
c.payment(makePayment);
break;
case 4:
double apr;
cin>>apr;
c.changeAPR(apr);
break;
}
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.