-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlab3_q7final.cpp
More file actions
185 lines (172 loc) · 5.13 KB
/
lab3_q7final.cpp
File metadata and controls
185 lines (172 loc) · 5.13 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include<iostream>
#define MAXSIZE 10
using namespace std;
class STUDENT
{
protected:
int age;
long regno;
string name;
public:
virtual void sort(int n)=0;
};
class MTech_stud: public STUDENT
{
protected:
float gpa;
public:
MTech_stud(): STUDENT()
{
gpa = 0.0;
}
void getval()
{
cout << "Name :: ";
cin >> name;
cout <<"Age :: ";
cin >> age;
cout << "Registration Number :: ";
cin >> regno;
cout << "GPA :: ";
cin >> gpa; }
void sort(int n)
{
for (int i = 0; i < n - 1; ++i)
{
for (int j = 0; j < n - i - 1; ++j)
{
if (this[i].gpa > this[i + 1].gpa)
{
MTech_stud temp = this[i];
this[i] = this[i + 1];
this[i + 1] = temp;
}
if(this[i].gpa == this[i+1].gpa)
{
if((this[i].name.compare(this[i+1].name)) < 0)
{
MTech_stud temp = this[i];
this[i] = this[i + 1];
this[i + 1] = temp;
}
}
}
}
}
void display()
{
cout << "Name :: " << name << endl;
cout << "Age :: " << age << endl;
cout << "Reg No. :: " << regno << endl;
cout << "GPA :: " << gpa << endl << endl;
}
};
class BTech_stud: public STUDENT
{
protected:
float mks;
public:
BTech_stud(): STUDENT()
{
mks = 0.0;
}
void getval()
{
cout << "Name :: ";
cin >> name;
cout <<"Age :: ";
cin >> age;
cout << "Registration Number :: ";
cin >> regno;
cout << "Marks :: ";
cin >> mks;
}
void sort(int n)
{
for (int i = 0; i < n - 1; ++i)
{
for (int j = 0; j < n - i - 1; ++j)
{
if (this[i].mks > this[i + 1].mks)
{
BTech_stud temp = this[i];
this[i] = this[i + 1];
this[i + 1] = temp;
}
if(this[i].mks == this[i+1].mks)
{
if((this[i].name.compare(this[i+1].name)) < 0)
{
BTech_stud temp = this[i];
this[i] = this[i + 1];
this[i + 1] = temp;
}
}
}
}
}
void display()
{
cout << "Name :: " << name << endl;
cout << "Age :: " << age << endl;
cout << "Reg No. :: " << regno << endl;
cout << "Marks :: " << mks << endl << endl;
}
};
int main()
{
STUDENT *S;
BTech_stud B[MAXSIZE];
MTech_stud M[MAXSIZE];
int n, x;
while(1)
{
cout << "Choose Programme :: \n";
cout << "1. B.Tech \n";
cout << "2. M.Tech \n";
cout << "Enter 0 to EXIT \n";
cout << "Your Choice :: ";
cin >> x;
switch(x)
{
case 0:
cout << "Exiting";
exit(0);
case 1:
cout << "Enter number of Students enrolled in the B.Tech programme ( <10 ):: ";
cin >> n;
cout << "Enter data of "<< n <<" student(s)";
S = B;
for( int i = 0; i < n; ++i)
{
cout << "Student #" << i+1 << endl; B[i].getval();
}
S->sort(n);
cout <<"The details of students sorted according to Marks :: \n";
for(int i=n-1;i>=0;++i)
{
B[i].display();
}
break;
case 2:
cout << "Enter number of Students enrolled in the M.Tech programme ( <10 ):: ";
cin >> n;
cout << "Enter data of "<< n <<" student(s)\n";
S = M;
for( int i = 0; i < n; ++i)
{
cout << "Student #" << i+1 << endl;
M[i].getval();
} S->sort(n);
cout <<"The details of students sorted according to Marks :: \n";
for(int i = n-1; i >= 0; --i)
{
M[i].display();
};
break;
default:
cout << "Invalid entry!";
}
}
return 0;
}