Write a program to adding a member function of class


 

/* Write a program to adding a member function of class*/

#include<iostream.h>

#include<conio.h>

class rectangle

{

private:

int l,b;

public:

void setdata(int x,int y)

{

l=x;

b=y;

}

void area()

{

int ar;

ar=l*b;

cout<<ar;

}};

void main()

{

rectangle r1,r2;

clrscr();

r1.setdata(5,6);

cout<<“area=”;

r1.area();

cout<<“\narea=”;

r2.setdata(10,11);

r2.area();

getch();

}

output:

area is=30

area is =110

Related Posts

Comments are closed.