#include <iostream.h>
class area //declare class
{
float width, lenght, areaofrect; //attributes
public:
area() //construcor
{
width=1;
lenght=1;
areaofrect=0;
}
//functions
void setwidth() //function to set width
{
again:
cout<<"Enter width of rectangle: ";
cin>>width;
if(width<0 || width>20)
{
cout<<"You cannot enter width greater than 20 and less than 0.\nEnter Valid Input."<<endl;
goto again;
}
}
void setlenght() //function to set lenght
{
again:
cout<<"Enter lenght of rectangle: ";
cin>>lenght;
if(lenght<0 || lenght>20)
{
cout<<"You cannot enter lenght greater than 20 and less than 0.\nEnter Valid Input."<<endl;
goto again;
}
}
void calculation() //function to calculate area of rectangle
{
areaofrect=width*lenght; //farmula of area of rectangle
}
void display() //function to display result
{
cout<<"Area of rectangle according to given parameters is: "<<areaofrect<<endl;
}
};
main()
{
again: //lable
area c; //create object
char ask;
//cla function of class area
c.setwidth();
c.setlenght();
c.calculation();
c.display();
// ask from user to calculate again.
cout<<"You want to calculate again? Y/N ";
cin>>ask;
if(ask=='Y' || ask== 'y')
{
goto again;
}
}
class area //declare class
{
float width, lenght, areaofrect; //attributes
public:
area() //construcor
{
width=1;
lenght=1;
areaofrect=0;
}
//functions
void setwidth() //function to set width
{
again:
cout<<"Enter width of rectangle: ";
cin>>width;
if(width<0 || width>20)
{
cout<<"You cannot enter width greater than 20 and less than 0.\nEnter Valid Input."<<endl;
goto again;
}
}
void setlenght() //function to set lenght
{
again:
cout<<"Enter lenght of rectangle: ";
cin>>lenght;
if(lenght<0 || lenght>20)
{
cout<<"You cannot enter lenght greater than 20 and less than 0.\nEnter Valid Input."<<endl;
goto again;
}
}
void calculation() //function to calculate area of rectangle
{
areaofrect=width*lenght; //farmula of area of rectangle
}
void display() //function to display result
{
cout<<"Area of rectangle according to given parameters is: "<<areaofrect<<endl;
}
};
main()
{
again: //lable
area c; //create object
char ask;
//cla function of class area
c.setwidth();
c.setlenght();
c.calculation();
c.display();
// ask from user to calculate again.
cout<<"You want to calculate again? Y/N ";
cin>>ask;
if(ask=='Y' || ask== 'y')
{
goto again;
}
}