Hi Guys,

I have an assignment to do a gpa calculator using class construction and an array of grades.

The assignment is to have a class called Student and have a user enter an ID and then enter however many grades they want and then have the program calculate the gpa depending on whatever they inputted. Here is what i got so far,

If you can help soon it would be great. Thanks,

include <iostream>
using namespace std;

class Student
{	private:
	int ID;
	float grades [5] = {4, 3, 2, 1, 0};
public:
	Student(int = 0,float = 0);
	int nofgrades;
	float averagegpa;
	void getData();
	void showData();
}

{
float Student::averagegpa()
{

Recommended Answers

then enter however many grades they want

float grades [5] = {4, 3, 2, 1, 0};

Perhaps you can prompt the user how many students and how many grades each student will they input so you know how much to allocate your arrays.

float Student::averagegpa()

you know how to calculate …

Jump to Post

All 3 Replies

then enter however many grades they want

float grades [5] = {4, 3, 2, 1, 0};

Perhaps you can prompt the user how many students and how many grades each student will they input so you know how much to allocate your arrays.

float Student::averagegpa()

you know how to calculate avg right?
use a for loop go through each grade and sum it up and divide the number by the number of grades.

This is roughly how you would get the input, its not very hard but you need to have an understanding of loops and classes.

/*
void Student::void getData(){
1)Use cout to print statement asking to enter the student id and save the input into your variable.
2)Use a loop and ask the user to enter the students results and keep saving until they enter eof or other terminating characters.
*/

This should help you get started with the getData function.

thanks... ill work on it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.