C++ program to find area and perimeter of rectangle using Class

Program to find area and perimeter of rectangle using Class.

C++ Program to find area and perimeter of rectangle using Class.Class is way to bind the data. It allows the data to be hidden.

#include<iostream.h>
#include<conio.h>
class rect
{
int x,y,a,p;
public:
void get()
  {
   cout<<"Enter Length of rectangle:- ";
   cin>>x;
   cout<<"Enter Breadth of rectangle:- ";
   cin>>y;
   }
void cal()
 {
  //int a,p;
  a=x*y;
  p=2*(x+y);
 }
void display()
{
 cout<<"Area of rectangle = "<<a<<endl;
 cout<<"Perimeter of rectangle = "<<p;
}
};
void main()
{
 clrscr();
 rect r;
 r.get();
 r.cal();
 r.display();
getch();
}

OUTPUT:-

area and perimeter of rectangle using Class


Comment below if you are facing any problem


Also read

C++ Program to add two numbers by defining function Outside the class
C++ Simple Program of Static Data Member
C++ program of Static Member Function

Array programs

C++ program to print alternate elements from an array
C++ program to Insert an element Into sorted array


Summary
C++ program to find area and perimeter of rectangle using Class
Article Name
C++ program to find area and perimeter of rectangle using Class
Description
This Program illustrate the concept to find area and perimeter of rectangle using Class.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *