1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
void SaveToFile(const string titles[], const int ratings[], int count)
{
string filename;
ofstream outfile;
filename = "tomatoes.txt";
outfile.open(filename);
PrintToText(outfile, titles, ratings, count);
WriteLine(cout, '=', 54);
cout << "SAVED TO FILE.";
}
void PrintToText(ostream& out, const string titles[], const int ratings[], int count)
{
for(int i = 0; i < count; i++)
{
out << titles[i] << '|' << " " << ratings[i];
}
}
void LoadFromFile(string titles[], int ratings[], int& count)
{
ifstream infile;
infile.open("tomatoes.txt");
if(!infile || !infile.is_open())
{
count = 0;
}
else
{
WriteLine(cout, '=', 54);
cout << "LOADING DATA FROM FILE..." << endl;
while( !infile.eof() )
{
getline(infile, titles[count], '|');
infile >> ratings[count];
count++;
}
}
}
void PrintAll(ostream& out, const string titles[], const int ratings[], int count)
{
WriteLine(out, '=', 54);
out << "PRINT ALL" << endl;
WriteLine(out, '-', 54);
for(int i = 0; i < count; i++)
{
out << setw(37) << left << titles[i]
<< right << setw(6) << ratings[i] << "%"
<< setw(10) << RatingToString(ratings, i) << endl;
}
}
|