Write a C++ program to find the area of the rectangle using the pointer to the data member.




Algorithm:
Step 1: Start the program.
Step 2: Create a class as the rectangle.
Step 3: Declare the pointer data members.
Step 4: Declare the member functions.
Step 5: Create an object in the main function.
Step 6: Call the member function.
Step 7: Stop the program.

Program Code:
#include<iostream.h>
#include<conio.h>
class rectangleUS.COM
{
int a,b,*x,*y;
public:
void getdata();
void area();
};
void rectangle :: getdata()
{
cout<<"Enter the length of the rectangle:";
cin>>a;
cout<<"Enter the breadth of the rectangle:";
cin>>b;
x=&a;
y=&b;
}
void rectangle :: area()
{
cout<<"The area of the rectangle is:"<<*x**y;
}
void main()
{
rectangle r;
clrscr();
r.getdata();
r.area();
getch();
}




Output:
Enter the length of the rectangle:12
Enter the breadth of the rectangle:15
The area of the rectangle is:180
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: