0
class
i cant get this chapter how can we make a rectangle with a get_area and get_parameter and then resize usibg void rezise (double factor)😥😥 can someone help me
2 ответов
0
not really sure what you mean by get_parameter (I implemented it as a member function that returns an array of length and width). Here's the code (not the best, but works just fine):
#include <iostream>
using namespace std;
class Rectangle{
int length;
int width;
int area;
int parameters[2]; //not really necessary, but I'm in a hurry
public :
Rectangle():length(100), width(100){}
Rectangle (int l, int w){
this ->length = l;
this ->width = w;
}
//needs better practice
int* get_parameters(){
parameters[0] = length ;
parameters[1] = width ;
return parameters ;
}
int get_area(){
return length * width ;
}
void resize(double factor){
this ->length *= factor ;
this->width *= factor ;
}
};
int main() {
Rectangle rect(10, 15);
cout << "length = " << rect.get_parameters()[0] << ". width = " << rect.get_parameters()[1] << "\nArea = "<< rect.get_area() << endl;
rect.resize(2);
cout << "new length = " << rect.get_parameters()[0] << ". new width = " << rect.get_parameters()[1] << "\nNew area = "<< rect.get_area() << endl;
return 0;
}
0
ooo thanks alot..it help me with my lab