Here we go again. As you can see, I have gotten much further. There are some elements however that I am unsure how to apply (i.e. bool tooMany). I haven't the slightest how to apply that. That is one snag that I have. Another, and the main one, is this:
The following code does work. It calls a file called "studentData.txt". Said file contains the ID#s and Scores on their own lines :
(id) 101
(score) 100
102
95
103
90
...
...
121
0
Now, if I comment that out and just have it read from the arrays that I have hardcoded it works great. I can't quite figure out how to compute the .txt items into the individual arrays to make it use those as opposed to the hardcoded arrays. One of my main issues with reading from a .txt file, is that the only way I know how is using the getline feature. Is there anything better?
Currently I have the code calling the .txt file.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
void printTable(int score[], int id[], int count);
void printGrade(int oneScore, float average);
void readStudentData(ifstream &rss, int scores[], int id[], int &count, bool &tooMany)
{
const int MAX_SIZE = 21;
rss.open("studentData.txt");
string line;
id[MAX_SIZE];
int score[MAX_SIZE];
count = 0;
int oneScore = 0;
float average = 0;
string grade;
for(count = 0; count < MAX_SIZE; count++)
{
getline(rss,line);
cout << line;
getline(rss,line);
cout << " " << line;
cout << " " << grade << endl;
}
// printTable(score, id, count);
}
float computeAverage(int scores[], int count[])
{
const int MAX_SIZE = 21;
return 0;
}
void printTable(int score[], int id[], int count)
{
void printGrade(int oneScore, float average);
const int MAX_SIZE = 21;
int oneScore = 0;
float average = 0;
string grade;
id[MAX_SIZE];
score[MAX_SIZE];
cout << left << setw(9) << "ID#s" << setw(9) << "Scores" << setw(9) << "Grades" << endl << endl;
//for(count = 0; count < MAX_SIZE; count++)
//{
printGrade(oneScore,average);
//}
}
void printGrade(int oneScore, float average)
{
const int MAX_SIZE = 21;
int id[MAX_SIZE] = {101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121};
int scores[MAX_SIZE] = {100,95,90,85,80,75,70,65,60,55,50,45,40,35,30,25,20,15,10,5,0};
oneScore = 0;
average = 0;
string grade;
int sum = 0;
for(int i = 0; i < MAX_SIZE; i++)
sum += scores[i];
average = sum / MAX_SIZE;
for(int i = 0; i < MAX_SIZE; i++)
{
if(scores[i] > average + 10)
{
grade = "outstanding";
}
else if(scores[i] < average - 10)
{
grade = "unsatisfactory";
}
else
{
grade = "satisfactory";
}
// cout << left << setw(9) << id[i] << setw(9) << scores[i] << setw(9) << grade << endl;
}
}
int main()
{
ifstream rss;
string line;
const int MAX_SIZE = 21;
int scores[MAX_SIZE];
int id[MAX_SIZE];
int count;
bool tooMany;
readStudentData(rss, scores, id, count, tooMany);
return 0;
}