Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

no arrays no structures or classes only while,functions and pass by reference la

ID: 3866303 • Letter: N

Question

no arrays no structures or classes

only while,functions and pass by reference

lab6.txt is the 624 24 4

Write a C++ program to output the payment schedule for amount owed when each month nothing more is charged to the account but only the minimum payment is paid. The output stops when the balance is fully paid (i.e. no longer > 0). Input: Data must be done in a separate function Input the following: credit card balance, interest rate on your credit card, and percent of minimum payment. Test data: 624 24 4 Data must be read from a file called lab6.txt Calculate: This function must be called from main() from within the loop. For each month, calculate the amount of interest to be paid that month (adding this into payment due for the month, and updating new balance. If the minimum payment is less than $15.00 then set it at $15.00 if you owe at least $15.00 or the minimum payment will be just what you owe if you owe less than $15.00. Output: This function must be called from main() from within the loop. There needs to be a separate function to output month, balance at the end of the month, interest paid that month, minimum payment for that month, and the sum of amount of interest paid so far. All output must be redirected to a file. (See b http: //www.bankrate.com/calculators/managing-debt/minimum-payment-calculator.aspx)

Explanation / Answer

#include<iostream>
#include<fstream>
#include<iomanip>

using namespace std;

class credit_card {
   private:
      double balance;
      double intrest_this_month;
      double min_pay;
      double sum_intr;
      double annual_intr;
      double min_intr;
   public:
      credit_card(double bal, double intr, double min, double sintr, double aintr, double mintr);
      void calculate();
      void output_heading();
      void output_info(int a, ofstream &fout);

};

credit_card::credit_card(double bal, double intr, double min, double sintr, double aintr, double mintr){
           balance = bal;
           intrest_this_month = intr;
           min_pay = min;
           sum_intr = sintr;
           annual_intr = aintr;
           min_intr = mintr;
}


void credit_card::calculate(){


    intrest_this_month = ((annual_intr/1200) * balance);
    balance = balance + intrest_this_month;
    min_pay = (min_intr/100) * balance;
   
    if (min_pay < 15 && balance > 15){
       min_pay = 15;
    }
    if (min_pay < 15 && balance < 15){
       min_pay = balance;
    }

    balance = balance - min_pay;
    sum_intr = sum_intr + intrest_this_month;

}

void credit_card::output_heading(){

     cout << setw(10) << "Month" << setw(15) << "Balance" << setw(15) <<"Intrest" << setw(15) << "Minimum" << setw(20) << "Sum Of" << endl;
     cout << setw(10) << "     " << setw(15) << "       " << setw(15) << "this month" << setw(15) << "       " << setw(20) << "Intrest Paid" << endl;
}

void credit_card::output_info(int a, ofstream &fout){

     cout << setw(10) << a << setw(15) << setprecision(2) << fixed << balance << setw(15) << setprecision(2) << intrest_this_month;
     cout << setw(15) << setprecision(2) << min_pay << setw(20) <<setprecision(2) << sum_intr << endl;
     fout << setw(10) << a << setw(15) << setprecision(2) << fixed << balance << setw(15) << setprecision(2) << intrest_this_month;
     fout << setw(15) << setprecision(2) << min_pay << setw(20) <<setprecision(2) << sum_intr << endl;

}

int main(){


    ifstream fin;
    ofstream fout;
    double balance;
    double annual_intr;
    double min_intr;
      
   

    fin.open("lab6.txt");
    fout.open("output17.txt");
    if (fin){
       while (fin >> balance >> annual_intr >> min_intr);
       cout << "Balance owing :" << "$ " << balance << endl;
       cout << "APR as %   " << annual_intr << endl;
       cout << "Percent of minimum payment as " << min_intr << endl;
       fout << "Balance owing :" << "$ " << balance << endl;
       fout << "APR as %   " << annual_intr << endl;
       fout << "Percent of minimum payment as " << min_intr << endl;
       fin.close();
       credit_card cd(balance,0,0,0,annual_intr,min_intr);
       cd.output_heading();
       fout << setw(10) << "Month" << setw(15) << "Balance" << setw(15) <<"Intrest" << setw(15) << "Minimum" << setw(20) << "Sum Of" << endl;
       fout << setw(10) << "     " << setw(15) << "       " << setw(15) << "this month" << setw(15) << "       " << setw(20) << "Intrest Paid" << endl;
       for (int i = 0; i<5; i++){
            cd.calculate();
            cd.output_info(i+1,fout);
       }      
       fout.close();      
       
    }
    else {
        cout << "Error in opening file";
    }

    return 0;
}