Modification

The question is the question asked user to prompt how many student's CGPA wished to be calculated from 0 to 99. Then it ask user to enter how many years he is doing his course to calculate his overall CGPA for the course for the user entered.

This is the header file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 #include <iostream>
#include <string>
using namespace std;

class Student //class
{
public:
	Student(string name);
	void GetPointers();
	void display();


private:
	double points[3][4];  // using 2D array
	int CreditHour[3][4]; // using 2D array
	string name;
	double CalculateGPA();
	double CalculateCGPA();
};

This is the StudentM cpp file
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
#include <iostream>
#include <iomanip>
#include <string>
#include "StudentM.h"
using namespace std;

Student::Student(string nama)
{
	name = nama;
};
void Student::GetPointers()
{
	for (int i = 0; i < 3; i++)
	{
		cout << "Semester " << i + 1 << endl;
		for
			(int x = 0; x < 4; x++)
		{
			cout << "Points for subject: " << x + 1 << endl;
			cin >> points[i][x];
			cout << "Credit  hour for subject: " << x + 1 << endl;
			cin >> CreditHour[i][x];
		}
	}
}
void Student::display()
{
	cout << "Hello " << name << endl;
	cout << "Your current GPA is " << setprecision(3) << CalculateGPA() << endl;
}
double Student::CalculateGPA()
{
	double totalPoints = 0;
	int totalCreditHour = 0;
	double totalGPA = 0;
	double CalculateCGPA;
	int x = 0;
	for
		(int i = 0; i < 3; i++)
	{
		for (x = 0; x < 4; x++)
		totalPoints = (points[i][x] * CreditHour[i][x]);
		totalCreditHour += CreditHour[i][x];
	}
	totalGPA = totalPoints / totalCreditHour;
	return totalGPA;

	double CalulateCGPA = totalPoints / totalCreditHour;
	return CalculateCGPA;
}

This is the Main.cpp file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include "StudentM.h"
using namespace std;
void main(void)
{
	string nama;
	int i, x;
	cout << "Enter your name?: " << endl;
	cin >> nama;
	Student StudentA(nama);


	cout << "Key in points for 4 subjects \n";
	StudentA.GetPointers();
	cout << "Total CGPA is: \n" << endl;
	StudentA.display();
}


p/s: Help me please.
Last edited on
What exactly is your question?

One problem appears to be line 42. Don't you want to use the += operator? As you have it, totalPoints will be reset each time through the loop.

Lines 48-49 will never be executed. Most compilers should flag this with at least a warning.

Line 48: This is a duplicate declaration. calcualteCGPA has already been declared at line 36. This also should have been flagged by your compiler as an error.

AbstractionAnon


The question is "The program should ask user to enter total year of semesters to be calculated as CGPA. Now i able to get for one year only. Lets say the user total year of semesters is 12, so it should calculate the total CGPA for the 12 semesters. So far i able to get 1 year which is equivalent to 3 semesters only.
Topic archived. No new replies allowed.