No arrays, structs, or advance tools only functions, calling by references, and
ID: 3867617 • Letter: N
Question
No arrays, structs, or advance tools
only functions, calling by references, and files (fstreams and fout),loops, if statements
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 balance before calculating minimum payment), total of interest paid, amount of minimum 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 the table heading. Also output the information input from the file. 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) Sample output: Balance Owing: $ 624.00 APR as % 24 Percent for minimum payment as % 4Explanation / 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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.