fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5.  
  6.  
  7.  
  8. class Rectangle{
  9. public:
  10. Rectangle(double w, double h);
  11. double area() const {
  12. return width*height;
  13. }
  14. private:
  15. bool operator >(const Rectangle& other);
  16. double width, height;
  17. };
  18.  
  19.  
  20.  
  21. Rectangle::Rectangle(double w, double h)
  22. :width(w),height(h)
  23. {}
  24.  
  25. bool Rectangle::operator >(const Rectangle& other){
  26.  
  27. return this->area()>other->area();
  28. }
  29.  
  30.  
  31. void bubble_sort(vector<Rectangle>& vec){
  32. bool swapped = true;
  33.  
  34. for (int i=0;(i<vec.size()-1)&& swapped; i++){
  35. swapped = false;
  36.  
  37. for(int j = i; j<vec.size()-1;j++){
  38.  
  39. if(vec[j]>vec[j+1]){
  40. Rectangle temp = vec[j];
  41. vec[j] = vec[j+1];
  42. vec[j+1] = temp;
  43. swapped = true;
  44. }
  45. }
  46. }
  47. }
  48.  
  49. int main(){
  50. vector<Rectangle>v;
  51.  
  52. while(cin){
  53. double w,h;
  54.  
  55. cin>>w>>h;
  56. v.push({w,h});
  57. }
  58.  
  59. bubble_sort(v);
  60. for(int i=0; i<v.size();i++)
  61. cout<< v[i].area()<<' ';
  62. cout<< '\n';
  63. }
  64. }
  65. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘bool Rectangle::operator>(const Rectangle&)’:
prog.cpp:27:30: error: base operand of ‘->’ has non-pointer type ‘const Rectangle’
     return this->area()>other->area();
                              ^~
prog.cpp: In function ‘void bubble_sort(std::vector<Rectangle>&)’:
prog.cpp:39:34: error: ‘bool Rectangle::operator>(const Rectangle&)’ is private within this context
                 if(vec[j]>vec[j+1]){
                                  ^
prog.cpp:25:6: note: declared private here
 bool Rectangle::operator >(const Rectangle& other){
      ^~~~~~~~~
prog.cpp: In function ‘int main()’:
prog.cpp:56:15: error: ‘class std::vector<Rectangle>’ has no member named ‘push’
             v.push({w,h});
               ^~~~
prog.cpp: At global scope:
prog.cpp:64:9: error: expected declaration before ‘}’ token
         }
         ^
stdout
Standard output is empty