I need some help...
I wrote a program that reads an input file containing names and numbers.
I mapped the nunbers to letter grades and wrote the output to another file as well as the screen.
What I have to do now is use arrays to keep track of names, numeric grades, and letter grades.
This is what i have so far.
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
|
void inputFile()
{
ifstream iFile;
ofstream oFile;
string lines;
int num;
char grade;
iFile.open("inputFile.txt");
if (!"inputFile.txt")
{
cout << "ERROR: Could not open file." << endl;
}
oFile.open("outputFile.txt");
if (!oFile)
{
cout << "ERROR: Could not open file." << endl;
}
while (!iFile.eof())
{
iFile >> lines >> num;
// cout << lines << " " << num << endl;
if (num > 90){
grade = 'A';
}else if (num > 80){
grade = 'B';
}else if (num > 70){
grade = 'C';
}else if (num > 60){
grade = 'D';
}else{
grade = 'F';
}
oFile << lines << " " << num << " " << grade << endl;
cout << lines << " " << num << " " << grade << endl;
}
iFile.close();
oFile.close();
}
|
Now, this program runs fine..
I figured the arrays should be
1 2 3
|
string names[6]; // there are 6 names
int numScores[6]; // there are 6 "numerical scores"
char letterGRade[6]; //there should be 6 letter grades.
|
what's inside inputFile.txt:
Joe 93
Mary 96
Travis 82
Seif 61
Omar 75
Louis 56 |
whats inside outputFile.txt:
Joe 93 A
Mary 96 A
Travis 82 B
Seif 61 D
Omar 75 C
Louis 56 F
|
So the question I have is: Where do i implement these and couldn't i just put everything in one giant for loop and use #define to my advantage if more names were to be added?