Professional Documents
Culture Documents
#include<iostream.h>
#include<conio.h>
class com
{
protected:
float x,y;
public:
com() {}
com(float real, float img)
{
x = real;
y = img;
}
OUTPUT:
Complex Number
Enter the real number: 2
Enter the imaginary value: 2
complex number (decrement by 1): 1+(1)j
complex number (decrement by 1): s: 3+(3)j
#include<stdio.h>
#include<conio.h>
#include<math.h>
class over
{
public:
int volume(int x)
{
return(x*x*x); //cube
}
float volume(int r, int h)
{
return(3.14*r*r*h); //cylinder
}
float volume(int l, int b, int h)
{
return(l*b*h); //rectangle
}
};
void main()
{
over fo;
int x, l, b, h, r, a, n, con;
float r1, d, d1;
double a2, r2;
clrscr();
cout<<”**********FUNCTION OVERLOADING**********”;
load;
cout<<”\n enter your choice :”;
cout<<”\n 1cube \n 2cylinder \n 3rectangle”;
cin>>n;
switch(n)
{
case 1:
cout<<”\n The volume of cube “;
cout<<”\n \n enter the value of x :”;
cin>>x;
a = fo.volume(x);
cout<<”\n the volume is :”<<a;
break;
case 2:
cout<<”\n The volume of cylinder “;
cout<<”\n \n enter the value of radius & height :”;
cin>>r>>h;
a1 = fo.volume(r,h);
cout<<”\n the volume is :”<<a1;
break;
case 3:
cout<<”\n The volume of rectangle “;
cout<<”\n \n enter the value of l,b & h :”;
cin>>l>>b>>h;
a1 = fo.volume(l,b,h);
cout<<”\n the volume is :”<<a1;
break;
OUTPUT:
**********FUNCTION OVERLOADING**********
enter your choice
1 cube
2 cylinder
3 rectangle 1
#include<iostream.h>
#include<conio.h>
class emp
{
char name[10];
int eno,bs;
float pf, hra, gp, net;
public:
void input();
void output();
};
void main()
{
int n;
emp c[10];
clrscr();
cout<<”enter the number of person :”;
cin>>n;
for(int i = 0; i < n; i++);
{
c[i].input();
c[i].output();
}
getch();
};
OUTPUT
enter the number of person :1
enter employee name : santhosh
enter employee number : 230
enter basic salary : 12000
EMPLOYEE DETAILS
OUTPUT
Prime Series
2
5
7
11
13
17
19
23
29
31
37
41
43
47
20. /*class template to find maximum of two numbers*/
#include<iostream.h>
#include<conio.h>
public:
Test(T1 x, T2 y)
{
a = x;
b = y;
}
if a > b
cout<<”a is maximum \n”;
else
cout<<”b is maximum \n”;
}
int main()
test1.show();
test2.show();
};
7. /*data manipulations on array*/
#include<iostream.h>
#include<conio.h>
int a[5], ctr = 0, sum;
void main()
{
for(; ctr<5; ctr++)
{
cout<<”\n Enter 5 value “);
cin>> a[ctr];
}
void main()
{
int even[3] = {0,2,4};
int reverse[3];
for(int i = 0; int j = 2; i < 3; i++, j - -)
reverse[j] = even [i];
clrscr();
for(i = 0; i < 3; i++)
cout’\t’<< even[i] << ‘\t’ << reverse [i] << ‘\n’;
getch();
}
OUTPUT
0 4
1 2
4 0
8. /*length of a string*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char name[20];
cout<<”Enter the name\n”;
cin>>name;
cout<<”\n The length of the string \t“<<strlen(name);
getch();
}
class strings
{
char s[10];
public:
strings()
{
s[0] = ‘\0’;
}
strings(char *c)
{
strcpy(s,c);
}
char *operator+(strings x1)
{
char *temp;
strcpy(temp,s);
strcat(temp,x1.s);
return temp;
}
};