My teacher gave me the following instructions:
A. Open a text file and type at least ten records (each full record of an account should be on a separate line). Each record will consist of the following items separated by spaces:
1- Credit Card (16 digits – no dashes or spaces. You should use a string variable for credit card number).
2- First Name.
3- Last Name.
4- Interest Rate (between 11.4% and 24.9%)
5- Balance from Previous statement.
6- Current charges.
Save the file as “balances.txt”.
B. Now write a C++ program that would read each record, calculate the interest charges on the previous balance for the current period (one month), add the current charges, calculate the new balance and write out the same record format with the newly calculated balance (and 0 current charges of course).
the information I created is:
John Smith, 8970624354603214, 12.4, 5600, 7200
Liam Jones, 6243534182163415, 11.7, 7600, 6321
Jackson Miller, 5312532162438241, 13.1, 4500, 5432
David Clark, 6032824132622432, 20.1, 3200, 8321
Jack Davis, 7281834132122462, 22.6, 8200, 7334
Olivia Scott, 2561324345634250, 17.2, 5750, 8326
Sophia Baker, 3242251562708256, 15.4, 6210, 6524
Emily Collins, 7241328475436270, 23.8, 5712, 8223
Amanda Evans, 7261326870352516, 16.3, 6320, 4321
Chloe Rogers, 6132423661403240, 18.2, 3525, 6748
and the code I have is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
ifstream fin;
ofstream fout;
string firstName, lastName;
fin.open ("balances.txt");
fout.open ("balances2.txt");
fin >> firstName >> lastName >>
fout << firstName << ", " << lastName << "," << '\t'<< endl;
<< " " << lastName << endl;
fin >> creditcard >> interest >> previousbalance >> currentcharges;
fout << creditcard: " ";
fout << interest: " ";
fout << previousbalance: " ";
fout << currentcharges: " ";
fin.close ("balances.txt");
fout.close ("balances2.txt");
cout << "interest charges on previous balance for the curret period" << endl;
return 0;
}
|