-
Notifications
You must be signed in to change notification settings - Fork 0
/
2dArrayTask3.cpp
74 lines (66 loc) · 1.95 KB
/
2dArrayTask3.cpp
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
#include <iostream>
using namespace std;
int main()
{
//1. First we will get students' multiple subjects marks
// and display them
//2. Then we will calculate each subject gpa
//3. Finally, we will find the gpa of each student in a
// semester
// gpa = SUM(each subject gpa * credit hours)/total credit hours
// array for credit hours, size will be SUBJECTS
// array for semester gpa, size will be STUDENTS
const int STUDENTS = 2;
const int SUBJECTS = 3;
int marks[STUDENTS][SUBJECTS];
float subGpa[STUDENTS][SUBJECTS];
float semGpa[STUDENTS];
int crdHrs[SUBJECTS];
for(int i=0; i<SUBJECTS; i++)
{
cout<<"Enter the credit hours for subject "<<i+1<<" : ";
cin>>crdHrs[i];
}
int totalCrdHrs = 0;
for(int i=0; i<SUBJECTS; i++)
totalCrdHrs += crdHrs[i];
for(int i=0; i<STUDENTS; i++)
{
cout<<"**************************************\n";
cout<<"\tStudent "<<i+1<<endl;
cout<<"**************************************\n";
for(int j=0; j<SUBJECTS; j++)
{
cout<<"Enter marks for subject "<<j+1<<" : ";
cin>>marks[i][j];
}
}
float sum;
for(int i=0; i<STUDENTS; i++)
{
sum = 0.0;
cout<<"**************************************\n";
cout<<"\tStudent "<<i+1<<endl;
cout<<"**************************************\n";
for(int j=0; j<SUBJECTS; j++)
{
if(marks[i][j] >= 87 && marks[i][j] <= 100)
subGpa[i][j] = 4.0;
else if(marks[i][j] >= 80 && marks[i][j] < 87)
subGpa[i][j] = 3.5;
else if(marks[i][j] >= 72 && marks[i][j] < 80)
subGpa[i][j] = 3.0;
else if(marks[i][j] >= 67 && marks[i][j] < 72)
subGpa[i][j] = 2.5;
else if(marks[i][j] >= 60 && marks[i][j] < 67)
subGpa[i][j] = 2.0;
else
subGpa[i][j] = 0.0;
cout<<"Subject "<<j+1<<"\t"<<"Marks = "<<marks[i][j]<<"\tGPA = "<<subGpa[i][j]<<endl;
sum += subGpa[i][j]*crdHrs[j];
}
semGpa[i] = sum/totalCrdHrs;
cout<<"Semester GPA = "<<semGpa[i]<<endl;
}
return 0;
}