Sunday, May 17, 2009

Department Results

Well, The Results for the Sixth Semester were declared and it has always been a practice for me to sort the results.
So,Here I am again. This Time I am sharing the Code so that People don't think I manually sort them ;).Also, I would like to congratulate all the dept guys/gals who have excelled as always and awaiting a cool Final Year ahead.





#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct stud
{
double cgpa;
double sgpa;
int roll;
};
struct sorter
{
bool operator () (const struct stud a, const struct stud b)
{
return a.cgpa>b.cgpa;
}
};
int main()
{
vectorvec;
ofstream out("res.txt");
ifstream in("in.txt");
struct stud a;
while(in>> a.roll >> a.sgpa >> a.cgpa)
vec.push_back(a);
sort(vec.begin(),vec.end(),sorter());
out<< "Roll\tSGPA\tCGPA\n" ;
for(int i=0;i<vec.size();i++){
out << vec[i].roll << "\t" << vec[i].sgpa << "\t" << vec[i].cgpa << endl;
}
out.close();
in.close();
return 0;
}


This Requires an Input File of the form :: Roll\tSGPA\tCGPA
and Output has the same Format which can be changed as well.

I would be coming out with more of code snippets.Till then Enjoy Life.

PS:

The Actual Cpp File is available at this Link :: Here
The Output File::

Roll SGPA CGPA
48 9.12 9.27
61 9.36 9.26
60 9.12 9.09
39 9.36 9.08
26 9.16 8.95
62 9.36 8.89
16 9.28 8.89
2 9.04 8.85
28 9.04 8.81
30 9.36 8.81
46 8.6 8.77
7 8.76 8.67
53 8.52 8.58
37 8.36 8.55
42 9 8.48
3 8.2 8.43
25 8.52 8.42
50 8.6 8.33
10 8.64 8.3
52 8.44 8.23
27 7.84 8.22
14 8.68 8.22
59 8.6 8.21
5 8.84 8.19
43 8.76 8.19
34 8.04 8.18
33 8.2 8.15
11 8.2 8.05
31 7.84 8.05
6 8.36 8.01
23 8.2 7.99
38 7.56 7.99
55 7.84 7.87
9 8.04 7.85
17 7.52 7.8
49 7.52 7.77
35 7.84 7.66
21 7.8 7.61
41 7.52 7.59
63 7.08 7.58
36 7.24 7.52
8 7.24 7.39
40 7.8 7.39
45 7.88 7.37
19 7.4 7.31
51 7.68 7.28
56 6.76 7.28
1 7.32 7.26
24 6.84 7.16
20 7 7.06
18 6.92 7.04
44 7.24 7.01
15 7.36 6.82
54 6.32 6.81
32 6.44 6.75
64 6.96 6.73
13 6.04 6.63
57 6.52 6.59
22 6 6.45
29 6.36 6.37
58 5.44 6.13
12 4.96 6.12
4 0 0
47 0 0