Member Avatar for becraxie

Hi, I really need help with my c++ assignments. Thank's to everyone who can help!


Create a grading program that reads a file exam grades and computes the Average grade and the letter grade for each of 5 students. Each student has 4 exam grades. Letter grade: A => 90 > B => 80 > C => 70 > D => 60 > F

Output: StudentNumber , Exams, Average, Grade

Example Output::

The record for student number: 1
The exam grades are: 70 80 90 95
The numeric average is: 83.75
and the letter grade assigned is B

Use the class definition given. Code the class.

class StudentRecord
{
public:
void input( ifstream& input,int studentid);
// reads exam scores for this student
void computeGrade();
//calculates the numeric average and letter grade.
void output();
//outputs the student record.
private:
int studentNumber;
double exam1;
double exam2;
double exam3;
double exam4;
double average;
char grade;
};

Use the following test data to test your program:
File name ( contains 4 grades for each of 5 students
ExamGrades.txt 70 80 90 95 95 85 90 80 75 85 70 80 55 85 50 70 45 50 40 35

#include <iostream>
#include <fstream> // I/O
#include <iomanip> // For setw()
using namespace std;

ofstream     outputfile("output.txt");     // Output file

const int    MAX_FILE_NAME = 35;            // Max space allocated for file name
const int CLASS_SIZE = 5;

class StudentRecord
{
public:
void input( ifstream& input,int studentid);
// reads exam scores for this student
void computeGrade();
//calculates the numeric average and letter grade.
void output();
//outputs the student record.
private:
  int studentNumber;
  double exam1;
  double exam2;
  double exam3;
  double exam4;
  double average;
  char grade;
};

// Utility Functions
void open_input(ifstream& input, char name[]); // Get file name & Open file
void process_file(ifstream& input);            // Read each value & process it

int main() 
// Parameters: None
// Returns:    Zero
// Calls:      open_input(), process_file()    
{  char again;             // Does user want to go through loop again?
   char file_name[MAX_FILE_NAME + 1]; // Name of file to be processed
   ifstream input_numbers;            // For working with input file

   cout << "This program can calculate the values needed for\n"
        << "customer invoices.\n" << endl;
   system("pause"); // Hold message on screen until key is pressed

   do 
   {  
      system("cls");                           // Clear screen
      open_input(input_numbers, file_name);    // Get file name & open file
      process_file(input_numbers);             // Process values in file
      input_numbers.close();                   // Close file

      cout << "\nDo you want to process another file (Y/N)? ";
      cin >> again;
      cin.ignore(256, '\n');  // Remove Enter key from keyboard buffer
   
   } while ( again == 'y' || again == 'Y'); 

   cout << "\nEnd of Program!" << endl;
   outputfile << "\n\nThanks for using Invoice!\f"; 
   outputfile.close();
   
   return 0; 
}  // End of main()



void open_input(ifstream& input, char name[]) //Open file, exit on error
// Parameters: Variables for input file reference nad input file name
// Returns:    None
// Calls:      None
{  int count = 0;             // Count number of tries
   do // Continue until we get a valid file name and can open file
   {  count++;
      if (count != 1)  // Issue error message if we are trying again.
      {  cout << "\n\aInvalid file name or file does not exist. Please try again." 
              << endl;
      }
      cout << "\nEnter the input file name (maximum of " << MAX_FILE_NAME
           << " characters please)\n:> ";
      cin.get(name, MAX_FILE_NAME + 1);// Gets at most MAX_FILE_NAME characters
      cin.ignore(256, '\n');           // Remove Enter key from keyboard buffer
      input.clear();                   // Clear all error flags, if any, from prev try
      input.open(name,ios_base::in); // Open only if file exists
   } while (input.fail() );            // If can't open file, try again
} // End of open_input()

void process_file(ifstream& input) 
// Parameters: Variable for file reference
// Returns:    None
// Calls:      Invoice::set_merchandise_value(), Invoice::output()
{ 
	int thisStudent = 0;

StudentRecord student = StudentRecord();
	while (thisStudent++ < CLASS_SIZE)
	{
		student.input (input, thisStudent);
			student.computeGrade();
			student.output();
    }
} // End of process_file()

void StudentRecord::computeGrade()

{
	int studentnubmer;
	
	double average = average;

	average = (exam1+exam2+exam3+exam4)/4;

}

double average;
{

  double value;         
  double sum = 0;
  int count = 0;
     
    
  while (input >> value) 
  
   {   
      sum += value;
	  count ++;
   }
   return sum/count;
}

char grade;

{
	char grade;

	if(average>=90)
		grade = 'A';
	else if(average<90 && average>=80)
		grade = 'B';
	else if(average<80 && average>=70)
		grade = 'C';
	else if(average<70 && average>=60)
		grade = 'D';
	else if(average<60)
		grade = 'F';
}

void StudentRecord::output()
{
	
	 cout<<"The exam grades are: "<<exam1<<"\t"<<exam2<<"\t"<<exam3<<"\t"<<exam4<<"\t"<<endl;
	 cout<<"The numeric average is: "<<average<<endl;
	 cout<<" and the letter grade assigned is: "<<grade<<endl;
}

1>c:\users\Jimmy\documents\visual studio 2010\projects\assignment 8\assignment 8\assign 8.cpp(119): warning C4101: 'studentnubmer' : unreferenced local variable
1>c:\users\Jimmy\documents\visual studio 2010\projects\assignment 8\assignment 8\assign 8.cpp(128): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\Jimmy\documents\visual studio 2010\projects\assignment 8\assignment 8\assign 8.cpp(146): error C2447: '{' : missing function header (old-style formal list?)
1>

Recommended Answers

All 2 Replies

The error lines don't match up with the code lines you posted. Lines 115 to 130 -- This is code in the middle of nowhere. Is this supposed to be a function? Ditto lines 132 to 147. Perhaps there are some bracket mismatches?

on line 115 and line 132. I presume you are trying to create a function but you don't define it correctly. If the function takes no arguments you should put ( void ) behind it, and not just a ; (or like you did in output() on line 149 ).

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.