Solve this question

P

perochak

Write a C++ program to calculate the GPA of students. Your program
should contain a class named Gpa. The class should have an array named
result, as its data member.

This array is meant to take the marks/grades of student in each course.
Hence the data member of the class Gpa should be of type Template.

Your program should have following member functions of a Template Class
T.

1: input()
This function will take input of marks/grades in each course from the
user.

2: cal_gpa()

This function will calculate gpa of the student according to the
entered marks/grades. The gpa will be calculated according to the
following criteria.

If a student gets more than or equal to 80 marks or take an A grade in
a course, he should be given 12 points against that course. Similarly,
if he gets more than or equal to 70 marks and less than 80 marks or
take a B grade in a course, then he should be given 9 points against
that course. Here is the table that depicts respective grading policy

Grades Marks Points
A >=80 12
B >=70 9
C >=60 6
D >=50 3
F <=49 0


3 credit hours are given for each course.
Final gpa is calculated by adding the points of each course and then
divide the added number by total number of credit hours.

For example:
Suppose if a student has taken 5 courses in a semester. Among which he
has taken 1 A, 1 B, 1 C, 1 D and 1 F. Then his Gpa will be calculated
as

(12 + 9 + 6 + 3 + 0 ) / 15

where 15 is the total number of credit hours in 5 courses.

Take two instances of Gpa class. One is of type int and other should be
of type char. Take marks as input for instance for int type and
students grades for instance of char type. Calculate and display Gpa
against both instances according to the way mentioned above.
Also write constructor and destructor for Gpa.


Sample Output:

Enter student's marks in each course:

90
85
80
75
75
The student's Gpa is 3.6
__________________________________

Enter student's grades in each course:

A
A
A
B
B
The student's Gpa is 3.6
 
J

Jacek Dziedzic

Write a C++ program to calculate the GPA of students. Your program
should contain a class named Gpa. The class should have an array named
result, as its data member.

This array is meant to take the marks/grades of student in each course.
Hence the data member of the class Gpa should be of type Template.

Your program should have following member functions of a Template Class
T.

1: input()
This function will take input of marks/grades in each course from the
user.

2: cal_gpa()

This function will calculate gpa of the student according to the
entered marks/grades. The gpa will be calculated according to the
following criteria.

If a student gets more than or equal to 80 marks or take an A grade in
a course, he should be given 12 points against that course. Similarly,
if he gets more than or equal to 70 marks and less than 80 marks or
take a B grade in a course, then he should be given 9 points against
that course. Here is the table that depicts respective grading policy

Grades Marks Points
A >=80 12
B >=70 9
C >=60 6
D >=50 3
F <=49 0


3 credit hours are given for each course.
Final gpa is calculated by adding the points of each course and then
divide the added number by total number of credit hours.

For example:
Suppose if a student has taken 5 courses in a semester. Among which he
has taken 1 A, 1 B, 1 C, 1 D and 1 F. Then his Gpa will be calculated
as

(12 + 9 + 6 + 3 + 0 ) / 15

where 15 is the total number of credit hours in 5 courses.

Take two instances of Gpa class. One is of type int and other should be
of type char. Take marks as input for instance for int type and
students grades for instance of char type. Calculate and display Gpa
against both instances according to the way mentioned above.
Also write constructor and destructor for Gpa.


Sample Output:

Enter student's marks in each course:

90
85
80
75
75
The student's Gpa is 3.6
__________________________________

Enter student's grades in each course:

A
A
A
B
B
The student's Gpa is 3.6

What's the method of payment?

- J.
 
S

Salt_Peter

Write a C++ program to calculate the GPA of students. Your program
should contain a class named Gpa. The class should have an array named
result, as its data member.

This array is meant to take the marks/grades of student in each course.
Hence the data member of the class Gpa should be of type Template.

Your program should have following member functions of a Template Class
T.

1: input()
This function will take input of marks/grades in each course from the
user.

2: cal_gpa()

This function will calculate gpa of the student according to the
entered marks/grades. The gpa will be calculated according to the
following criteria.

If a student gets more than or equal to 80 marks or take an A grade in
a course, he should be given 12 points against that course. Similarly,
if he gets more than or equal to 70 marks and less than 80 marks or
take a B grade in a course, then he should be given 9 points against
that course. Here is the table that depicts respective grading policy

Grades Marks Points
A >=80 12
B >=70 9
C >=60 6
D >=50 3
F <=49 0


3 credit hours are given for each course.
Final gpa is calculated by adding the points of each course and then
divide the added number by total number of credit hours.

For example:
Suppose if a student has taken 5 courses in a semester. Among which he
has taken 1 A, 1 B, 1 C, 1 D and 1 F. Then his Gpa will be calculated
as

(12 + 9 + 6 + 3 + 0 ) / 15

where 15 is the total number of credit hours in 5 courses.

Take two instances of Gpa class. One is of type int and other should be
of type char. Take marks as input for instance for int type and
students grades for instance of char type. Calculate and display Gpa
against both instances according to the way mentioned above.
Also write constructor and destructor for Gpa.


Sample Output:

Enter student's marks in each course:

90
85
80
75
75
The student's Gpa is 3.6
__________________________________

Enter student's grades in each course:

A
A
A
B
B
The student's Gpa is 3.6

Show what you have done so far.
If you plan to have someone do the homework for you, consider an
alternative to programming.
Seriously: all the requirements and expected results are quite clear
and detailed, are they not?
 
O

osmium

Write a C++ program to calculate the GPA of students. Your program
should contain a class named Gpa.

The next sentence is premature, it should be later in the write-up.
The class should have an array named
result, as its data member.

This assignemnt is just plain nasty. Computing GPA is basically trivial but
*this* is embedded in a baroque specification that seems intended to drive
one crazy. I strongly recommend you start by getting a hard copy of the
assignment, and a white board if you have one. They key is to note that
grades are numbers, (int in his example) and marks are letters, or char in
geek speak.
This array is meant to take the marks/grades of student in each course.
Hence the data member of the class Gpa should be of type Template.

Your program should have following member functions of a Template Class
T.

1: input()
This function will take input of marks/grades in each course from the
user.

2: cal_gpa()

This function will calculate gpa of the student according to the
entered marks/grades. The gpa will be calculated according to the
following criteria.

I think he wants something like this, what is shown may need tweaking. As
far as I know, this complies with the specification. Getting that
compliance is the hardest part of the problem.

template <class T>
class Gpa
{
public:
Gpa();
~Gpa();
void input(); /* number of inputs are
unknown. Terminate with EOF*/
double cal_gpa();
private:
T* presult; // pointer to an array
int na; // current size of result array.
// try starting with na = 6 or so.
};
Some people would prefer vector to array, I don't have any really strong
feelings there.
But I think the use of (primitive) arrays mixed with (leading edge)
templates is incongruous.

Test it with T as an int and T as a char.
 
G

Gavin Deane

osmium said:
template <class T>
class Gpa
{
public:
Gpa();
~Gpa();
void input(); /* number of inputs are
unknown. Terminate with EOF*/
double cal_gpa();
private:
T* presult; // pointer to an array
int na; // current size of result array.
// try starting with na = 6 or so.
};
Some people would prefer vector to array, I don't have any really strong
feelings there.

Really? The assignment calls for an array, so presumably a vector would
not be acceptable. But having said that, I would have thought this is a
perfect example of how vectors could make your life easier. Nothing in
the spec says anything about how many courses a particular student
might have taken. The examples happen to use 5, but that's not stated
as a requirement. Using an array implies needing to keep count of how
many entries you've made so far, and reallocating as required. Exactly
the sort of things a vector does for you. Unless the point of this
assignment is to learn how to do that sort of thing by hand (unlikely -
since the point seems to be something about templates) the requirement
to use an array looks to me like an unnecessary complication. The only
other possibility that occurs is that, after this assignment is handed
in, the class will be shown how much simpler it could be with a vector,
but again, that message would probably be confused amongst the
templates.

Gavin Deane
 
O

osmium

Write a C++ program to calculate the GPA of students. Your program
should contain a class named Gpa. The class should have an array named
result, as its data member.

This thing has been nagging at me all day and I finally pinned down another
objection. There is no way in the world that the array should be named
result. Result of what? It is the input data, the result is a GPA for
God's sake..
 
O

osmium

Gavin Deane said:
osmium wrote:

Really? The assignment calls for an array, so presumably a vector would
not be acceptable. But having said that, I would have thought this is a
perfect example of how vectors could make your life easier. Nothing in
the spec says anything about how many courses a particular student
might have taken. The examples happen to use 5, but that's not stated
as a requirement. Using an array implies needing to keep count of how
many entries you've made so far, and reallocating as required. Exactly
the sort of things a vector does for you. Unless the point of this
assignment is to learn how to do that sort of thing by hand (unlikely -
since the point seems to be something about templates) the requirement
to use an array looks to me like an unnecessary complication. The only
other possibility that occurs is that, after this assignment is handed
in, the class will be shown how much simpler it could be with a vector,
but again, that message would probably be confused amongst the
templates.

In retrospect, what I should have said was that some people - in particular
some of the regulars of this group - would *insist* that a vector must be
used instead of an array. That attitude assumes that there are a series of
lectures and then a series of laboratory exercises. That's not the way the
world works; the lab work is interlaced with the lectures. And since
everything can't be taught in one hour, there are necessarily things the
student does not yet know. Clearly a C++ programmer would, indeed, use a
vector, but the course is not *for* C++ programmers, it is for students. He
could have worded it so a vector was permissible for those who already knew
about them. In my wording, I was simply trying to dissociate myself from
the purists.

Or even better, he could have found a problem where the usefulness of
templates doesn't have to looked for with a microscope. The end result is
an almost useless program because in the real world the mark or grade a
student gets is local to a course, not to a school. So a workable solution
would be a converter to go from letter grades to number scores on a course
by course basis - if necessary - followed by a function (probably) that
computes the GPA based on numbers. The approach followed here is all
letters or all numbers, no mixtures allowed.
 
G

Gavin Deane

In retrospect, what I should have said was that some people - in particular
some of the regulars of this group - would *insist* that a vector must be
used instead of an array. That attitude assumes that there are a series of
lectures and then a series of laboratory exercises. That's not the way the
world works; the lab work is interlaced with the lectures.

I don't think it does assume that. I think it assumes two things:
1. That at the point a lab exercise is worked on, the lectures have at
least covered all of the concepts required to complete the exercise.
2. That vectors should be taught before raw dynamic arrays.
And since
everything can't be taught in one hour, there are necessarily things the
student does not yet know. Clearly a C++ programmer would, indeed, use a
vector, but the course is not *for* C++ programmers, it is for students.

If the course is for students who want to become C++ programmers, then
I think many people (myself included) would hope that vectors are
taught first and so there is a point where the student knows vectors
but doesn't know raw arrays yet, not the other way around.

Unless the point of the exercise is specifically to learn about manual
memory management, then, continuing with my assumption that vectors
have been taught first, there is an argument that a student who doesn't
use a vector should lose marks. If they are learning to be C++
programmers, the highest score should be given to the program that most
resembles what a competent, experienced programmer would write, and
that will very likely use a vector not a raw array.

Gavin Deane
 
D

Dave Rahardja

Write a C++ program to calculate the GPA of students. Your program
should contain a class named Gpa. The class should have an array named
result, as its data member.

Homework sucks, doesn't it? Unfortunately you're looking forward to basically
a career lifetime of homework if you want to be a software developer.

I suggest you get a head start by doing this homework yourself. Come back when
you're stuck.

-dr
 
D

Diego Martins

Gavin said:
Really? The assignment calls for an array, so presumably a vector would
not be acceptable. But having said that, I would have thought this is a
perfect example of how vectors could make your life easier. Nothing in
the spec says anything about how many courses a particular student
might have taken. The examples happen to use 5, but that's not stated
as a requirement. Using an array implies needing to keep count of how
many entries you've made so far, and reallocating as required. Exactly
the sort of things a vector does for you. Unless the point of this
assignment is to learn how to do that sort of thing by hand (unlikely -
since the point seems to be something about templates) the requirement
to use an array looks to me like an unnecessary complication. The only
other possibility that occurs is that, after this assignment is handed
in, the class will be shown how much simpler it could be with a vector,
but again, that message would probably be confused amongst the
templates.

Gavin Deane

I don't know and I don't care what is a GPA, but we have to admit it is
a good exercise to build an array<> or a matrix<> template in the
classroom.
It is very good for learning templates, constructors, destructors,
memory management, first class objects...

Diego
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top