// File: stugrades.cpp
// Computes a external file and compiles it into a table with 3 columns of ID numbers, scores, and corresponding scores.
#include <iostream>
#include <fstream> // re. ifstream object
#include <iomanip> // re. setw, setprecision, fixed in formatted output
using namespace std;
int main()
{
ifstream fin( "grades.txt" ); // construct ifstream object fin
if( fin ) // if opened ok ...
{
cout << "Student ID" << " " << "Average Score" << " " << "Corresponding Grade" << endl;
int id;
string grade;
int count = 7;
float average;
int mean = 72.8;
while( fin >> id )
{
int sum = 0, score[7];
//int mean = 0, average[7];
for( int i = 0; i < 7; ++ i )
{
fin >> score[i];
sum += score[i];
average = (sum / count);
if (average > mean + 10)
{
grade = "outstanding";
}
else if (average < mean - 10)
{
grade = "unsatisfactory";
}
else if ((average <= mean + 10) && (average >= mean - 10))
{
grade = "satisfactory";
}
}
cout << " " << id << " " << " " << average << " " << " " << grade << endl;
}
fin.close(); // since done with file now ...
}
}
The grades file is simply...
3313 90 42 58 64 70 75 100 5688 88 48 79 70 79 70 94 4700 50 44 89 73 70 73 100 9561 88 69 88 87 84 63 98 3199 96 69 100 90 88 67 100 3768 78 57 80 59 57 15 60 8291 72 56 70 82 74 9 83 7754 76 62 93 100 78 41 58 8146 94 68 99 94 93 9 54 2106 98 47 96 94 70 27 100
I've only been briefly introduced to structs. I think somthing like this would be the start of my struct....
struct examStats
{
float id;
int scores;
string grade;
float mean;
float sum;
}
This
is an opening code tag. The whole thing. A pair of brackets [ ] with the word code between them. This tag goes before your code. This
is a closing code tag. A pair of brackets [ ] with /code inside. This tag goes after your code.
This post has been edited by r.stiltskin: 28 April 2012 - 09:28 AM
Reason for edit:: Added code tags. Please learn to use them.

New Topic/Question
Reply



MultiQuote






|