-
Notifications
You must be signed in to change notification settings - Fork 3
/
student.cpp
70 lines (69 loc) · 1.65 KB
/
student.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
#include<iostream>
#include<fstream>
using namespace std;
class Student
{
public :
double cgpa;
string regno,name,course;
};
int main()
{
ifstream fin;
fin.open("2Apr2.txt",ios ::in);
Student ob[20];
int i=0,j,cho,sizes=0;
while(!fin.eof())
{
fin>>ob[i].regno>>ob[i].name>>ob[i].course>>ob[i].cgpa;
i++;
sizes++;
}
cout<<"Enter your choice :- \n1)Get the details through the name of the student.\n2)Get the details through the Registration number of the student.";
cin>>cho;
if(cho==2)
{
string regno;
cin>>regno;
for(i=0;i<sizes;i++)
{
if(!ob[i].regno.compare(regno))
{
cout<<"The details of the student are :- "<<ob[i].name<<"\t"<<ob[i].regno<<"\t"<<ob[i].course<<"\t"<<ob[i].cgpa<<endl;
}
}
}
else if (cho==1)
{
string names;
cin>>names;
for(i=0;i<sizes;i++)
{
if(!ob[i].name.compare(names))
{
cout<<"The details of the student are :- "<<ob[i].name<<"\t"<<ob[i].regno<<"\t"<<ob[i].course<<"\t"<<ob[i].cgpa<<endl;
}
}
}
Student ob1;
for(i=0;i<sizes-1;i++)
{
for(j=0;j<sizes-1-i;j++)
{
if(ob[j].cgpa>ob[i].cgpa)
{
ob1 = ob[i];
ob[i] = ob[j];
ob[j] = ob1;
}
}
}
ofstream f2;
f2.open("Student1.txt",ios :: out);
for(i=0;i<sizes;i++)
{
f2<<ob[i].name<<"\t"<<ob[i].regno<<"\t"<<ob[i].course<<"\t"<<ob[i].cgpa<<endl;
}
f2.close();
fin.close();
}