PROGRAM OF CONSTRUCTOR OVERLOADING





Hello Friends!!!!!! Today I am Going to learn about the constructor oveloading. Overloading of a constructor means that we use more than one constructor in a single program.A program is given below which shows you concept of constructor overloading......

So Let's Start=>

//Name : Mayank Sharma //
//Roll No : 1101026 //
//CSE(4th Sem)

PROGRAM OF CONSTRUCTOR OVERLOADING

#include
#include
class distance
{
int feet;
float inches;
public:
distance()
{
feet=0;
inches=0;
}
distance(int ft, float in)
{
feet=ft;
inches=in;
}
void get_dist()
{
cout<<"Enter feet :";
cin>>feet;
cout<<"Enter Inches :";
cin>>inches;
}
void show_dist()
{
cout< }
void add_dist(distance,distance);
};
void distance :: add_dist(distance d2,distance d3)
{
inches=d2.inches+d3.inches;
feet=0;
if(inches>=12.0)
{
inches-=12.0;
feet++;
}
feet+=d2.feet+d3.feet;
}
void main()
{
clrscr();
distance d1,d3;
distance d2(11,7.56);
d1.get_dist();
d3.add_dist(d1,d2);
cout<<"\n d1=";
d1.show_dist();
cout<<"\n d2=";
d2.show_dist();
cout<<"\n d3=";
d3.show_dist();
getch();
}

I think this post will help you.I think this post will help you.
Thanks!!!
If any query about this post then put your comment in comment box below..

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites