Hi guys !
I am trying to find out how to do this problem using construction with useful value , here is
Can I use cons traction with
public :
void set_value (int e, int r)
{
q=e;
w=r;
}
My code
/*
Q: Write a C++ program to print the area of rectangle using class constructor?
*/
#include<iostream>
using namespace std;
class rectangle
{
int q,w ;
char o;
public :
void set_value (int e, int r)
{
q=e;
w=r;
}
rectangle(); // my construction
int area()
{
return q*w ;
}
};
Rectangle::rectangle ()// I could not do it with useful values so I use this sentence
{
cout<<"Welcome to Area Calulater \n\n";
}
int main()
{
int t,y,u;
char i;
rectangle rect;
cout << "Enter a length:\n";
cin>>t;
cout << "Enter a width:\n " ;
cin >> y;
rect.set_value(t,y);
u = rect.area();
cout<< "area of the rectangle ="<<u;
cin>>i;
return 0;
}