New Member: Big problem with enumerators

type specifier omitted for parameter

Page 1 of 1

3 Replies - 772 Views - Last Post: 31 March 2009 - 01:24 PM Rate Topic: -----

#1 Aeroacer   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 31-March 09

New Member: Big problem with enumerators

Post icon  Posted 31 March 2009 - 12:08 PM

Ok so I have visited this website before to get information, but now I have a big problem so I made an account.

My professor wants us to write a program the reads a student's name, id, exam score, and sex and processes all of it. He wants us to learn how to uses switches and enumerators in this program. He said that it would be redundant (we need a switch to find the grade, one to count the grade, and one to print the grade) (i know i could do it all in one). Also all of the functions i used are necessary as well according to the assignment. My problem is that i created an enum variable: enum grade {A, B, C, D, F}; and made it global. Then I declared: grade studGrade; When I declare my functions the compiler gives me the error: type specifier omitted for parameter 'grade'. It happens in lines 40, 50, and 110.

Here are the errors:
prog9t.cxx:40: error: type specifier omitted for parameter `grade'
prog9t.cxx:40: error: parse error before `)' token
prog9t.cxx:50: error: type specifier omitted for parameter `grade'
prog9t.cxx:50: error: parse error before `)' token
prog9t.cxx:110: error: type specifier omitted for parameter `grade'
prog9t.cxx:110: error: parse error before `&' token

And Here is my code. Thank you in advance for any help.

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

void printHeading(ofstream& outFile);
//***************************************************************
//Purpose: Print heading for output file.
//Input: none.
//Pre: outFile is opened and ok.
//Output: outFile.
//Post: Heading is printed in outFile.
//Note: none.
//***************************************************************

bool validData(int id, char sex, int exam);
//***************************************************************
//Purpose: This function determines if the data is valid.
//Input: id, sex, exam;
//Pre: data exists and has been read from inFile.
//Output: bool (true or false).
//Post: this function will return true if all data is correct or
//	  false if any data is incorrect.
//Note: none.
//***************************************************************

void findCountGrade(int& gradeA, int& gradeB, int& gradeC, int& gradeD, int& gradeF, grade studGrade);
//***********************************************************************************************************
//Purpose: This function determines the grade for a student.
//Input: exam, gradeA, gradeB, gradeC, gradeD, gradeF, studGrade
//Pre: variables have been assigned and are ok.
//Output: gradeA, gradeB, gradeC, gradeD, gradeF, grade
//Post: count for gradeA, gradeB, gradeC, gradeD, or gradeF has been updated. grade has been assigned
//Note: this function uses a switch.
//***********************************************************************************************************
void printGrade(ofstream& outFile, grade studGrade);
//***************************************************************
//Purpose: This function prints average and grade
//Input: studGrade
//Pre: outFile is opened and ok. grade has been assigned
//Output: outFile.
//Post: grade is printed in outFile.
//Note: this function uses a switch to determine what to print.
//***************************************************************

void printInvalidDataMsg(ofstream& outFile);
//***************************************************************
//Purpose: Prints invalid data message in output file.
//Input: none.
//Pre: outFile is opened and ok. Also data is invalid.
//Output: outFile.
//Post: Invalid data message is printed in outFile.
//Note: none.
//***************************************************************

float avgOfExams(float sum, float count);
//***************************************************************
//Purpose: computes the mean of all the exams.
//Input: sum, count.
//Pre: sum and count are assigned and count > 0.
//Output: float
//Post: the value of mean is returned to the main
//Note: none.
//**************************************************************

void countGender(char sex, int& male, int& female);
//**************************************************************
//Purpose: determines the number of male and female students.
//Input: sex, male, female.
//Pre: sex, male, and female are assigned.
//Output: none.
//Post: the number of males or females has been modified.
//Note: male and female must be originally set to zero.
//**************************************************************

void printStats(ofstream& outFile, int gradeA, int gradeB, int gradeC, int gradeD, int gradeF);
//************************************************************************************************
//Purpose: prints the number of A's, B's, C's, D's, and F's
//Input: outFile, gradeA, gradeB, gradeC, gradeD, gradeF
//Pre: outFile is opened and ok. variables are assigned
//Output: outFile
//Post: the numbers for each grade have been printed in the outFile.
//Note: none.
//************************************************************************************************

void printPercentage(ofstream& outFile, int male, int female);
//************************************************************************************************
//Purpose: prints the percentage of males and females.
//Input: outFile, male, female
//Pre: outFile is opened and ok. variables are assigned
//Output: outFile
//Post: the percentages for males and females have been printed in the outFile.
//Note: none.
//************************************************************************************************

void findGrade(int exam, grade& studGrade);
//****************************************************************************
//Purpose: takes int exam and determines grade of students.
//Input: exam
//Pre: exam has value and is valid data
//Output: grade
//Post: grade is determined
//Note:
//****************************************************************************


const int MAXID = 9999;
const int MINID = 1111;
const float MAXSCORE = 100.00;
const float MINSCORE = 0.00;
enum grade {A, B, C, D, F};


int main()

{
  ofstream outFile;
  ifstream inFile;

  outFile.open("out.data");
  inFile.open("in.data");

  if(!outFile||!inFile)
  {
	cout  <<  "File opening  error.";
	cout  <<  "Program terminated."  <<  endl;

	return 1;
  }

  outFile.setf(ios::fixed);
  outFile.precision(2);

  char  sex;						   //declaring valiables
  int id, exam;
  int male = 0;
  int female = 0;
  int gradeA = 0;
  int gradeB = 0;
  int gradeC = 0;
  int gradeD = 0;
  int gradeF = 0;
  string name;
  float  mean;
  float count = 0.00;
  float sum = 0.00;
  grade studGrade;

  printHeading(outFile);
  inFile >> name >> id >> sex >> exam;							  // retrieves the variables

  while(inFile)
  {

	outFile << left << setw(15)<< name << setw(10) << id << setw(5) << sex  // writes the middle of the outFile
			<< setw(12) << exam;


	if(validData(id, sex, exam))
	{
	  findGrade(exam, studGrade);
	  findCountGrade(gradeA, gradeB, gradeC, gradeD, gradeF, studGrade);
	  printGrade(studGrade);

	  count = count + 1;
	  sum = sum + exam;

	  countGender(sex, male, female);

	}
	else
	{
	  printInvalidDataMsg(outFile);											   //writes invalid data
	}

	inFile >> name >> id >> sex >> exam;

  }


  if(count > 0)									 //checks if there is data and computes mean
	{
	  mean = avgOfExams(sum, count);
	  outFile << "~ ~ Exam AVG = " << mean << endl;
	}
  else
	{
	  outFile << "~ ~ Exam AVG = No Valid Data, No AVG of Exams!!!" << endl;				  // assigns special value for "No Valid Data No Mean of AVG" msg
	}

  printStats(outFile, gradeA, gradeB, gradeC, gradeD, gradeF);
  printPercentage(outFile, male, female);

  outFile.close();			  //closes the input and output files
  inFile.close();

  return 0;

}


void printHeading(ofstream& outFile)
//***************************************************************
//Purpose: Print heading for output file.
//Input: none.
//Pre: outFile is opened and ok.
//Output: outFile.
//Post: Heading is printed in outFile.
//Note: none.
//***************************************************************

{
 outFile << "* ~ ~ < Stud Exam Report > ~ ~ *" << endl << endl;	//prints the beginning of the outfile
 outFile << left << setw(15) << "Name" << setw(10) << "Stud Id" << setw(5) << "Sex" << setw(12)
		 << "Exam" << setw(9) << "Grade" << endl;
 outFile << left << setw(15) << "----" << setw(10) << "-------" << setw(5) << "---" << setw(12)
		 << "----" << setw(9) << "-----" << endl;
}


bool validData(int id, char sex, int exam)
//***************************************************************
//Purpose: This function determines if the data is valid.
//Input: id,sex, exam1, exam2, exam3.
//Pre: data exists and has been read from inFile.
//Output: bool (true or false).
//Post: this function will return true if all data is correct or
//	  false if any data is incorrect.
//Note: none.
//***************************************************************


{
  return((id >= MINID && id <= MAXID) && (exam >= MINSCORE && exam <= MAXSCORE)	  //determines validity
		&&(sex == 'M' || sex == 'F'));
}


void findCountGrade(int& gradeA, int& gradeB, int& gradeC, int& gradeD, int& gradeF, grade studGrade)
//***************************************************************
//Purpose: This function determines the grade for a student.
//Input: average.
//Pre: average has been assigned.
//Output: char
//Post: character for grd is returned
//Note: none.
//***************************************************************


{
 switch (studGrade)
  {
	case A:
	 {
	  ++gradeA;
	  break;
	 }
	case B:
	 {
	  ++gradeB;
	  break;
	 }
	case C:
	 {
	  ++gradeC;
	  break;
	 }
	case D:
	 {
	  ++gradeD;
	  break;
	 }
	case F:
	 {
	  ++gradeD;
	  break;
	 }
  }
}


void printGrade(ofstream& outFile, grade studGrade)
//***************************************************************
//Purpose: This function prints average and grade
//Input: average, grd.
//Pre: outFile is opened and ok.
//Output: outFile.
//Post: average and grade are printed in outFile.
//Note: none.
//***************************************************************


{
 switch (studGrade)
  {
	case A:
	  outFile << setw(9) << "A" << endl;
	case B:
	  outFile << setw(9) << "B" << endl;
	case C:
	  outFile << setw(9) << "C" << endl;
	case D:
	  outFile << setw(9) << "D" << endl;
	case F:
	  outFile << setw(9) << "F" << endl;
  }
}


void printInvalidDataMsg(ofstream& outFile)
//***************************************************************
//Purpose: Prints invalid data message in output file.
//Input: none.
//Pre: outFile is opened and ok. Also data is invalid.
//Output: outFile.
//Post: Invalid data message is printed in outFile.
//Note: none.
//***************************************************************


{
  outFile << setw(9) << "**** Invalid data" << endl;
}


float avgOfExams(float sum, float count)
//***************************************************************
//Purpose: computes the mean of all the exam's averages.
//Input: sum, count, mean
//Pre: sum and count are assigned and are < 0.
//Output: mean.
//Post: the value of mean is returned to the main
//Note: none.
//**************************************************************


{
  return sum/count;
}


void countGender(char sex, int& male, int& female)
//**************************************************************
//Purpose: determines the number of male and female students.
//Input: sex, male, female.
//Pre: sex, male, and female are assigned.
//Output: none.
//Post: the number of males or females has been modified.
//Note: male and female must be originally set to zero.
//**************************************************************


{
  if(sex == 'M')
	male = male + 1;
  else
	female = female +1;
}


void printStats(ofstream& outFile, int gradeA, int gradeB, int gradeC, int gradeD, int gradeF)
//***********************************************************************************************
//Purpose: prints mean of average, # of males & females & valid & invalid
//Input: mean, male, female, valid, invalid.
//Pre: outFile is opened and ok.
//Output: outFile
//Post: mean of average, males, females, valid, & invalid have been printed
//Note: a special value (-100) for mean will print an invalid data message.
//***********************************************************************************************


{
  outFile << endl << "Number of A: " << gradeA << endl;
  outFile << endl << "Number of B: " << gradeB << endl;
  outFile << endl << "Number of C: " << gradeC << endl;
  outFile << endl << "Number of D: " << gradeD << endl;
  outFile << endl << "Number of F: " << gradeF << endl << endl;
}


void printPercentage(ofstream& outFile, int male, int female)
//***********************************************************************************************
//Purpose: prints mean of average, # of males & females & valid & invalid
//Input: mean, male, female, valid, invalid.
//Pre: outFile is opened and ok.
//Output: outFile
//Post: mean of average, males, females, valid, & invalid have been printed
//Note: a special value (-100) for mean will print an invalid data message.
//***********************************************************************************************


{
  outFile << endl << "Female% = " << (female/(male + female)) << "%" << endl;
  outFile << endl << "Male% = " << (male/(male + female)) << "%" << endl;
}


void findGrade(int exam, grade& studGrade)
//****************************************************************************
//Purpose: takes int exam and determines grade of students.
//Input: exam
//Pre: exam has value and is valid data
//Output: grade
//Post: grade is determined
//Note:
//****************************************************************************

{
 switch (exam)
  {
	case 90 ... 100:
	 {
	  studGrade = A;
	  break;
	 }
	case 80 ... 89:
	 {
	  studGrade = B;
	  break;
	 }
	case 70 ... 79:
	 {
	  studGrade = C;
	  break;
	 }
	case 60 ... 69:
	 {
	  studGrade = D;
	  break;
	 }
	case 0 ... 59:
	 {
	  studGrade = F;
	  break;
	 }
  }
}



Is This A Good Question/Topic? 0
  • +

Replies To: New Member: Big problem with enumerators

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6248
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: New Member: Big problem with enumerators

Posted 31 March 2009 - 12:51 PM

Where is grade defined? The compiler does not know what a grade is, so it's puking all over itself.
Was This Post Helpful? 0
  • +
  • -

#3 Aeroacer   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 31-March 09

Re: New Member: Big problem with enumerators

Posted 31 March 2009 - 12:56 PM

const int MAXID = 9999;
const int MINID = 1111;
const float MAXSCORE = 100.00;
const float MINSCORE = 0.00;
enum grade {A, B, C, D, F};


^^^ those are my global definitions. doesn't that define grade as an enum data type?

this is my question: i don't know how to set up an enum data type.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6248
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: New Member: Big problem with enumerators

Posted 31 March 2009 - 01:24 PM

Put in a header file and include it, or put it ahead of the function prototypes.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1