Must use header file, implementation file, main program

Question

* Must use a header file, implementation file, and main program *

** Create on C++

**SET UP TO MAKE A PURCHASE AS A USER (NOT HARD CODED)

* Must use a header file, implementation file and main program *

1) Please create a credit card application (from the bank of Guido) that will use a class that has methods for:

initial balance ($1201.25) (must be function and passed in value of $1201.25)
Balance may not exceed ($1800) ** can’t borrow anymore (must be function)
Assume that the balance is on 1/1/2021
Make a purchase (must be function)
* setup to make a purchase *
compute balance with interest (must be function)
total interest = P * R * T

P = Principle Amount
N = Number of payments
R = Rate of interest
T = time (in days)
Make a payment (must be function)
Compute monthly payments based 1, 2 or 3 year loan payments (must be function)
Make a end-of-the-year summary of purchases, total interest and ending balance.
The private variables are loan amount and payment. The program should have an implementation file along with the main function. This will ask the user if they wish to borrow or repay on a loan. Use your discretion as to what a loan program would normally do.

Parameters:

Yearly Interest rate is 20% (daily compounded interest) (nothing is free in this world) 😊
Calculations for interest rate is Principle * rate * time (how long the loan is)
You don’t have to calculate leap year
This process is only for the year 2021.

* functions needed *

A) ask for current balance (must include the date i.e. 6/1/21)

B) Make a purchase (date, amount, and description of what you bought)

C) Make a payment (date, amount)

D) Calculate long-term payout (1, 2 or 3 year loan on amount)

* Summary on how does a credit card work *

1) You are borrowing money from a bank to make a purchase.

2) They want their money back at some point, but with interest on what you borrowed.

3) Your interest is calculated with a yearly rate of 10% but it is based on your daily balance. For instance, you make a purchase on 2/5/21 – you owe interest on $1201.25 from 1/1/21 to 2/5/21.

4) When you make a payment, you must calculate the new balance as of 2/5/21.

5) If I make a payment on 6/1/21, you must calculate the total interest from 2/5 – 6/1. You then have an up-to-date balance to work with.

6) If I ask for payment plan on 12/1/21, you will calculate the new balance that includes interest from 6/1/21 – 12/1/21. You will ask the user for the terms (1, 2 or 3 years) of the payments. What would the monthly payments be?

Examples:

I make a purchase on 2/19/21 of $300 of a camera, I need to figure out the days until the last calculation of interest which is on 1/1/21. Which equates to:

1 – 31 days

2 – 19

50 days out of 365 days in the year.

Interest = $1.25 ( estimated) + $1201.25

Add the actual purchase of $300

New balance on 2/5 = $1502.50

I make a payment on 6/1/21. I need to calculate the total interest not added yet to the balance:

2 – 9 days (28 – 19)

3 – 31 days

4 – 30 days

5 – 31 days

_____ total days 101 days of interest 101 out of 365 days

Balance on 6/1/21 was $1502.50, the 101 days of interest needs to be added to the total.

Example $6.01 in interest + $1502.50 = 1508.51

Payment made of $100

New balance on 6/1/21 = $1408.51

Make a payout function of 1 year:

Existing balance $1408.51

Add in the interest for 1 year roughly ($280.00)

$1408.51 + $280 = $1688.51 / 12 = $140.67 per month.

Explanation

Here in the given question, we have to write a program in C++. Where we have to use a header file, implementation file, and main program. Where there is a structure to store data and perform calculations in its, there are different classes and functions used. Also, we use different methods. All the data to enter is given in the question.

 

Code

#include<iostream>
using namespace std;

//user-defined structure to store date
struct date
{
    int month,date,year;
};

class CardBalance
{
    int T;
    date d;	
    double P,Balance,interest;
public:
    //set intitial balance
    void setbalance(double b)
    {	Balance=b;
        cout<<"\nInitial balance set to : "<<Balance;
        d.date=1;
        d.month=1;
        d.year=2001;
    }
    //check if borrow allowed or not
    int BorrowAllow(double b)
    {	if(b>1800)
            return 1;
        else
            return 0;
    }
    //function to make purchase
    double makePurchase(date dt,double amount, char s[20])
    {	int count=d.month;
        T=0;
        while(count<dt.month)
        {	if(count==1||count==3||count==5||count==7||count==8||count==10||count==12)
                T+=31;
            if(count==2)
                T+=28;
            if(count==4||count==6||count==9||count==11)
                T+=30;	
            count++;			
        }
        T+=dt.date;
        interest=Balance*0.02*T/365;
        cout<<"\nInterest: "<<interest;
        P=amount+interest+Balance;
        if(BorrowAllow(P)==1)
            cout<<"\nCan't Borrow more amount ";
        else
            Balance=P;
        cout<<"\nNew Balance on "<<dt.month<<"/"<<dt.date<<" is: "<<Balance;		
        d.date=dt.date;
        d.month=dt.month;
        d.year=dt.year;
    }
    //function to makePayment
    int makePayment(date dt, double amount)
    {	int count=d.month;
        T=0;
        while(count<dt.month)
        {	if(count==1||count==3||count==5||count==7||count==8||count==10||count==12)
                T+=31;
            if(count==2)
                T+=28;
            if(count==4||count==6||count==9||count==11)
                T+=30;	
            count++;			
        }
        T+=dt.date-d.date;
        interest=Balance*0.02*T/365;
        P=interest+Balance-amount;
        Balance=P;
        cout<<"\nPayment made of "<<amount;
        cout<<"\nNew Balance on "<<dt.month<<"/"<<dt.date<<" is: "<<Balance;	
    }
    double longTermPay(int yr)
    {	interest=Balance*0.2*yr;
        Balance=(Balance+interest)/12;
        cout<<"\nInterest per month is: "<<Balance;
    }
};

int main()
{	CardBalance obj;
    obj.setbalance(1201.25);
    date dte;
    dte.date=19;
    dte.month=2;
    dte.year=2021;
    obj.makePurchase(dte,300,"Shopping");
    dte.date=1;
    dte.month=6;
    dte.year=2021;	
    obj.makePayment(dte,100);
    obj.longTermPay(1);
    return 0;
    
    
}

Output

 header file

 

Also read, Trolls either always lie or always tell the truth.

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *