-
Notifications
You must be signed in to change notification settings - Fork 0
/
19.cpp
101 lines (80 loc) · 1.85 KB
/
19.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
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
@Author: Amritanshu Sikdar
Session: 2018-'19
Repository: https://github.com/amritanshusikdar/CS30PracticalQuestion
*/
// Print merit list of students
#include <fstream.h>
#include <conio.h>
#include <iomanip.h>
struct merit
{
int roll, percentage;
};
void line();
void bubbleSortReverse(int*, int);
void main()
{
clrscr();
int i, j, meritList[10];
merit student;
fstream list("RESULT.TXT", ios::in | ios::out);
cout << "Enter details: " << endl;
for(i=0; i<10; i++)
{
cout << "Student " << i+1 << ":-\n";
cout << "Roll no.: ";
cin >> student.roll;
cout << "Percentage: ";
cin >> student.percentage;
meritList[i] = student.percentage;
list.write((char*) &student, sizeof(student));
}
bubbleSortReverse(meritList, 10);
cout << "\n\nMerit list of Top 10 Students: \n";
line();
cout << "S.No.\tRoll No. Percentage\n";
line();
list.seekg(0,ios::beg);
for(i=0; i<10; i++)
{
for(j=0; j<10; j++)
{
list.read((char*) &student, sizeof(student));
if(meritList[i] == student.percentage)
{
cout << setw(3) << i+1 << '\t' << setw(7) << student.roll << " " << setw(10) << student.percentage << endl;
break;
}
}
list.seekg(0,ios::beg);
}
line();
list.close();
getch();
}
void bubbleSortReverse(int *array, int size)
{
int i = size, j, temp;
do
{
for(j = size-i-1; j >= 0; j--)
{
if(array[j] < array[j+1])
{
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
i--;
}while(i > 0);
}
void line()
{
for(int i=0; i<69; i++)
{
cout << '-';
}
cout << endl;
}