Solved

Help with C++ program for class (URGENT!)

Posted on 2010-08-15
7
369 Views
Last Modified: 2013-12-14
Hi I'm having a problem with my code not computing correct values.  There is a weighted score that computes a .7 * exam + .3 * lab.  It is not functioning properly someone please tell me why the results are off.
0
Comment
Question by:etan08
  • 3
  • 2
  • 2
7 Comments
 

Author Comment

by:etan08
ID: 33442693
Here's the code for the program.
#include <iostream>

#include <iomanip>



using namespace std;

#define max 100



int getExamScores(int, double*);

int getLabScores(int, double*);

int getTotalStudentCount();



void calculatePointGrades(double[], int, double[]);

void calculateLetterGrades(int, double[]);

void showGradeData(int);



double examGrade[max];

double labGrade[max];

double pointGrade[max];



char letterGrade[max];



void main()

{

	int numStudents;

	numStudents = getTotalStudentCount();

	getExamScores(numStudents, examGrade);

	getLabScores(numStudents, labGrade);

	calculatePointGrades(examGrade, numStudents, labGrade);

	calculateLetterGrades(numStudents, pointGrade);

	showGradeData(numStudents);

	cin.ignore(2);

}



//asks the user to enter the number of students and returns the value entered.

int getTotalStudentCount()

{

	int totalStudentCount;

	cout << "Please enter the number of students: ";

	cin>>totalStudentCount;



	cout << endl;



	return totalStudentCount;

}



//receives the number of students and the name of one-dimensional integer array to store the scores entered 

//by the user.  It should include the student number in the prompt to enter each exam score.

int getExamScores (int totalStudentCount , double *Grade)

{

	cout << endl;



	for (int student = 0; student < totalStudentCount; ++student)

	{

		cout << "Enter the exam grade for student " <<  student + 1 << ": ";

		cin >> *Grade;

		Grade++;

	}



	cout << endl;

	return 0;

}



//receives the number of students and the name of one-dimensional array to store the floating point 

//lab average scores entered by the user.  It should include the student number in the prompt to enter each score.

int getLabScores (int totalStudentCount , double *Grade)   

{

	cout << endl;

	for (int student = 0; student < totalStudentCount; ++student)

	{

		cout << "enter the lab grade for student " <<  student + 1 << ": ";

		cin >> *Grade;

		Grade++;

	}

	cout << endl;





	return 0;

}



//receives the two arrays of scores (for the exam and lab average), the number of students and the 

//name of a one-dimensional array into which the calculated point grades are to be stored.

void calculatePointGrades(double labGrade[],int totalStudentCount, double examGrade[])  

{

	for (int student = 0; student < totalStudentCount; student++)

	{

		pointGrade[student] = (.7 * examGrade[student]) + (.3 * labGrade[student]);

	}

}



//receives the point grades array, the number of students, and the name of a one-dimensional array(pointGrade) of 

//characters to store the letter grades (as determined by each student’s point grade)

void calculateLetterGrades(int totalStudentCount, double pointGrade[])  

{

	for (int student = 0; student < totalStudentCount; ++student)

	{

		if(pointGrade[student]>=90)

			letterGrade[student]='A';

		else if(pointGrade[student] >= 80 && pointGrade[student] < 90)

			letterGrade[student]='B';

		else if(pointGrade[student] >= 70 && pointGrade[student] < 80)

			letterGrade[student]='C';

		else if(pointGrade[student] >= 60 && pointGrade[student] < 70)

			letterGrade[student]='D';

		else

			letterGrade[student]='F';

	}

}



//to display the table as shown in Figure 1 and the overall averages for exam, lab scores and point scores

void showGradeData(int totalStudentCount) 

{

	double examGradeTotal = 0, labGradeTotal = 0.0, pointTotal = 0.0;  

	double examGradeAvg, labGradeAvg, pointScoreAvg;  



	cout << "-----------------------------------------------------------------" << endl;

	cout << "|" << setw(3) << "SN" << setw(15) << "Exam" << setw(15) << "Lab" << setw(15) << "Point" << setw(15) << "Letter" << "|" << endl;

	cout << "|" << setw(3) << "" << setw(15) << "" << setw(16) << "Ave." << setw(14) << "Grade" << setw(14) << "Grade"<< setw(2) << "|" << endl;

	cout << "-----------------------------------------------------------------" << endl;

	for(int student = 0; student < totalStudentCount; student++)

	{

		cout << "|" << setw(3) << student + 1 << setw(15) << examGrade[student] << setw(15) << labGrade[student] << setw(15) << pointGrade[student] << setw(10) << letterGrade[student] << setw(6) << "|" << endl;



		examGradeTotal = examGradeTotal + examGrade[student];

		labGradeTotal = labGradeTotal + labGrade[student];

		pointTotal = pointTotal + pointGrade[student];

	}

	cout << "-----------------------------------------------------------------" << endl;



	examGradeAvg = (double)examGradeTotal / totalStudentCount;

	labGradeAvg = labGradeTotal / totalStudentCount;

	pointScoreAvg = pointTotal / totalStudentCount;



	cout << "\n\n Exam Average        : " << examGradeAvg;

	cout << "\n Lab Average Average : " << labGradeAvg;

	cout << "\n Point Score Average : " << pointScoreAvg;

}

Open in new window

0
 

Author Comment

by:etan08
ID: 33442732
ExpectedResults:
      
SN   Exam Lab   Points      Grade
1      100      100      100              A
2      95      99.9      96.47      A
3      90      99.9      92.97      A
4      80      88.8      82.64      B
5      70      77.7      72.31      C
6      60      66.6      61.98      D
7      50      55.5      51.65        F

      Exam Average:        77.8571
      Lab Grade Average:   84.0571
      Point Grade Average: 79.7171
      
      
      
      
ActualResults:
      
SN   Exam Lab   Points      Grade
1      100      100   100              A
2      95      99.9      98.43      A
3      90      99.9      96.93      A
4      80      88.8      86.16      B
5      70      77.7      75.39      C
6      60      66.6      64.62      D
7      50      55.5      53.85       F
      
      Exam Average:        77.8571
      Lab Grade Average:   84.0571
      Point Grade Average: 82.1971
      
0
 
LVL 32

Accepted Solution

by:
phoffric earned 500 total points
ID: 33442845
>> void calculatePointGrades(double labGrade[],int totalStudentCount, double examGrade[])  
>> calculatePointGrades(examGrade, numStudents, labGrade);

Do you see a problem here?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:w00te
ID: 33442865
You switched the parameters in your call for exam and lab grades.
0
 
LVL 12

Expert Comment

by:w00te
ID: 33442868
Aw damn you and your faster typing Phoffric :p.
0
 
LVL 32

Expert Comment

by:phoffric
ID: 33442870
Isn't that evident from my post?
0
 

Author Comment

by:etan08
ID: 33442872
yup! Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now