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?

#include  using 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!