language: C++ 4.7.2 (gcc-4.7.2)
date: 103 days 6 hours ago
link:
visibility: public
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
#include<iostream>
#include<list>
#include<algorithm>
#include<vector>
 
 
using namespace std;
 
class student
{
    public:
    string name;
    int roll_number;
 
    student(string n,int rn)
    {
        name=n;
        roll_number=rn;
    }
};
bool operator==(const student& lhs, const student& rhs)
{
    return lhs.name == rhs.name;
}
 
 
void display(list<student> &s)
{
    list<student> :: iterator p;
    for(p=s.begin();p!=s.end();p++)
    cout<<p->name<<" "<<p->roll_number<<endl;
}
int main()
{
    student s1("J",63),s2("P",29),s3("M",12),s4("S",71),s5("R",04);
    list<student> student_list;
 
    student_list.push_back(s1);
    student_list.push_back(s2);
    student_list.push_back(s3);
    student_list.push_back(s4);
    student_list.push_back(s5);
 
   display(student_list);
 
   list<student> :: iterator q;
   string temp;
    list<student> :: iterator s,e;
    s=student_list.begin();
    e=student_list.end();
//Accepting name of the student from the user to display roll number of it.
 
   cout<<"Please Enter the name of student:"<<endl;
   cin>>temp;
 
 
   q=find(s, e, student(temp, 0));
 
   cout<<"The number is "<<q->roll_number<<endl;
    return 0;
}