0% found this document useful (0 votes)
6 views5 pages

1136 - Experiment No 3

The document is a C++ program demonstrating constructor overloading with a class named 'constr'. It includes multiple constructors to perform addition, subtraction, and multiplication based on user input. The program continuously prompts the user for operations until they choose to exit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

1136 - Experiment No 3

The document is a C++ program demonstrating constructor overloading with a class named 'constr'. It includes multiple constructors to perform addition, subtraction, and multiplication based on user input. The program continuously prompts the user for operations until they choose to exit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

/* Name:Nayan Sunil Sonawane

Date:17-6-2022
roll no-1136
program to demonstrate constructor overloding*/

#include<iostream.h>
#include<conio.h>
int ch;

class constr
{
public:
int a,b,c;
constr(int,int);
constr(float,float);
constr(int,int,int);
void putdata();
void putdata1();

};

constr::constr(int x,int y)
{
if(ch==1)
{
int c;
c=x+y;
cout<<"\nADDITION:"<<c;
}

if(ch==2)
{
int c;
c=x-y;
cout<<"\nSUBTRACTION:"<<c;
}
}

constr::constr(float x,float y)
{
if(ch==1)
{
float c;
c=x+y;
cout<<"\nADDITION:"<<c;
}

if(ch==2)
{
float c;
c=x-y;
cout<<"\nSUBTRACTION:"<<c;
}
}

constr::constr(int a,int b,int c)

{
int d;
d=a*b*c;
cout<<"\n\tMULTIPLICATION:"<< d;

void main()
{
static int x,y,z;
static float p,q;
while(1)
{

cout<<"\n\t1.ADDITION\n\t2.SUBTRACTION\n\t3.MULTIPLICATION\n\t4.EXIT";
cout<<"\n\tENTER YOUR CHOICE\t";
cin>>ch;

switch(ch)
{
case 1:
cout<<"\n\tENTER TWO INTEGER NUMBERS\n";
cin>>x>>y;
constr c1(x,y);
cout<<"\n\tENTER TWO FLOAT NUMBER\n";
constr c2(p,q);
break;
case 2:

cout<<"\n\tENTER TWO INTEGER NUMBERS\t";


cin>>x>>y;
constr c3(x,y);
cout<<"\n\tENTER TWO FLOAT NUMBER\t";
cin>>p>>q;
constr c4(p,q);
break;

case 3:

cout<<"\n\tENTER THREE INTEGER NUMBERS\t";


cin>>x>>y>>z;
constr c5(x,y,z);

break;

case 4:

break;

default:
cout<<"\n\tWRONG CHOLCE";
}

}
getch();

OUTPUT:

You might also like