Question: In C++. Write a class having two private variables and one member function which will return the area of the rectangle. How can I do
In C++.
Write a class having two private variables and one member function which will return the area of the rectangle.
How can I do cuz I'm stucked with this?
#includeusing namespace std; class Rectangle{ private: double longueur; double largeur; public: /*Rectangle(double longueur,double largeur){ this->longueur = longueur; this->largeur = largeur; }*/ Rectangle(double longueur,double largeur); friend class Donnees; }; class Donnees{ public: Donnees(const Rectangle& r); double aire()const; private: Rectangle r; }; double Donnees::aire() const { return r.longueur * r.largeur; } int main() { cout << "Hello, World!" << endl; //Rectangle rr (5.0,2.0); //double aire = rr.aire(); double longueur,largeur; cout << "The length of rectangle is :"; cin >> longueur; cout << "The width of rectangle is :"; cin >> largeur; const Rectangle r = Rectangle(longueur,largeur); Donnees dd = Donnees(r); double aire1 = dd.aire(); //Donnees dd(Rectangle); cout << "The area is :"; cout << aire1; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
