-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlab3_q7.cpp
More file actions
145 lines (114 loc) · 2.76 KB
/
lab3_q7.cpp
File metadata and controls
145 lines (114 loc) · 2.76 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
/*
7. Write a C++ program to create a class STUDENT with age name and register number.
Using Inheritance, derive two classes MTech-stud and BTech-stud.List both the category of
students in the increasing order of marks( for BTech-stud) and gpa( for MTech-stud). In
case of tie, display whichever name comes first. Make sort() function as a virtual function.
*/
#include <iostream>
using namespace std;
class STUDENT{
protected:
string name;
int age,reg_no;
public:
void getData();
virtual void getMark(){};
virtual int retMark(){};
virtual int sortting(){cout<<"error";};
void outPut();
};
class Btech:public STUDENT{
protected:
int mark;
public:
void getMark();
int retMark(){
return(mark);
}
int sortting();
};
class Mtech:public STUDENT{
protected:
float gpa;
public:
void getMark();
// int sort();
};
void STUDENT::getData(){
cout<< "Enter the Register Number, Name,Age\n";
cin>>reg_no>>name>>age;
}
void STUDENT::outPut(){
int mark=retMark();
cout<<reg_no<<"\t"<<name<<"\t"<<mark<<endl;
}
void Btech::getMark(){
cout<<"Enter the marks"<<endl;
cin>>mark;
}
int Btech::sortting(){
}
void Mtech::getMark(){
cout<<"Enter the GPA"<<endl;
cin>>gpa;
}
int main(){
int i,j,key,n,f;
STUDENT *str;
STUDENT temp;
Btech b[20],t;
Mtech m;
cout<<"Select \n 1.Btech \n 2.Mtech \n";
cin >> key;
switch(key){
case 1:
cout<< "Enter the number of Btech Students" <<endl;
cin>> n;
//str=b;
for(i=0;i<n;i++){
b[i].getData();
b[i].getMark();
}
/* for(i=0;i<n;i++){
str=&b[i];
str->sortting();
}
cout<<"checking"<<endl;;
t=b[1];
str=&t;
str->outPut();
/* for(i=0;i<n-1;i++){
for(j=0;j<n-i-1;j++){
str=&b[i];
f=str[j]->sortting();
cout <<"before"<<f<<endl;
if(f==1){
cout <<"f="<<f<<endl;
temp=*str[j];
*str[j]=*str[j+1];
*str[j+1]=temp;
t=b[j];
b[j]=b[j+1];
b[j+1]=t;
}
}
}
*/
cout<<"RegNo.\tName\tMarks"<<endl;
for(i=0;i<n;i++){
b[i].outPut();
}
/* break;
case 2:
cout<< "Enter the number of Mtech Students" <<endl;
cin>> n;
for(i=0;i<n;i++){
str[i]=&m;
str[i]->getData();
str[i]->getMark();
}
*/
break;
}
return 0;
}