0

I need to write a program in C++ that will compute numeric grades for a course. The course records are in a file that will serve as the input file.Each line will have a last name, first name, ten quizes all on one line...

you should calculate the average and standard deviation of the grades;;;

2
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by Vladvaga
0

when i enter a file name, the program is terminating before it does anything...

Here is the program......

#include <iostream> 
#include <fstream> 
#include <cstdlib> 
#include <ctype.h> 
using namespace std;

void calc_grade(ifstream& ins, ofstream& outs); 
bool isscore(ifstream& ins); 

int main()
{ 
  char file1[12], file2[12]; 
  ifstream ins; 
  ofstream outs; 

   cout << "Enter the name of input file: "; 
   cin >> file1; 
   ins.open(file1); 
   if (ins.fail()) 
   { 
        cout << "Input file could not be opened"<<endl; 
        exit(1); 
   } 

    cout << "Enter the name of output file: "; 
    cin >> file2; 
    outs.open(file2); 
           if (outs.fail()) 
   { 
          cout << "Output file could not be opened"; 
     exit(1); 
} 

calc_grade(ins, outs); 

ins.close(); 
outs.close(); 

cout << "End of program.\n"; 
} 

bool isscore(ifstream& ins) 
{ 
     char next; 
     ins.get(); 
     next=ins.peek(); 
     return isdigit(next); 
  }

void calc_grade(ifstream& ins, ofstream& outs) 
{ 
    char lname[20], fname[15]; 

   while (!ins.eof())
   { 
   int score, total=0, count=1; 
   ins >> lname >> fname; 

outs << lname << " " << fname << " " ; 
    while (count<11 && isscore(ins)) 
	{ 
    ins >> score; 
    count++; 
    total+=score; 
    outs.width(4); 
    outs << score; 
 } 

   outs <<" " <<(double(total)/10) << endl; 
  } 
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.