Student Statistics

Hello everyone,
First would like to say I am new to this forum and C++ programming. I am in my first semester of programming and have been asked to write a program that will pull from a txt file and compute the students name and grades.
Write a program that reads from a file (with variable number of records) student names and the grades for 2 tests (the points are floating-point numbers between 0 and 100) (format: Name Test1 Test2) and determines and outputs for each student the overall total points for all tests (column Total Points) 1, the numeric grade (column Numeric Grade)2 (between 0 and 100) and the letter grade (column Letter Grade)3. The program should also compute and output the number of students (row Number), and average numeric grade (row Average) among all students and displays them with 2 decimals. Display the output in the exact format shown below (use 2 decimals for floating-point numbers and the columns and alignment suggested bellow):
STUDENT STATISTICS:
Name Total Points Numeric Grade Letter Grade
Anderson 171.25 85.63 B
Blake 165.00 82.50 B
Castillo 135.00 67.50 D
Dang 180.00 90.00 A
CLASS STATISTICS:
Number:
10
Minimum:
47.50
Maximum:
94.50
Average:
74.33
And here is the program I wrote, I used the professors practice one as a template. But I get nothing on the output screen but the Class statistics and the words name total points etc.
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

int _tmain(int argc,_TCHAR*argv[])

{
//Declare and initialize the variable for Sum
int Sum = 0;
//Declare and initialize the variable for Max
int Max = 0;
//Declare and initialize the variable for Min
int Min = 0;
//Initialize counter
int counter = 0;
// FLAG/EOF-CONTROLED LOOP
//Read data from a file and compute the sum, average, and maximum of the numerical value
cout << "\n\n\nFLAG/EOF-CONTROLED LOOP";
//Open the file
ifstream in("Grades.txt");
//Initialize Sum
Sum = 0;
//Initialize counter
counter = 0;
//Initialize maximun
Max = 0;
//Initialize min
Min = 1000000;
//Output the table header
cout << "\n\nStudent Statistics"
<< endl;
cout << setw(7) << left << "Name"
<< " "
<< setw(6) << left << "Total Points"
<< " "
<< setw(5) << left << "Numeric Grade"
<< " "
<< setw(4) << left << "Letter Grade"
<< endl;
cout << setfill(' ');
cout << setw(7) << left << " "
<< " "
<< setw(6) << left << " "
<< endl;
cout << setfill(' ');
//read from file
do
{
//Read one line
string Name;
int Number;
if (in.eof())
break;
in >> Number;
//output line
cout << setw(7) << left << Name
<< " "
<< setw(6) << left << Number
<< endl;
//Update the sum
Sum = Sum + Number;
//Update the max
if (Max < Number)
Max + Number;
//Update the min
if (Min > Number)
Min = Number;
//Update the counter
counter = counter + 1;
}
while (in);
//Close the file
in.close();
//Output the statistics in table
if (counter != 0)
{
float Average = static_cast<float>(Sum) / counter;
cout << setfill(' ');
cout << setw(7) << left << " "
<< " "
<< setw(6) << left << " "
<< endl;
cout << setfill(' ');
cout << setw(7) << left << "Average"
<< " "
<< setw(6) << left << Average
<< endl;
cout << setw(7) << left << "Minimum"
<< " "
<< setw(6) << left << Min
<< endl;
cout << setw(7) << left << "Maximum"
<< " "
<< setw(6) << left << Max
<< endl;
}
else
cout << "\n\nWe cannot compute the statistics since we do not have any numbers";

//Prevent the console from closing
cout << "\n\nPress any key to continue...";
_getch();
return 0;

}

One problem is in >> Number; The first column is the name but you read it into an int which contains then garbage.
You need to read all the fields in the line.
Topic archived. No new replies allowed.