hopeolicious 0 Light Poster

I have to write a program to compute the class's average and standard deviation from a file which contains a collection of student idds and corresponding scores for my computer class. I am to assign each stedent a letter grade as follows:

100-90 = A
89-80 = B
79-70 = C
69-60= D
BELOW 60 = F

I am to have no less than 7 students and no more than 25 and i have to save the average

This is what i have come up with so far but I've never did a file and stuff before
can someone help me to make this correct please

This is my file containing the ids and scores
student.dat

#include <fstream.h>
#include <stdlib.h>

int main()
{
const int MAXID =  4;
const MAXNUMGRADE = 3;
ofstream out;
int i = 0, id[MAXID], numgrade[MAXNUMGRADE];

out.open("student.dat");
if(out.fail())
  {
	cout << "The output file was not successfully opened" << endl;
	exit(1);
  }
do{
cout << "\nEnter Student ID: ";
cin >> id;

cout << "Enter student number grade: ";
cin >> numgrade;
}whle(i>7 || i<25); // get and write records while greater than 7 and less than 25

// write the file
out << id << "          " << numgrade << endl;

out.close();
cout << "\n\nEnd of data input.";
cout << "\nThe file has been written.\n";

return 0;
}

and this is the program that reads student.dat

students.cpp

#include <fstream.h>
#include <stdlib.h>

int main()
{
const int MAXID =  4;
const MAXNUMGRADE = 3;
ofstream out;
int i = 0, id[MAXID], numgrade[MAXNUMGRADE], total =0;
char lettergrade;
float average = 0;

in.open("student.dat", ios::in);
if(in.fail())
{
	cout << "\nThe input file was not successfully opened"
  	        << "\n Please check that the file currently exists."
	        << endl;
	exit(1);
}

cout << "\nStudent ID                     Number Grade       LetterGrade\n";
cout << "**********************************************";

while( (ch =in.peek()) != EOF)
{
in >> id >> numgrade;

if (numgrade >= 90) strcpy(lettergrade,"A");
else if (numgrade >= 80) strcpy(lettergrade,"B");
else if (numgrade >= 70) strcpy(lettergrade,"C");
else if (numgrade >= 60) strcpy(lettergrade,"D");
else strcpy(lettergrade,"F");

cout << id << "                          " << numgrade << "              " <<  lettergrade << endl;
}
for(i=1;i++)
{
in >> numgrade;
numgrade = total;
total = total + numgrade;
average = total/i;

cout << " Class average is " << average << endl;

return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.