Calculate GPA in C++

GPA = total grade points / the total credit hours

In this assignment, you need to write a C++ program which can input a student’s courses data, such as how many courses taking, what are the credit hours and grade for each course, then calculate and output the GPA for this student. In your program, you need to construct a loop that runs N times where N is the number of courses that student takes. You also need to write codes to convert a grade to its corresponding grade points using condition branches (if-else-if or case-switch).

For example, a student takes 3 courses in the current semester and receives grades as shown in the following:

Courses |Cred. HRs.| Grade |
Course1 | 4 | B |
Course2 | 4 | C |
Course3 | 3 | A |

For the example student's GPA, the total credit hours are 11, and the grade points are converted by the rule:

A = 4.00 grade points
B = 3.00 grade points
C = 2.00 grade points
D = 1.00 grade points
F = 0.00 grade points

So, the total grade points for the student are 12 + 8 + 12 = 32.

Therefore, the GPA for the student in this semester is:
32/11 = 2.91


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

#include <iostream>
using namespace std;

int main() {
//
int N;
char g,c,gpa,cr;

//
 cout << "How many courses are you taking?: ";
 cin>> c;
 cout << "Credits for each course: ";
 cin>> cr;
 cout << "Grades for each course: ";
 cin>> g;
//
 

}


Literally all I got, this one assignment has really confused me. please help me step by step to the final product.
Last edited on
please help me step by step to the final product

What about reading the assignment?

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
// GPA = total grade points / the total credit hours
// In this assignment, you need to write a C++ program which can input a
// student’s courses data, such as how many courses taking, what are the credit
// hours and grade for each course, then calculate and output the GPA for this
// student.
// In your program, you need to construct a loop that runs N times where N is
// the number of courses that student takes.
// You also need to write codes to convert a grade to its corresponding grade
// points using condition branches (if-else-if or case-switch).
// For example, a student takes 3 courses in the current semester and receives
// grades as shown in the following:
// Courses |Cred. HRs.| Grade |
// Course1 |    4     |   B   |
// Course2 |    4     |   C   |
// Course3 |    3     |   A   |
// For the example student's GPA, the total credit hours are 11, and the grade points are converted by the rule:
// A = 4.00 grade points
// B = 3.00 grade points
// C = 2.00 grade points
// D = 1.00 grade points
// F = 0.00 grade points
// So, the total grade points for the student are 12 + 8 + 12 = 32.
// Therefore, the GPA for the student in this semester is:
// 32/11 = 2.91
#include ...

int main()
{
    /* ASSIGNMENT: a C++ program which can input ... how many courses taking */
    std::cout << "How many courses have you attended? ";
    int howmany;
    std::cin >> howmany;
    /* ASSIGNMENT: In your program, you need to construct a loop that runs N
                   times where N is the number of courses that student takes. */
    int tot_g_p {},                         // total grade points
        tot_h {};                           // total credit hours
    for(/* iterates as many times as courses attended */) {
        /* ASSIGNMENT: a C++ program which can input ... what are the credit
                       hours and grade for each course */
        std::cout << "\nWhat are the credit hours ...
        int ...
        std::cin ...
        tot_h ... 	// increment by the hours of this course
        std::cout << "What is ...
        char ...
        std::cin >> ...
        /* ASSIGNMENT: write codes to convert a grade to its corresponding grade
                       points using condition branches (if-else-if or
                       case-switch) */
        switch(/* ??? */) {
            case 'A': tot_g_p // increment by the proper grade points
            case ...
            ...
        }
    }
    std::cout << "Your current GPA is "
              << // perform a **floating point** division
              << '\n';
}

ive read it over and over again and the more i read it the more confusing it got. Thanks for an outline.
Topic archived. No new replies allowed.