Â
The Code given below can be used in TURBO C++ Compilers: -
#include <iostream.h>
#include <conio.h>
class Rectangle
{
int len, bre, area;
public:
void setlen(int l = 0)
{
len = l;
}
void setbre(int b = 0)
{
bre = b;
}
Rectangle operator*(Rectangle obj)
{
Rectangle obj1;
obj1.area = len * obj.bre;
return obj1;
}
void print()
{
cout << "Area of rectangle: " << area << " unit sq.";
}
};
void main()
{
clrscr();
int len, bdth;
cout << "Enter the Length and Breadth: ";
cin >> len >> bdth;
Rectangle Len;
Len.setlen(len);
Rectangle Bred;
Bred.setbre(bdth);
Rectangle Area;
Area = Len * Bred;
Area.print();
getch();
}
//.......Coded by SAHIL SHAIKH
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
using namespace std;
class Rectangle
{
int len, bre, area;
public:
void setlen(int l = 0)
{
len = l;
}
void setbre(int b = 0)
{
bre = b;
}
Rectangle operator*(Rectangle obj)
{
Rectangle obj1;
obj1.area = len * obj.bre;
return obj1;
}
void print()
{
cout << "Area of rectangle: " << area << " unit sq.";
}
};
int main()
{
int len, bdth;
cout << "Enter the Length and Breadth: ";
cin >> len >> bdth;
Rectangle Len;
Len.setlen(len);
Rectangle Bred;
Bred.setbre(bdth);
Rectangle Area;
Area = Len * Bred;
Area.print();
return 0;
}
//.......Coded by SAHIL SHAIKH
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP