-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12. StudentUGPG.cpp
88 lines (87 loc) · 1.8 KB
/
12. StudentUGPG.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<iostream>
using namespace std;
class student{
public:
int reg,age;
char name[50];
void getdata();
};
class ug:public student{
public:
int sem;
float fees,stipend;
void getdata();
};
class pg:public student{
public:
int sem;
float fees,stipend;
void getdata();
};
void student::getdata(){
cout<<"\nEnter Name :";
cin>>name;
cout<<"Enter Regsiter No. and Age respectively:";
cin>>reg>>age;
}
void ug::getdata(){
student::getdata();
cout<<"Enter Sem:";
cin>>sem;
cout<<"Enter fees and stipend repectively:";
cin>>fees>>stipend;
}
void pg::getdata(){
student::getdata();
cout<<"Enter Sem:";
cin>>sem;
cout<<"Enter fees and stipend repectively:";
cin>>fees>>stipend;
}
int main(){
ug u[20];
pg p[20];
int j,i,n;
float avg;
cout<<"Enter the entries of UG student:";
cin>>n;
cout<<"Enter the details\n";
for(i=0;i<n;i++)
u[i].getdata();
for(i=1;i<=8;i++){
int count=0,found=0;
float sum=0;
for(j=0;j<n;j++){
if(u[j].sem==i){
found=1;
count++;
sum+=u[j].age;
}
}
if(found==1){
avg=sum/count;
cout<<"The average age of Sem "<<i<<" is "<<avg<<endl;
}
}
cout<<"Enter the entries of PG student:";
cin>>n;
cout<<"Enter the details\n";
for(i=0;i<n;i++)
p[i].getdata();
for(i=1;i<=4;i++){
int count=0,found=0;
float sum=0;
for(j=0;j<n;j++){
if(p[j].sem==i){
found=1;
count++;
sum+=p[j].age;
}
}
if(found==1){
avg=sum/count;
cout<<"The average age of Sem "<<i<<" is "<<avg<<endl;
}
}
return 0;
}