#include<iostream.h>
#include<conio.h>
class rectangle
{
int a,b;
public:
void setdata(int x,int y)
{
a=x;
b=y;
}
void show()
{
cout<<"area of rectangle is "<<a*b;
}
};
void main()
{
clrscr();
rectangle r1,r2,r3;
r1.setdata(7,6);
r1.show();
cout<<endl;
r1.setdata(5,5);
r2.setdata(10,10);
r2.show();
cout<<endl;
r1.show();
getch();
}
- Upinder Singh Dhami
- Bangalore, Karnataka, India
- Extending one hand to help someone has more value rather than joining two hands for prayer
program to show the basics of inline function in oops
Tuesday, September 1, 2009Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: programs of oops
program to find the area and circumference of circle using classes
#include<iostream.h>
#include<conio.h>
class circle
{
float r;
public:
void setdata();
void area();
void circum();
};
void circle::setdata()
{cout<<"enter the radius of circle ";
cin>>r;
}
void circle::area()
{ double area;
area=3.14*r*r;
cout<<"area of circle "<<area<<endl;
}
void circle::circum()
{ double cir;
cir=2*3.14*r;
cout<<"circumference of circle is "<<cir<<endl;
}
void main()
{ clrscr();
circle c1,c2;
c1.setdata();
cout<<"for first circle"<<endl;
c1.area();
c1.circum();
cout<<"for second circle"<<endl;
c2.setdata();
c2.area();
c2.circum();
getch();
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: programs of oops
program to add, sub, mul ,and divide two complex numbers using classes
#include<iostream.h>
#include<conio.h>
class complex
{
double a,b,c,d;
public:
void setdata();
void add();
void subt();
void mult();
void divd();
};
double x,y;
void complex::setdata()
{
cout<<"for first number"<<endl;
cout<<"enter real part ";
cin>>a;
cout<< "enter imiginary part ";
cin>>b;
cout<<endl;
cout<<"for second number"<<endl;
cout<<"enter real part ";
cin>>c;
cout<<"enter imiginary part ";
cin>>d;
cout<<endl;
}
void complex::add()
{
x=a+c;
y=b+d;
cout<<"addition of complex number is "<<x<<" "<<y<<"i"<<endl;
}
void complex::subt()
{
x=a-c;
y=b-d;
cout<<"subtraction of complel number is "<<x<<" "<<y<<"i"<<endl;
}
void complex::mult()
{
x=(a*c)-(b*d);
y=(b*c)+(a*d);
cout<<"multiple of complex number is "<<x<<" "<<y<<"i"<<endl;
}
void complex::divd()
{
x=((a*c)+(b*d))/((c*c)+(d*d));
y=((b*c)-(a*d))/((c*c)+(d*d));
cout<<"divident number is "<<x<<" "<<y<<"i"<<endl;
}
void main()
{
clrscr();
complex c1;
c1.setdata();
c1.add();
c1.subt();
c1.mult();
c1.divd();
getch();
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: programs of oops