-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPA.CPP
More file actions
93 lines (76 loc) · 1.35 KB
/
GPA.CPP
File metadata and controls
93 lines (76 loc) · 1.35 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include<iostream.h>
#include<conio.h>
class student
{
private:
char name[20],sg[8],lg[4];
int sub,lab;
float sgpa,credits;
public:
void getdata();
void calc();
void display();
};
void subcalc(float &total1,float pt,char s[],int size);
void student::getdata()
{
int i;
cout<<"\n Enter your name\n";
cin>>name;
cout<<"\nHow many subjects?\n";
cin>>sub;
cout<<"\nHow many labs?\n";
cin>>lab;
cout<<"\nCredits=";
cin>>credits;
cout<<"\n Enter grades of your "<<sub<<" subjects\n";
for(i=0;i<sub;i++)
cin>>sg[i];
cout<<"\n Enter grades of your "<<lab<<" subjects\n";
for(i=0;i<lab;i++)
cin>>lg[i];
}
void student::calc()
{
float total=0;
subcalc(total,4,sg,sub);
subcalc(total,1.5,lg,lab);
sgpa=total/credits;
}
void student::display()
{
cout<<"\n SGPA="<<sgpa;
}
void main()
{
student s;
clrscr();
s.getdata();
s.calc();
s.display();
getch();
}
void subcalc(float &total1,float pt,char s[],int size)
{
int i;
for(i=0;i<size;i++)
{
switch(s[i])
{
case 's'|'S':total1+=10*pt;
break;
case 'a'|'A':total1+=9*pt;
break;
case 'b'|'B':total1+=8*pt;
break;
case 'c'|'C':total1+=7*pt;
break;
case 'd'|'D':total1+=6*pt;
break;
case 'e'|'E':total1+=5*pt;
break;
case 'f'|'F':total1+=0;
break;
}
}
}