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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#include <iostream>
#include <string>
#include <iomanip>
#include <istream>
#include <math.h>
#include <fstream>
const int SIZE = 20;
typedef char String[SIZE];
//prototypes
void Menu(int &);
void ReadFile(fstream &,String[],String[],int[],char[]);
void ShowContents(fstream &,String[],String[],int[],char[],const int);
using namespace std;
int main()
{
char filename[]= "grades.txt";
String fname[SIZE], lname[SIZE];
int score[SIZE];
char grade[SIZE];
int choice;
ifstream InGradeList;
ofstream OutGradeList
InGradeList.open(filename);
OutGradeList.open(filename);
if(InGradeList.good() && OutGradeList.good())
{
Menu(choice);
switch(choice)
{
case 1:
ReadFile(InGradeList,fname,lname,score,grade);
ShowContents(OutGradeList,fname,lname,score,grade,SIZE);
/*case 2:
case 3:
case 4:
case 5:*/
}
}
else
cout << "File did not open successfully." << endl << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
void Menu(int &choice)
{
cout << "\n Choose an option:";
cout << "\n...................................";
cout << "\n 1- Display All Content of the File";
cout << "\n 2- Display Content in Reverse Order";
cout << "\n 3- Display from Point A to Point B";
cout << "\n 4- Display from Point B to Point A";
cout << "\n 5- Exit";
cout << "\n\n Enter your choice: ";
cin >> choice;
}
void ReadFile(fstream &inFile,String fname[],String lname[],int score[],char grade[])
{
int idx = 0;
while (inFile.good())
{
inFile >> fname[idx] >> lname[idx] >> score[idx] >> grade[idx];
idx++;
}
inFile.close();
}
void ShowContents(fstream &outputFile,String fname[],String lname[],int score[],char grade[],const int SIZE)
{
int idx = 0;
for(int idx = 0; idx < SIZE; idx++)
{
outputFile << fname[idx] << " " << lname[idx] << " ";
outputFile << score[idx] << " " << grade[idx] << endl;
}
outputFile.close();
}
|