-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent_Bubble_Selection.cpp
More file actions
91 lines (84 loc) · 2.15 KB
/
Student_Bubble_Selection.cpp
File metadata and controls
91 lines (84 loc) · 2.15 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
#include<iostream>
using namespace std;
class sort {
float m[30];
int i, j, n;
public:
void insert() {
cout << "\nEnter the number of students: ";
cin >> n;
cout << "\nEnter marks: ";
for (i = 0; i < n; i++) {
cout << "\n" << m[i];
}
}
void display() {
cout << "\nMarks entered are: ";
for (i = 0; i < n; i++)
cout << "\n" << m[i];
}
void bubble() {
float temp;
for (i = 0; i < n - 1; i++) {
for (j = 0; j < (n - 1) - i; j++) {
if (m[j] > m[j + 1]) {
temp = m[j];
m[j] = m[j + 1];
m[j + 1] = temp;
}
}
}
cout << "\nTop five students are: ";
for (i = n - 1; i >= (n - 5); i--) {
cout << "\n" << m[i];
}
}
void selection() {
int min;
float temp;
for (i = 0; i < (n - 1); i++) {
min = i;
for (j = i + 1; j < n; j++) {
if (m[j] < m[min]) {
min = j;
}
}
temp = m[i];
m[i] = m[min];
m[min] = temp;
}
cout << "\nTop five students are: ";
for (i = n - 1; i >= (n - 5); i--) {
cout << "\n" << m[i];
}
}
};
int main() {
sort s;
int ch, x;
cout << "\n==============================MERIT LIST (Top 5)==============================";
do {
cout
<< "\n1.Create \n2.Display \n3.Top five using bubble sort\n4.Top five using insertion sort\nEnter your choice: ";
cin >> ch;
switch (ch) {
case 1:
s.insert();
break;
case 2:
s.display();
break;
case 3:
s.bubble();
break;
case 4:
s.selection();
break;
default:
cout << "\nWrong choice.";
}
cout << "\nDo you want ot continue? 1.Yes 2.No : ";
cin >> x;
} while (x == 1);
return 0;
}