Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question#1: find the errors, and why? rec_sqr.h class Rectangle { private: publi

ID: 3551391 • Letter: Q

Question

Question#1:


find the errors, and why?


rec_sqr.h


class Rectangle


{


private:


public:


float length;


float width;


Rectangle(float l,float w);


void setlength(float);


void setwidth(float);


float perimeter();


float area();


void print();


friend void isSameArea(Rectangle , Square);


};


//--------------------------


class Square


{


private:


const float side;


Square(float s);


float perimeter();


float area();


void print();


friend void isSameArea(Rectangle , Square);


};


//-----------------------


friend void isSameArea(Rectangle rec , Square sqr);



rec_sqr.cpp


#include<iostream>


using namespace std;


Rectangle::Rectangle(float l,float w)


{length=l; width=w; }


void Rectangle::setlength(float len)


{ length = len; }


void Rectangle::setwidth(float wid)


{ width = wid; }


float Rectangle::area()


{


return length * width;


}


void Rectangle::print()


{ cout<<length<<endl;


cout<<width<<endl; }


//------------------------


Square::Square(float s)


{


side=s;


}


float Square::area()


{


return side*side;


}


void Square::print()


{


cout<<side<<endl;


}


//-----------------------


void isSameArea(Rectangle rec , Square sqr)


{


if(rec.area()==sqr.area())


cout<<"equal"<<endl;


else


cout<<"not equal"<<endl;


}


main.cpp


#include"rec_sqr.h"


int main()


{


Rectangle rec1(2,8);


const Rectangle rec2(3,4);


Square sqr(4);


rec1.isSameArea(rec1, sqr);


cout<<"rec1:"<<endl;


rec1.print();


cout<<"rec2:"<<endl;


rec2.print();


cout<<"sqr:"<<endl;


sqr.print();


system("pause");


return 0;


}





















find the errors, and why?

Explanation / Answer

In square class,all methods are defined private..but later accessed in main function..which is not correct

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote