-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq1.cpp
More file actions
48 lines (37 loc) · 937 Bytes
/
q1.cpp
File metadata and controls
48 lines (37 loc) · 937 Bytes
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
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class customer{
public:
string name;
int age;
char gender;
double credits;
void print(){
cout<<"name = "<<name<<endl;
cout<<"age = "<<age<<endl;
cout<<"gender = "<<gender<<endl;
cout<<"credits = "<<credits<<endl;
}
};
bool ageCompare(customer a, customer b){
return a.age < b.age;
}
int main(){
vector<customer> v;
v.push_back(customer{"kartik",21,'m',5222});
v.push_back(customer{"mandeep",17,'m',4222});
v.push_back(customer{"khushi",17,'f',4222});
cout<<"Before Sorting:\n";
for(customer c : v){
cout<<c.name<<" "<<c.age<<" "<<c.credits<<endl;
}
cout<<endl;
sort(v.begin(), v.end(), ageCompare);
cout<<"After Sorting (by age):\n";
for(customer c : v){
cout<<c.name<<" "<<c.age<<" "<<c.credits<<endl;
}
return 0;
}