-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patha01.cpp
More file actions
255 lines (252 loc) · 5.25 KB
/
a01.cpp
File metadata and controls
255 lines (252 loc) · 5.25 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
//============================================================================
// Assignment 2
// Roll No. : 21164
// Name : Sooraj VS
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include<bits/stdc++.h>
using namespace std;
class Student{
int rollNo;
float marks;
public:
Student();
void read();
void display();
friend class Database;
};
Student::Student(){
rollNo=0;
marks=0.0;
}
void Student::read(){
validation1:
cout<<"\nRoll No : ";cin>>rollNo;
if(rollNo<1){
cout<<"\nInvalid Roll No, Try Again!";
goto validation1;
}
validation2:
cout<<"\nMarks : ";cin>>marks;
if(marks<-1||marks>100){
cout<<"\nInvalid Marks, Try Again!";
goto validation2;
}
}
void Student::display(){
if(marks==-1){
cout<<"\n "<<rollNo<<"\t\tA";
return;
}
cout<<"\n "<<rollNo<<"\t\t"<<marks;
}
class Database{
Student *s;
int t,p;
public:
Database();
Database(int);
void allocate(int);
void read();
void display();
int absent();
Student maxMarks();
Student minMarks();
void searchStudent(Student);
float average();
int mode();
void menu();
void arrange();
};
Database::Database(){
s=NULL;
t=0;
p=0;
}
Database::Database(int n){
this->t=n;
s=new Student[this->t];
p=0;
}
void Database::allocate(int n){
this->t=n;
s=new Student[this->t];
p=0;
}
void Database::arrange(){
Student temp;
for(int i=0;i<t;i++){
for(int j=i+1;j<t;j++){
if(s[i].rollNo>s[j].rollNo){
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
}
void Database::read(){
for(int i=0;i<t;i++){
validation3:
cout<<"\nStudent "<<i+1;
s[i].read();
for(int j=0;j<i;j++){
if(s[i].rollNo==s[j].rollNo){
cout<<"\nStudent Roll No. Repeated, Try Again!";
goto validation3;
}
}
}
for(int i=0;i<t;i++){
if(s[i].marks!=-1)
p++;
}
}
float Database::average(){
float avg=0.0;
for(int i=0;i<t;i++){
if(s[i].marks!=-1)
avg+=s[i].marks;
}
if(p)
avg=avg/p;
return avg;
}
int Database::mode(){
Student temp;
int count=0,frequency=0;
for(int i=0;i<t;i++){
for(int j=i+1;j<t;j++){
if(s[i].marks>s[j].marks){
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
for(int i=0;i<t;i++){
count=0;
if(s[i].marks!=-1){
for(int j=0;j<t;j++){
if(s[i].marks==s[j].marks)
count++;
}
}
if(count>=frequency){
frequency=count;
temp=s[i];
}
}
if(frequency==1)
return 0;
cout<<"\nMost Scored Marks = "<<temp.marks;
return frequency;
}
void Database::display(){
cout<<"\nMARKS DATABASE: ";
cout<<"\nRoll No.\tMarks";
for(int i=0;i<t;i++){
s[i].display();
}
}
Student Database::maxMarks(){
Student max;
for(int i=0;i<t;i++){
if(s[i].marks>max.marks)
max=s[i];
}
return max;
}
Student Database::minMarks(){
Student min;
min.marks=100;
for(int i=0;i<t;i++){
if(s[i].marks!=-1&&s[i].marks<min.marks)
min=s[i];
}
return min;
}
void Database::searchStudent(Student a){
for(int i=0;i<t;i++){
if(s[i].marks==a.marks)
s[i].display();
}
return;
}
int Database::absent(){
for(int i=0;i<t;i++)
if(s[i].marks==-1)
s[i].display();
return t-p;
}
void Database::menu(){
cout<<"\n----------------------DATABASE MENU----------------------";
cout<<"\n| Press 1: Re-Enter Test Database |";
cout<<"\n| Press 2: Display Test Database |";
cout<<"\n| Press 3: Most Scored Marks |";
cout<<"\n| Press 4: Average Score of the Test |";
cout<<"\n| Press 5: Max Score of the Test |";
cout<<"\n| Press 6: Max Score of the Test |";
cout<<"\n| Press 7: Absent Students List |";
cout<<"\n---------------------------------------------------------";
}
int main(){
int choice,n,count=0;
Student s;
cout<<"\n----------------------DATABASE ENTRY---------------------";
cout<<"\nEnter No. of Students: ";
cin>>n;
Database dsa(n);
dsa.read();
dsa.arrange();
cout<<"\nData Entry Successful!";
dsa.menu();
do{
cout<<"\n---------------------------------------------------------";
cout<<"\nEnter Choice [0-Exit|9-Menu]: ";
cin>>choice;
switch(choice){
case 0: cout<<"\n---------------------------END---------------------------";
break;
case 1: cout<<"\n----------------------DATABASE ENTRY---------------------";
cout<<"\nEnter No. of Students: ";
cin>>n;
dsa.allocate(n);
dsa.read();
dsa.arrange();
cout<<"\nData Entry Successful!";
break;
case 2: dsa.display();
break;
case 3: count=dsa.mode();
if(count)
cout<<", Scored by "<<count<<" Students";
else
cout<<"\nNo Scores Repeated!";
dsa.arrange();
break;
case 4: cout<<"\nAverage Test Score = "<<dsa.average();
break;
case 5: s=dsa.maxMarks();
cout<<"\nHighest Score:";
cout<<"\nRoll No.\tMarks";
dsa.searchStudent(s);
break;
case 6: s=dsa.minMarks();
cout<<"\nLowest Score:";
cout<<"\nRoll No.\tMarks";
dsa.searchStudent(s);
break;
case 7: cout<<"\nAbsent Students:";
cout<<"\nRoll No. --";
count=dsa.absent();
cout<<"\nAbsent Count = "<<count;
break;
case 9: dsa.menu();
break;
default:cout<<"\nInvalid Choice, Try Again!";
}
}while(choice);
return 0;
}