//preprocessor directives
#include<iostream>
#include<fstream>
#include<iomanip>
//step 1
usingnamespace std;
int main(){
system("color f0");
cout<<"=******************************************="<<endl;
cout<<"* IT210 Business Applications with C++ *"<<endl;
cout<<"* Programmer: Richard Hoang *"<<endl;
cout<<"* Date: October 15, 2015 *"<<endl;
cout<<"* Assignment 2 - Interest Calculator *"<<endl;
cout<<"=******************************************="<<endl;
//declare objects of type ifstream and ofstream
ifstream fin;
ofstream fout;
//open fin and fout or associate files with fin and fout
fin.open("customer.txt");
fout.open("output.txt");
//error check fin and fout
if(!fin){
cout<<"Input failure/n";
system("pause");
return 1;
}//end of fin error check
if(!fout){
cout<<"Output failure/n";
system("pause");
return 1;
}//end of fout error check
cout<<"Successfully opened input/output files"<<endl;
//execute at this stage always
cout<<endl;
cout<<endl;
cout<<"This program calculates the interest on unpaid"<<endl;
cout<<"credit card balances using the average daily balance"<<endl;
cout<<"and the total interest owed to the Bank"<<endl;
cout<<endl;
cout<<endl;
//read from input text files
string firstName;
string lastName;
int credit;
float netBalance;
float payment;
int d1;
int d2;
float averageDailybalance;
float interest;
float APR;
//output to monitor and text files
cout<<"************************************************************"<<endl;
cout<<"123456789012345678901234567890123456789012345678901234567890"<<endl;
cout<<"************************************************************"<<endl;
cout<<left<<setw(20)<<"FULL NAME"<<setw(13)<<"CARD #"<<setw(10)<<"BALANCE"<<
setw(9)<<"APR (%)"<<setw(8)<<"INTEREST"<<endl;
cout<<"------------------------------------------------------------"<<endl;
while(fin){
//step 4
fin>>firstName>>lastName>>credit>>netBalance>>payment>>d1>>d2;
averageDailybalance=(netBalance*d1-payment*d2)/d1;
if(averageDailybalance<=100.00){
APR="5.0/n";
system("pause");
return 1;
}
interest=averageDailybalance*(APR/100.0*12.0);
cout<<left<<setw(20)<<firstName<<setw(10)<<credit<<setw(10)<<right<<fixed<<setprecision(2)
<<netBalance<<setw(10)<<APR<<setw(10)<<interest<<endl;
fout<<left<<setw(20)<<firstName<<setw(10)<<credit<<setw(10)<<right<<fixed<<setprecision(2)
<<netBalance<<setw(10)<<APR<<setw(10)<<interest<<endl;
if(fin.peek()=='\n')fin.ignore();
}//end of fin controlled while
//fin.close fin and fout
fin.close();
fout.close();
cout<<"------------------------------------------------------------"<<endl;
cout<<endl;
cout<<endl;
cout<<"12345678901234567890123456789012345678901234567890"<<endl;
cout<<"**************************************************"<<endl;
cout<<endl;
cout<<endl;
cout<<"Total interest owed to Bank is $"<<interest;
cout<<endl;
cout<<endl;
cout<<"**************************************************"<<endl;
cout<<endl;
cout<<endl;
system("pause");
return 0;
}//end of main