-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector_sort_recarea.cpp
More file actions
40 lines (35 loc) · 992 Bytes
/
vector_sort_recarea.cpp
File metadata and controls
40 lines (35 loc) · 992 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
#include <iostream>
#include <vector>
#include <algorithm>
struct Rectangle
{
int length;
int breadth;
int area;
};
bool sortByArea(const Rectangle &a, const Rectangle &b)
{
return a.area >= b.area;
}
int main()
{
Rectangle obj;
std::vector<Rectangle> list;
std::cout<<"Enter the length, followed by the breadth."<<std::endl;
while(std::cin>>obj.length && std::cin>>obj.breadth)
{
obj.area = obj.length * obj.breadth;
list.push_back(obj);
}
std::cout<<"Vector before sorting"<<std::endl;
for(auto start = list.begin(); start != list.end(); start++)
{
std::cout<<"Length->"<<(*start).length <<"Breadth->"<<(*start).breadth <<"Area->"<<(*start).area<<std::endl;
}
std::cout<<"Vector after sorting"<<std::endl;
std::sort(list.begin(), list.end(), sortByArea);
for(auto start = list.begin(); start != list.end(); start++)
{
std::cout<<"Length-(oh yeah)"<<(*start).length <<"Breadth-(oh yeah)"<<(*start).breadth <<"Area-(oh yeah)"<<(*start).area<<std::endl;
}
}