5 Replies - 1450 Views - Last Post: 25 May 2009 - 07:00 AM Rate Topic: -----

#1 dwade3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 21-May 09

Displaying Student Grade

Posted 24 May 2009 - 10:23 PM

I am trying to display grades corresponding to the student marks. Once a user has created a new student record (student ID and mark), when it is displayed, it will also display the grades corresponding to the mark.

Here is my code:
#include <iostream>
#include <string>
using namespace std;

const int SIZE=30;
struct StudentRecord
	 {
	   string studentID;
	   float studentMark;
	 };

void populate(StudentRecord *,string);
void dispOne(StudentRecord *);
int linearSearch (StudentRecord*student,const string id,int totalStudents);

int main()
{
	int menu;
	StudentRecord student[SIZE] = 
				  {
				  {"P1001",78.50},
				  {"P1002",66}
				  };
	StudentRecord *recPoint;
	int totalStudents=2;
	float totalMarks;
	float averageMark;
	string id;
	int found;
	char studentGrade;
	
	cout << "MAIN MENU\n"
		 << "0. Exit		 1. Statistics\n"
		 << "2. Enter mark   3. Find mark\n"
		 << "------------------------------\n"
		 << "Your choice -> ";
	cin >> menu;
  while (menu != 0)
  {
	switch (menu)
	{
		   case 1:
				totalMarks=0;
				for(int j=0;j<totalStudents;j++)
					totalMarks+=student[j].studentMark;
					averageMark=totalMarks/totalStudents;
					cout << "Number of records: " << totalStudents <<endl;
					cout << "Mean or average: " << averageMark <<endl;
				break;
		   case 2:
				cout << "Enter a Student Record: " <<endl;
				cout << "Student ID -> ";
				cin >> id;
				found = linearSearch(student,id,totalStudents);
				if (found!=-1)
				  {
					cout << "Record already exists." << endl;
				  }
				else
				  {
					recPoint = new StudentRecord;
					populate(recPoint,id);
					dispOne(recPoint);
					student[totalStudents].studentID=recPoint->studentID;
					student[totalStudents].studentMark=recPoint->studentMark;
					totalStudents++;
				  }			
				break;
		   case 3:
				cout << "Find marks for ID -> ";
				cin >> id;
				found = linearSearch(student,id,totalStudents);			
				if(found!=-1)
				  { 
					cout << "-------------" << endl;
					cout << "Student ID: " << student[found].studentID << endl;
					cout << "Mark/Grade: " << student[found].studentMark;
					if
					{
							(student[found].studentMark >= 85)
					   studentGrade = 'H';
					else if (student[found].studentMark <85 && >=75)
					   studentGrade = 'D';
					else if (student[found].studentMark <75 && >=65)
					   studentGrade = 'C';
					else if (student[found].studentMark <65 && >=50)
					   studentGrade = 'P';
					else
					   studentGrade = 'F';
					}
					cout << " (" << studentGrade << ")" << endl;
					cout << "-------------" << endl;
				  }
				else
				  cout << "Record does not exist." << endl;		  
				break;
		   default:
				cout << "Invalid selection. Please make a selection between 0-3.\n"
					 << endl;
				break;
	}	

	cout << "MAIN MENU\n"
		 << "0. Exit		 1. Statistics\n"
		 << "2. Enter mark   3. Find mark\n"
		 << "----------------------------\n"
		 << "Your choice -> ";
	cin >> menu;
  }
system("Pause");
return 0;
}

void populate(StudentRecord *record, string stId)
{
	 record->studentID = stId;
	 cout << "Enter the corresponding mark: ";
	 cin >> record->studentMark;
	 return;
}

void dispOne(StudentRecord *contents)
{
	 cout << "\nThe contents of the record just created is:"
		  << "\nStudent ID: " << contents->studentID
		  << "\nMark: " << contents->studentMark << endl;
	 return;
}

int linearSearch(StudentRecord*student,const string id,int totalStudents)

{
	int retValue=-1;
	for(int i=0;i<totalStudents;++i)
	{
			if(student[i].studentID == id)
			{
			  retValue=i;
			  break;
			}
	}
	return retValue;
}



I get the following errors:
- In function `int main()':
- 79 expected `(' before '{' token

The output of the record should display something like this:
Student ID: P1001
Mark/Grade: 78.80 (D)

Student ID: P1002
Mark/Grade: 66 ( C)

This post has been edited by dwade3: 24 May 2009 - 10:26 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Displaying Student Grade

#2 BlakeJustBlake  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 26
  • View blog
  • Posts: 441
  • Joined: 15-February 09

Re: Displaying Student Grade

Posted 24 May 2009 - 11:55 PM

delete the '{' after the if and the '}' after the else statement.
Was This Post Helpful? 0
  • +
  • -

#3 dwade3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 21-May 09

Re: Displaying Student Grade

Posted 25 May 2009 - 12:42 AM

I am unsure which "{" to delete as there are 2 if statements. But I deleted the "{" after the second if statement. And it removed the error. However, by doing so, I generated additional errors:
- 82 expected primary-expression before '>=' token
- 84 expected primary-expression before '>=' token
- 86 expected primary-expression before '>=' token

How do I fix this?
Was This Post Helpful? 0
  • +
  • -

#4 BlakeJustBlake  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 26
  • View blog
  • Posts: 441
  • Joined: 15-February 09

Re: Displaying Student Grade

Posted 25 May 2009 - 01:30 AM

you're not putting anything to compare with >=, you 're comparing something, and then you have the "&& <=..." the compiler doesn't guess to use the same thing you compared before, so you have to put that there again, so it'd be like: student[found].studentMark <85 && student[found].studentMark >=75)
Was This Post Helpful? 1
  • +
  • -

#5 extatic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 25-May 09

Re: Displaying Student Grade

Posted 25 May 2009 - 03:57 AM

View PostBlakeJustBlake, on 25 May, 2009 - 12:30 AM, said:

you're not putting anything to compare with >=, you 're comparing something, and then you have the "&& <=..." the compiler doesn't guess to use the same thing you compared before, so you have to put that there again, so it'd be like: student[found].studentMark <85 && student[found].studentMark >=75)


replace

					if
							 {
							(student[found].studentMark >= 85)
							  studentGrade = 'H';



to

				   if (student[found].studentMark >= 85)
								studentGrade = 'H'


Just a small typo,
Was This Post Helpful? 0
  • +
  • -

#6 CodeSpawn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 24-May 09

Re: Displaying Student Grade

Posted 25 May 2009 - 07:00 AM

Here see. That bracket. It doesn't belong there you have to remove it.
					if
					{
							(student[found].studentMark >= 85)
					   studentGrade = 'H';


					if(student[found].studentMark >= 85)
					   studentGrade = 'H';



EDIT: lol extatic beat me to it

This post has been edited by CodeSpawn: 25 May 2009 - 07:08 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1