Array and Fuctions to Calculate Average and Grade Point....

I am not really sure how i would go about finding the average of two arrays while their in a function. Can someone point me towards the right direction, i would really appreciate it. So far this is what i come up with and will continue trying to figure this out thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
using namespace std;

#define Max_Students 100

int getStudentCount();
int getExamScores(int);
int getLabScores(int);
int calculatePointGrades();
int ExamGrade[Max_Students];
int LabGrades[Max_Students];
void main()
{
int NumStudents;
NumStudents = getStudentCount( );
getExamScores(NumStudents);
getLabScores(NumStudents);

cin.ignore(2);
return;
}

int getStudentCount ( )
{
int StudentInput;
cout << "Enter the number of students: ";
cin>>StudentInput;
return StudentInput;
}


int getExamScores (int count )
{
for (int student = 0; student <count; ++student)
{
cout << "enter exam grade for student "<< student+1 <<": ";
cin >> ExamGrade[student];
}
return 0;
}

int getLabScores (int count)
{
for (int student = 0; student <count; ++student)
{
cout << "enter lab grade for student "<< student+1 <<": ";
cin >> LabGrades[student];
}
return 0;
}
int calculatePointGrades(int LabGrades[],int count, int ExamGrades[])
{

	for (int average = 0; average < count; ++average){
average = 
return 0; 
}
Last edited on
What is the formula you are supposed to use for the average?

I assume there is some weights given for the exam scores and lab scores.


well the exams are worth 70%(.70) and the labs are 30%(.30) which is what you would you for the point grade. point grade = labscore x .30 + exam x .70 and for the lab average you would just add up all the labs then divide by the amount of students this would also apply for finding the point grade average. What i am not really sure of is how to receive the two array scores, the number of students, and how to store it into another array. I have have googled some tutorials but i am still a bit confused how to do this with functions.


i know that my would kinda look like this

int calculatePointGrades(double array , double array , number , double array);


thanks for you assistance!
Last edited on
would it be something like this?

1
2
3
4
5
6
7
int calculatePointGrades(double examGrades[],double labGrades[],double pointaverage[],int count)
{
	for (int student = 0; student <count; ++student){
		pointaverage[student]=(examGrades[student] * .70) + (labGrades[student] * .30);}
	cout << pointaverage[student] << " ";
return 0; 
}
I'm confused.

If a student is going to have more than one lab score or more than one exam score, then to store all of
the lab and exam scores for all students at once, you need a two-dimensional array. But your program
on lines 10 and 11 only make one-dimensional arrays.

Your code in your most recent post looks ok (except for misplaced closing brace) as long as each
student has only one exam grade and only one lab grade.
yeah each student only gets one exam grade and one lab grade.
Then aside from your misplaced brace on line 4, it looks like it should work.
this is what i have now but for some reason my grade point average is not being calculated right. Any tips?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iostream>

using namespace std;
#define Max_Students 100

int getStudentCount();
int getExamScores(int,float*);
int getLabScores(int,float*);
void calculatePointGrades(float[],int,float[]);
void calculateLetterGrades(int,float[]);
float ExamGrade[Max_Students];
float LabGrade[Max_Students];
float PointGrade[Max_Students];
char LetterGrade[Max_Students];

void display(int);

void main()
{
  int NumStudents;
  NumStudents = getStudentCount();
  getExamScores(NumStudents, ExamGrade);
  getLabScores(NumStudents, LabGrade);
  calculatePointGrades(ExamGrade,NumStudents,LabGrade);
  calculateLetterGrades(NumStudents,PointGrade);
  display(NumStudents);
  cin.ignore(2);
}

int getStudentCount()		// functions that gets total number of students
{
   int StudentInput;
   cout << "Enter the number of students: ";
   cin>>StudentInput;

   cout<<endl;

   return StudentInput;
}

int getExamScores (int count , float *Grade)	// function that gets Exam Grade
 {
    cout<<endl;

    for (int student = 0; student <count; ++student)
	{
	  cout << "enter exam grade for student "<< student+1 <<": ";
	  cin >> *Grade;
	  Grade++;
	}

    cout<<endl;
    return 0;
 }


int getLabScores (int count , float *Grade)   // function that get Lab Average grade
 {
    cout<<endl;
    for (int student = 0; student <count; ++student)
	{
	  cout << "enter lab grade for student "<< student+1 <<": ";
	  cin >> *Grade;
	  Grade++;
	}
    cout<<endl;


    return 0;
 }


void calculatePointGrades(float LabGrade[],int count, float ExamGrade[])  // function that calculates Point Grade by getting ExamGrade and LabAverage as arguments
  {
	for (int student = 0; student < count; student++)
	  {
	       PointGrade[student] = (.7*ExamGrade[student]) + (.3*LabGrade[student]);
	  }
  }

void calculateLetterGrades(int count,float PointGrade[])  // function that calculates Letter Grades based on Point Grade
  {
	for (int student = 0; student < count; ++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';

	  }
  }

void display(int count) // function that display the mark details along with total average
  {
      int TotalExamGrade=0;
      float TotalLabGrade=0.0,TotalPointScore=0.0;  // variables for finding total

      float AvgExamGrade,AvgLabGrade,AvgPointScore;  // variables for finding average

      cout<<"\n\nSNO"<<"\t"<<"EXAM SCORE"<<"\t"<<"LAB SCORE"<<"\t\t"<<"POINT GRADE"<<"\t"<<"LETTER GRADE"<<endl;
      for(int student=0; student<count ; student++)
	{
	    cout<<student+1<<"\t"<<ExamGrade[student]<<"\t\t"<<LabGrade[student]<<"\t\t"<<PointGrade[student]<<"\t\t"<<LetterGrade[student]<<endl;

	    TotalExamGrade = TotalExamGrade + ExamGrade[student];
	    TotalLabGrade = TotalLabGrade + LabGrade[student];
	    TotalPointScore = TotalPointScore + PointGrade[student];
	}

      AvgExamGrade = (float)TotalExamGrade / count;
      AvgLabGrade = TotalLabGrade / count;
      AvgPointScore = TotalPointScore / count;

      cout<<"\n\n Exam Average        : "<<AvgExamGrade;
      cout<<"\n Lab Average Average : "<<AvgLabGrade;
      cout<<"\n Point Score Average : "<<AvgPointScore;
  }
When I compile your program, I get the following compile warnings:


foo.cpp:18: error: ‘::main’ must return ‘int’
foo.cpp: In function ‘void display(int)’:
foo.cpp:111: warning: converting to ‘int’ from ‘float’


The second one in particular. It says you are implicitly converting a floating point number to an integer.

Looking at line 111:

 
TotalExamGrade = TotalExamGrade + ExamGrade[ student ];


So ExamGrade is an array of float. TotalExamGrade is an int.
int + float = float in C++, but then you are storing that resulting float back into TotalExamGrade, which
is an int. When you do that, the fractional portion is truncated, so 2.99 becomes 2 when converted
to int.

Correct this, and see what happens.

Also, consider heeding the first warning and changing void main() to int main(). [This will not cause
you any runtime problems, but it is not compliant with the C++ standard.]

got everything working! thanks for helping a newbie lol....

Topic archived. No new replies allowed.