C++ Assign
C++ Assign
CODING:-
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,s,sp=1,k,limit=69;
clrscr();
cout<<"ABCDEFG\n";
for(i=67;i>=65;i--)
{
for(j=65;j<=i;j++)
{
cout<<(char)j;
}
for(s=1;s<=sp;s++)
{
cout<<" ";
}
[1]
for(k=limit;k<=71;k++)
{
cout<<(char)k;
}
sp+=2;
limit++;
cout<<endl;
}
cout<<endl;
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 03/10/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.1(b).CPP"<<endl;
getch();
}
OUTPUT:-
[2]
b) *
* *
* * *
CODING:-
#include<conio.h>
#include<iostream.h>
void main()
{
int i,j,k;
int num;
clrscr();
cout<<"Enter number of row = ";
cin>>num;
for(i=1;i<=num;i++)
{
for(k=1;k<=num-i;k++)
{
cout<<" ";
}
for(j=1;j<=i;j++)
{
cout<<" *";
[3]
}
cout<<"\n";
}
cout<<endl;
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 05/10/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.1(c).CPP"<<endl;
getch();
}
OUTPUT:-
[4]
c) 1
1 2
1 2 3
1 2 3 4
CODING:-
#include<iostream.h>
#include<conio.h>
class A
{
public:
int i,j;
void F()
{
for(i=1;i<5;i++)
{
for(j=1;j<=i;j++)
{
cout<<j<<" ";
}
cout<<"\n";
}
}
};
void main()
[5]
{
A obj;
clrscr();
obj.F();
cout<<endl;
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 04/10/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.1(b).CPP"<<endl;
getch();
}
OUTPUT:-
[6]
d) 1
121
1331
14641
CODING:-
#include<iostream.h>
#include<conio.h>
void main()
int i,j=1,k=11;
clrscr();
for(i=1;i<=4;i++)
k=11*k;
cout<<j;
cout<<endl;
j=k;
}
<<endl;
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 06/10/2021"<<endl;
[7]
cout<<"PATH - C:\\TUROC\\BIN\\Q.1(d).CPP"<<endl;
getch();
}
OUTPUT:-
[8]
PRACTICAL – 02
CODING:-
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
void main()
{
int i,j,k;
int choice;
clrscr();
cout<<"Enter following num for generate pattern\n";
cout<<"***********Pattern1***********\n";
cout<<"\t11\n\t12\n";
cout<<"***********Pattern2***********\n";
cout<<"\t21\n\t22\n";
cout<<"Enter your choice\n";
cin>>choice;
switch(choice)
[9]
{
case 11:
for(i=1;i<=4;i++)
{
for(j=1;j<=5-i;j++)
printf("%c",(char)(64+j));
for(k=1;k<=2*i-1;k++)
printf(" ");
printf("\b\b");
for(j=j-2;j>=0;j--)
printf("%c",(char)(65+j));
cout<<"\n";
}
break;
case 12:
for(i=1;i<=4;i++)
{
for(j=1;j<=5-i;j++)
printf("%c",(char)(64+j));
for(k=1;k<=2*i-1;k++)
cout<<" ";
cout<<"\b\b";
for(j=j-2;j>=0;j--)
printf("%c",(char)(65+j));
[10]
cout<<"\n";
}
break;
case 21:
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
cout<<j;
cout<<"\n";
}
break;
case 22:
i=1;
while(i<=4)
{
j=1;
while(j<=i)
{
for(j=1;j<=i;j++)
cout<<j;
cout<<"\n";
j=j+1;
}
i=i+1;
[11]
}
break;
default :
cout<<"Invalid Choice\n";
}
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 07/10/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.2.CPP"<<endl;
getch();
}
OUTPUT:-
[12]
PRACTICAL – 03
[13]
if(r<10)
{
r=r+48;
hex[i++]=r;
}
else
{
r=r+55;
hex[i++]=r;
}
num=num/16;
}
for(j=0;j<i;j++)
{
cout<<hex[j];
}
cout<<"";
}
}
void octal()
{
int num,temp;
int r=0,i=0,j,k;
char oct[20];
[14]
cout<<"\n\nFor Octal Number \n";
cout<<"Enter number of term:- ";
cin>>temp;
for(k=1;k<=temp;k++)
{
i=0;
num=k;
while (num!=0)
{
r=num%8;
oct[i++]=r+48;
num=num/8;
}
for(j=0;j<i;j++)
{
cout<<oct[j];
}
cout<<"";
}
}
void bin()
{
int num,temp,k;
int r=0,i=0,j;
[15]
char b[20];
cout<<"\nFor Binary number";
cout<<"\nEnter number of term:- ";
cin>>temp;
for(k=1;k<=temp;k++)
{
i=0;
num=k;
while (num!=0)
{
r=num%2;
b[i++]=r+48;
num=num/2;
}
for(j=i-1;j>=0;j--)
{
cout<<b[j];
}
cout<<"";
}
}
void Programer()
{
cout<<"\n";
[16]
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 08/10/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.3.CPP"<<endl;
}
};
void main()
{
system s1;
clrscr();
s1.hexa();
s1.octal();
s1.bin();
s1.Programer();
getch();
}
OUTPUT:-
[17]
PRACTICAL – 04
CODING:-
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<iostream.h>
void main()
{
int ch1,ch2,n,digit;
int i,j,k,f;
char p[17];
clrscr();
cout<<"Choose Num sys. for input\n";
cout<<"1.Decimal\n";
cout<<"2.Binary\n";
cout<<"3.Hexadecimal\n";
cout<<"4.Octal\n";
cin>>ch1;
cout<<"Choose Num sys. for Conversion\n";
[18]
cout<<"1.Decimal\n";
cout<<"2.Binary\n";
cout<<"3.Hexadecimal\n";
cout<<"4.Octal\n";
cin>>ch2;
switch(ch1)
{
case 1:
printf("Enter the no in Decimal\n");
scanf("%d",&n);
switch(ch2)
{
case 1:
cout<<"In Decimal=%d"<<n;
break;
case 2:
cout<<"In Binary= ";
for(j=0,i=15;j<=15,i>=0;i--,j++)
{
k=1<<i &n;
if(k!=0)
{
p[j]='1';
}
[19]
else
{
p[j]='0';
}
}
p[j]='\0';
printf("%s",p);
break;
case 3:
printf("In Hexadecimal=%x",n);
break;
case 4:
printf("In Octal=%o",n);
break;
default :
cout<<"Invalid Choice For Output";
}
break;
case 2:
cout<<"Enter The Num In Binary\n";
scanf("%s",&p);
for(i=0;p[i]!='\0';i++)
f=0;
for(j=1;j<=i;j++)
[20]
{
digit=p[j-1]-'0';
f=f+digit*pow(2,i-j);
}
n=f;
switch(ch2)
{
case 1:
cout<<"In Decimal= "<<n;
break;
case 2:
cout<<"In Binary=";
for(j=0,i=15;j<=15,i>=10;i--,j++)
{
k=1<<i &n;
if(k!=0)
{
p[j]='1';
}
else
{
p[j]='0';
}}
p[j]='\0';
[21]
printf("%s",p);
break;
case 3:
printf("In Hexadecimal=%x",n);
break;
case 4:
printf("In Octal=%o",n);
break;
default :
cout<<"Invalid Choice For Output";
}
break;
case 3:
cout<<"Ente The Num In Hexa Sys.\n";
cin>>n;
switch(ch2)
{
case 1:
printf("In Decimal=%d",n);
break;
case 2:
cout<<"In Binary=";
for(j=0,i=15;j<=15,i>=0;i--,j++)
{
[22]
k=1<<i &n;
if(k!=0)
{
p[j]='1';
}
else
{
p[j]='0';
}}
p[j]='\0';
printf("%s",p);
break;
case 3:
printf("In Hexadecimal=%x",n);
break;
case 4:
printf("In Decimal=%d",n);
break;
default :
cout<<"Inalid Choice For Output";
break;
}
switch(ch2)
{
[23]
case 1:
printf("In Decimal=%d",n);
break;
case 2:
cout<<"In Binary=";
for(j=0,i=15;j<=15,i>=0;i--,j++)
{
k=1<<i &n;
if(k!=0)
{
p[j]='1';
}
else
{
p[j]='0';
}}
p[j]='\0';
printf("%s",p);
break;
case 3:
printf("In Hexadecimal=%x",n);
break;
case 4:
printf("In Octal=%o",n);
[24]
break;
default :
cout<<"Invalid Choice";
}
break;
default :
cout<<"Invalid Choice";
}
cout<<"\n";
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 11/10/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.4.CPP"<<endl;
getch();
}
OUTPUT:-
[25]
PRACTICAL – 05
CODING:-
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
class arr1
{
int i,k,j;
int a[3][3],b[3][3],c[3][3];
public:
void add();
void sub();
void multi();
void programer()
{
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 12/10/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.5.CPP"<<endl;
}
};
[26]
void arr1::add()
{
cout<<"Perform addition operation \n\n";
cout<<"Enter array 3*3 element 1st matriks :- \n";
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cin>>a[i][j];
}
}
cout<<"Enter array 3*3 element 2nd matriks :- \n";
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cin>->b[i][j];
}
}
c[3][3]=0;
cout<<" addition of two matriks :- \n";
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
[27]
{
c[i][j]= a[i][j] +b[i][j];
cout<<" "<<c[i][j];
}
cout<<"\n";
}
}
void arr1 ::sub()
{
cout<<"Perform subtraction operation \n\n";
cout<<"Enter array 3*3 element 1st matriks :- \n";
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cin>>a[i][j];
}
}
cout<<"Enter array 3*3 element 2nd matriks :- \n";
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cin>>b[i][j];
[28]
}
}
c[3][3]=0;
cout<<" subtraction of two matriks :- \n";
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
c[i][j]= a[i][j] - b[i][j];
cout<<" "<<c[i][j];
}
cout<<"\n";
}
}
void arr1 :: multi()
{
cout<<"Perform multipliction operation \n\n";
cout<<"Enter array 3*3 element 1st matriks :- \n";
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cin>>a[i][j];
}
[29]
}
cout<<"Enter array 3*3 element 1st matriks :- \n";
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cin>>b[i][j];
}
}
c[3][3]=0;
cout<<" multipliaction of two matriks :- \n";
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
c[i][j]=0;
for(k=0;k<j;k++)
{
c[i][j]= a[i][k] + a[i][k]*b[i][j];
cout<<" "<<c[i][j];
}
}
cout<<"\n";
}
[30]
}
void main()
{
arr1 r1;
int n;
clrscr();
cout<<"Select Operation :- \n";
cout<<"1. Addition \n";
cout<<"2. Subtraction \n";
cout<<"3.Multiplication \n";
cout<<"4. Exit\n ";
cout<<"Select any one = ";
cin>>n;
if(n==1)
{
r1. add();
}
else if(n==2)
{
r1.sub();
}
else if(n==3)
{
[31]
r1.multi();
}
else if(n==4)
{
exit(0);
}
else
{
cout<<"Plz Try again";
}
r1.programer();
getch();
}
OUTPUT:-
[32]
[33]
PRACTICAL – 06
[34]
j=l-1;
while(i<j)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
i++;
j--;
}
cout<<"Reverse string is :-"<<a;
}
void count()
{
char a[15];
int i, l=0;
//char a=*x;
cout<<"\n Enter any string for find length:-\n";
cin>>a;
for(i=0;a[i]!='\0';i++)
l++;
cout<<"Length is="<<l;
}
void copy()
{
[35]
char a[15],b[15];
int i;
cout<<"\nEnter any string for copy any string-\n";
cin>>a;
for(i=0;a[i]!='\0';i++)
b[i]=a[i];
b[i]='\0';
cout<<"after copy = "<<b;
}
void vowel()
{
char a[15];
int i,c=0,v=0;
cout<<"\nEnter any string for find vowel and
consonant:-\n" ;
cin>>a;
for(i=0;a[i]!='\0';i++)
{
if((a[i]=='a')||(a[i]=='e')||(a[i]=='i')||(a[i]=='e')||(a[i]=='u ‘))
{
c++;
}
else
{
[36]
v++;
}
}
cout<<"Number of vowel is ="<<c;
cout<<"\nNumber of consonant is =" <<v;
}
};
void main()
{
clrscr();
as6 ob1;
ob1.rev();
ob1.count();
ob1.copy();
ob1.vowel();
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 13/10/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.6.CPP"<<endl;
getch();
}
[37]
OUTPUT:-
[38]
PRACTICAL – 07
CODING:-
#include<conio.h>
#include<iostream.h>
class student
{
int roll,mark1,mark2,mark3;
char name[20];
char sub1[20],sub2[20],sub3[20];
public:
void getdata();
void putdata();
void Programer()
{
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 14/10/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.7.CPP"<<endl;
}
};
void student ::getdata()
{
[39]
cout<<"Enter student name ";
cin>>name;
cout<<"Enter roll no. ";
cin>>roll;
cout<<"Enter 1st subject name & it's Marks :- \n";
cin>>sub1>>mark1;
cout<<"Enter 2nd subject name & it's Marks :- \n";
cin>>sub2>>mark2;
cout<<"Enter 3rd subject name & it's Marks :- \n";
cin>>sub3>>mark3;
}
void student ::putdata()
{
cout<<"\n Student Details\n";
cout<<"\nName = "<<name;
cout<<"\nRoll No. = "<<roll;
cout<<"\nSubject \tMax marks \tMin Marks \tObtain Marks \n
";
cout<<sub1<<"\t\t "<<100<<"\t\t "<<33<<"\t\t "<<mark1<<"\
n";
cout<<sub2<<"\t\t "<<100<<"\t\t "<<33<<"\t\t "<<mark2<<"\
n";
cout<<sub3<<"\t\t "<<100<<"\t\t "<<33<<"\t\t "<<mark3<<"\
n";
}
void main()
[40]
{
student stud;
clrscr();
stud.getdata();
stud.putdata();
stud.Programer();
getch();
}
OUTPUT:-
[41]
PRACTICAL – 08
[42]
{
cout<<"Enter student name:- ";
cin>>name;
cout<<"Enter roll no.:-";
cin>>roll;
cout<<"Enter 1st subject name & it's Marks :- \n";
cin>>sub1>>mark1;
cout<<"Enter 2nd subject name & it's Marks :- \n";
cin>>sub2>>mark2;
cin>>sub3>>mark3;
}
void student ::putdata()
{
cout<<"\n Student Details\n";
cout<<"Name = "<<name;
cout<<"\nRoll No. = "<<roll;
cout<<"\nSubject \tMax marks \tMin Marks \tObtain Marks \n
";
cout<<sub1<<"\t\t "<<100<<"\t\t "<<33<<"\t\t "<<mark1<<"\
n";
cout<<sub2<<"\t\t "<<100<<"\t\t "<<33<<"\t\t "<<mark2<<"\
n";
[43]
cout<<sub3<<"\t\t "<<100<<"\t\t "<<33<<"\t\t "<<mark3<<"\
n";
}
void main()
{
int i;
student stud[3],stud1;
clrscr();
for(i=1;i<=3;i++)
{
stud[i].getdata();
}
for(i=1;i<=3;i++)
{
stud[i].putdata();
}
stud1.programer();
getch();
}
OUTPUT:-
[44]
[45]
PRACTICAL – 09
CODING:-
#include<conio.h>
#include<iostream.h>
class array
{
int a[6],tem,j,i,b,item;
public:
array()
{
cout<<"enter 5 element \n";
for(i=1;i<=5;i++)
{
cin>>a[i];
}
}
void sort()
{
[46]
for(i=1;i<=5;i++)
{
for(j=i+1;j<=5;j++)
{
if(a[i]>a[j])
{
tem=a[i];
a[i]=a[j];
a[j]=tem;
}
}
}
for(i=1;i<=5;i++)
{
cout<<a[i]<<"\n";
}
}
void largest()
{
b=a[1];
for(i=1;i<=5;i++)
{
[47]
if(a[i]>b)
{
b=a[i];
}
}
cout<<"\nlargest element in array: -"<<b;
}
void search()
{
int k=0;
cout<<"\nEnter the element which you want to search:-";
cin>>item;
for(i=1;i<=5;i++)
{
if(item==a[i])
{
k++;
break;
}
}
if(k!=0)
{
[48]
cout<<"element present in array is:-"<<i;
}
else
{
cout<<"element is not present in array is:-";
}
}
void programer()
{
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 21/10/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.9.CPP"<<endl;
}
};
void main()
{
clrscr();
array ob1;
cout<<"sort element is:-\n";
ob1.sort();
ob1.largest();
ob1.search();
ob1.programer();
[49]
getch();
}
OUTPUT:-
PRACTICAL – 10
[50]
Q.10 Create a class simple with static member functions for
following tasks:
• To find factorial by recursive member function
• To check whether a no is prime or not
• To generate fibbonacci series up to requested terms.
CODING:-
#include<conio.h>
#include<iostream.h>
class sta1
{
public:
static void prime()
{
int i,n,p;
p=0;
cout<<"enter a number to check prime number \n";
cin>>n ;
for(i=1;i<=n;i++)
{
if(n%i==0)
{
p++;
}
}
if(p==2)
[51]
{
cout<<"number is prime";
}
else
{
cout<<"number is not prime";
}
}
static void fab()
{
static int a=0,b=1,c,n,i;
cout<<"Enter number of fabbinacci:-";
cin>>n;
cout<<a<<""<<b;
for(i=1;i<n-1;i++)
{
c=a+b;
cout<<""<<c<<"";
a=b;
b=c;
}
[52]
}
static int rec(int x)
{
static int f;
if(x==1)
{
return 1;
}
else
{
f=x*rec(x-1);
return f;
}
}
void Programer()
{
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 22/10/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.10.CPP"<<endl;
}
};
void main()
{
sta1 t1;
[53]
clrscr();
int fact,a;
cout<<"For prime number\n";
t1.prime();
cout<<"\n\nFor fabonaci series\n";
t1.fab();
cout<<"\n\nFor factorial\n";
cout<<"Enter a number ";
cin>>a;
fact=t1.rec(a);
cout<<"\nfactorial of given number is:"<<fact;
t1.Programer();
getch();
}
OUTPUT:-
[54]
PRACTICAL –13
Q.13 Create class polar having data members radius and angle it
contains member functions for taking input in data members and
Member function for displaying value of data members class
polar contains declares son of friend function at which accepts
two objects of class polar and returns object of class polar after
addition test the class using main function and objects of class
polar.
CODING:-
#include<conio.h>
#include<iostream.h>
class polar
{
public:
int radius,angle;
void input()
{
cout<<"\nEnter value of radius:-\n";
cin>>radius;
cout<<"\nEnter value of angle:-\n";
cin>>angle;
}
void output()
{-
cout<<"\nradius="<<radius;
cout<<"\nangle="<<angle;
}
[55]
void friend sum(polar x,polar y);
void Programer()
{
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 27/10/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.13.CPP"<<endl;
}
}p1,p2,p3;
void sum(polar x,polar y)
{
p3.radius=x.radius+y.radius ;
p3.angle=x.angle+y.angle;
}
void main()
{
clrscr();
p1.input();
p1.output();
p2.input();
p2.output();
cout<<"\nAfter addition of two object-\n";
sum(p1,p2);
p3.output();
p1.Programer();
getch();
}
[56]
OUTPUT:-
[57]
PRACTICAL –14
CODING:-
#include<conio.h>
#include<iostream.h>
class distance
{
int feet,inch;
public:
void get()
{
cout<<"\nEnter Feet: ";
cin>>feet;
cout<<"Enter Inch: ";
cin>>inch;
}
void showadd()
{
[58]
cout<<"\nValue Of Feet After Addition "<<feet;
cout<<"\nValue Of Ince After Addition "<<inch;
}
void showsub()
{
cout<<"\n\nValue Of Feet After Substraction "<<feet;
cout<<"\nValue Of Ince After Substraction "<<inch;
}
friend distance add(distance,distance);
friend distance sub(distance,distance);
};
distance add(distance x,distance y)
{
int a=0;
int b=0;
distance z;
z.feet=x.feet+y.feet;
z.inch=x.inch+y.inch;
if(z.inch>=12)
{
a = z.inch;
b = z.inch/12;
z.feet = z.feet+b;
z.inch = a%12;
}
return z;
[59]
}
distance sub(distance x,distance y)
{
int a=0,b=0;
distance z;
z.feet=x.feet-y.feet;
z.inch=x.inch-y.inch;
if(z.inch>=12)
{
a=z.inch;
b=z.inch/12;
z.feet=z.feet+b;
z.inch=a%12;
}
return z;
}
void main()
{
distance a,b,c,d;
clrscr();
cout<<"\nEnter First Distance: ";
a.get();
cout<<"\nEnter Second Distance: ";
b.get();
c=add(a,b);
c.showadd();
[60]
d=sub(a,b);
d.showsub();
cout<<"\n";
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 28/10/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.14.CPP"<<endl;
getch();
}
OUTPUT;-
PRACTICAL –15
[61]
Q.15 Write a Program to create class mother having data
member to store salary of mother create another class father
having data member to store salary of father write a friend
function which accept objects of class mother and father and
print sum of salary of mother and father objects.
CODING:-
#include<conio.h>
#include<iostream.h>
class father;
class mother
{
int ms;
public:
mother()
{
cout<<"Enter mother's salary:-";
cin>>ms;
}
friend void add(mother,father);
};
class father
{
int fs;
public:
father()
[62]
{
cout<<"Enter father's salary:-";
cin>>fs;
}
friend void add(mother,father);
void Programer()
{
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 29/10/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.15.CPP"<<endl;
}
};
void add(mother m,father f)
{
cout<<"\nSum of salary is:"<<m.ms+f.fs;
}
void main()
{
clrscr();
mother m;
father f;
add(m,f);
f.Programer();
[63]
getch();
}
OUTPUT:-
PRACTICAL –16
[64]
Q.16 Write a Program to create class mother having data
member to store salary of mother create another class father
having data member to store salary of father write a friend
function which accept objects of class mother and father and
print sum of salary of mother and father objects. create member
function in each class to get input in data member and to display
the value of data member.
CODING :-
#include<iostream.h>
#include<conio.h>
class father;
class mother
{
int m_sal;
public:
void get()
{
cout<<"Enter mother's salary:";
cin>>m_sal;
cout<<"The value of mother's salary is:"<<m_sal<<endl;
}
friend class father;
};
class father
{
int f_sal;
[65]
public:
void get()
{
cout<<"Enter fathers salary: ";
cin>>f_sal;
cout<<"The value of fathers salary is:"<<f_sal<<endl;
}
void add(mother m)
{
cout<<"\nSum of fathers and mothers salary is:"<<m.m_sal+f_sal;
}};
void main()
{
mother m;
father f;
clrscr();
m.get();
f.get();
f.add(m);
cout<<endl<<endl;
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 08/11/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.16.CPP"<<endl;
getch();
}
[66]
OUTPUT:-
[67]
PRACTICAL –17
CODING:-
#include<iostream.h>
#include<conio.h>
static int trackno=1;
class counter
{
public:
static void increment()
{
cout<<"Inside the increment() trackno=";
cout<<++trackno;
}
static void decrement()
{
cout<<endl<<"Inside the decrement() trackno=";
cout<<--trackno;
}
static void show()
[68]
{
cout<<endl<<"Current value of trackno
is="<<trackno<<endl;
}
void Programer()
{
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 09/11/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.17.CPP"<<endl;
}
};
void main()
{
clrscr();
counter c;
cout<<"Inside the main() trackno=";
cout<<trackno<<endl;
c.increment();
c.decrement();
c.show();
c.Programer();
getch();
}
[69]
OUTPUT:-
[70]
PRACTICAL –18
CODING:-
#include<conio.h>
#include<iostream.h>
class person
{
struct student
{
char name[20];
int roll;
int m1,m2,m3;
}stud;
public:
void input()
{
cout<<"Enter name of student: ";
cin>>stud.name;
cout<<"Enter Roll No. of student: ";
cin>>stud.roll;
cout<<"Enter marks of Hindi: ";
cin>>stud.m1;
cout<<"Enter marks of English:";
[71]
cin>>stud.m2;
cout<<"Enter marks of math:";
cin>>stud.m3;
}
void output()
{
cout<<"\n Details of student:-";
cout<<"\n Roll No. = "<<stud.roll;
cout<<"\n Name = "<<stud.name;
cout<<"\n Obtain marks";
[72]
p.input();
p.output();
p.Program();
getch();
}
OUTPUT:-
[73]
PRACTICAL –19
CODING:-
#include<iostream.h>
#include<conio.h>
class polar
{
float radius;
int angle;
public:
polar()
{
radius=16.50;
angle=60;
}
polar(float r,int a)
{
radius=r;
angle=a;
}
polar(polar &xobj)
[74]
{
radius=xobj.radius;
angle=xobj.angle;
}
void disdef()
{
cout<<"radius in default constructor is:-"<<radius<<endl;
cout<<"angle in default constructor is:-"<<angle<<endl;
}
void dispmtr()
{
cout<<"radius in parametrized constructor
is:-"<<radius<<endl;
cout<<"angle in parametrized constructor
is:-"<<angle<<endl;
}
void discpy()
{
cout<<"radius in copy constructorr:-"<<radius<<endl;
cout<<"angle in copy constructor:-"<<angle<<endl;
}
void program()
{
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 12/11/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.19.CPP"<<endl;
}
[75]
};
void main()
{
clrscr();
float radius;
int angle;
polar p;
p.disdef();
polar q(10,23);
cout<<"\n\n";
q.dispmtr();
polar r;
r=q;
cout<<"\n\n";
r.discpy();
cout<<"\n\n";
r.program();
getch();
}
[76]
OUTPUT:-
[77]
PRACTICAL –20
CODING:-
#include<iostream.h>
#include<conio.h>
class polar
{
float radius;
int angle;
public:
polar()
{
radius=14.50;
angle=60;
}
polar(float radius,int angle)
{
radius=radius;
angle=angle;
}
polar(polar &xobj)
[78]
{
radius=xobj.radius;
angle=xobj.angle;
}
void disdef()
{
cout<<"radius in default constructor is:-"<<radius<<endl;
cout<<"angle in default constructor is:-"<<angle<<endl;
}
void dispmtr()
{
cout<<"radius in parametrized constructor
is:-"<<radius<<endl;
cout<<"angle in parametrized constructor
is:-"<<angle<<endl;
}
void discpy()
{
cout<<"radius in copy constructorr:-"<<radius<<endl;
cout<<"angle in copy constructor:-"<<angle<<endl;
}
void program()
{
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 15/11/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.20.CPP"<<endl;
}
[79]
};
void main()
{
clrscr();
float radius;
int angle;
polar p;
p.disdef();
polar q(10,23);
cout<<"\n\n";
q.dispmtr();
polar r;
r=q;
cout<<"\n\n";
r.discpy();
cout<<"\n\n";
r.program();
getch();
}
[80]
OUTPUT:-
[81]
PRACTICAL –21
CODING:-
#include<iostream.h>
#include<conio.h>
class calculate
{
public:
static void area(int r)
{
float carea;
carea=3.14*r*r;
cout<<"Area of circle is: "<<carea;
}
static void area(int h,int b)
{
float rarea;
rarea=(h*b)/2;
cout<<"Area of Triangle is : "<<rarea;
}
static void area(float l,float w)
{
int tarea;
[82]
tarea=l*w;
cout<<"Area of Rectangle is: "<<tarea;
}
void Programer()
{
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 16/11/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.21.CPP"<<endl;
}
}c1;
void main()
{
clrscr();
int rad;
int h,b;
float l,w;
cout<<"\nEnter radius of circle is :";
cin>>rad;
c1.area(rad);
cout<<"\nEnter heigh of triangle:";
cin>>h;
cout<<"Enter base of triangle:";
cin>>b;
c1.area(h,b);
cout<<"\n\nEnter length of rectangle:";
cin>>l;
[83]
cout<<"Enter width of rectangle:";
cin>>w;
c1.area(l,w);
c1.Programer();
getch();
}
OUTPUT:-
[84]
PRACTICAL –22
CODING:-
#include<iostream.h>
#include<conio.h>
class Asort
{
public:
static void sort(int a[6])
{
int i,j,tem;
for(i=1;i<=5;i++)
{
for(j=i+1;j<=5;j++)
{
if(a[i]>a[j])
{
tem=a[i];
a[i]=a[j];
a[j]=tem;
}
}
}
cout<<"Sort integer number are:\n";
[85]
for(i=1;i<=5;i++)
{
cout<<a[i]<<"\n";
}
}
static void sort(float a[6])
{
float i,j,tem;
for(i=1;i<=5;i++)
{
for(j=i+1;j<=5;j++)
{
if(a[i]>a[j])
{
tem=a[i];
a[i]=a[j];
a[j]=tem;
}
}
}
cout<<" Sort Float number are:\n";
for(i=1;i<=5;i++)
cout<<a[i]<<"\n";
}
void Programer()
[86]
{
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 17/11/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.22.CPP"<<endl;
}
}a1;
void main()
{
int b[6],k;
float c[6],l;
clrscr();
cout<<"\nEnter Five integer number:";
for(k=1;k<=5;k++)
{
cin>>b[k];
}
a1.sort(b);
cout<<"\nEnter Five float number:";
for(l=1;l<=5;l++)
{
cin>>c[l];
}
a1.sort(c);
a1.Programer();
getch();
}
[87]
OUTPUT:-
[88]
PRACTICAL –23
CODING:-
#include<iostream.h>
#include<conio.h>
static void swap(int &,int &);
static void swap(float &,float &);
int main()
{ clrscr();
static int a,b;
static float x,y;
cout<<"Enter Value Of A:";
cin>>a;
cout<<"Enter Value of B:";
cin>>b;
cout<<"\n\nBefore swapping\nValue of A is "<<a<<"\
nValue of B is "<<b;
swap(a,b);
cout<<"\n\nEnter Value Of X:";
cin>>x;
cout<<"Enter Value of Y:";
cin>>y;
cout<<"\n\nBefore swapping\nValue of A is "<<x<<"\
nValue of B is "<<y;
[89]
swap(x,y);
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 18/11/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.23.CPP"<<endl;
getch();
return 0;
}
static void swap(int &a,int &b)
{
int c;
c=a;
a=b;
b=c;
cout<<"\nafter swapping\nValue of A is"<<a<<"\nValue
of B is"<<b;
}
static void swap(float &x,float &y)
{
float z;
z=x;
x=y;
y=z;
cout<<"\nafter swapping\nValue of X is"<<x<<"\nValue
of Y is"<<y;
}
[90]
OUTPUT:-
[91]
PRACTICAL –24
CODING:-
#include<iostream.h>
#include<conio.h>
static void swap(int *,int *);
static void swap(float *,float *);
int main()
{ clrscr();
static int a,b;
static float x,y;
cout<<"Enter Value Of A:";
cin>>a;
cout<<"Enter Value of B:";
cin>>b;
cout<<"\n\nBefore swapping\nValue of A is "<<a<<"\
nValue of B is "<<b;
swap(&a,&b);
cout<<"\n\nEnter Value Of X:";
cin>>x;
cout<<"Enter Value of Y:";
cin>>y;
cout<<"\n\nBefore swapping\nValue of A is "<<x<<"\
nValue of B is "<<y;
[92]
swap(&x,&y);
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 22/11/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.24.CPP"<<endl;
getch();
return 0;
}
static void swap(int *a,int *b)
{
int *c;
*c=*a;
*a=*b;
*b=*c;
cout<<"\nafter swapping\nValue of A is"<<*a<<"\nValue
of B is"<<*b;
}
static void swap(float *x,float *y)
{
float *z;
*z=*x;
*x=*y;
*y=*z;
cout<<"\nafter swapping\nValue of X is"<<*x<<"\nValue
of Y is"<<*y;
}
[93]
OUTPUT:-
[94]
PRACTICAL –25
CODING:-
#include<iostream.h>
#include<conio.h>
#include<string.h>
class string
{
public:
char *p;
int len;
[95]
public:
string()
{
len=0;
p=0;
}
string(const char *s)
{
len=strlen(s);
p=new char[len+1];
strcpy(p,s);
}
string(const string & s)
{
len=s.len;
p=new char[len+1];
strcpy(p,s.p);
}
~string()
{
delete p;
}
friend string operator +(const string &s, const string &t);
friend void show (const string s);
[96]
friend int operator <=(const string &s, const string &t);
};
string operator +(const string & s, const string &t)
{
string temp;
temp.len=s.len+t.len;
temp.p=new char[temp.len+1];
strcpy(temp.p,s.p);
strcat(temp.p,t.p);
return (temp);
}
int operator <=(const string &s, const string &t)
{
int m,n;
m=strlen(s.p);
n=strlen(t.p);
if(m<=n)
{
return 1;
}
else
{
return 0;
}
}
[97]
void show (const string s)
{
cout<<s.p;
}
int main()
{
clrscr();
string s1="new";
string s2="york";
string s3="Delhi";
string string1,string2,string3;
string1 =s1;
string2 =s2;
string3 =s1+s3;
cout<<"\nstring 1 = ";show(string1);
cout<<"\nstring 2 = ";show(string2);
cout<<"\nstring 3 = ";show(string3);
cout<<"\n\n";
if (string1<=string3)
{
show (string1);
cout<<"\nsmaller than";
show (string3);
cout<<"\n";
}
[98]
else
{
show (string3);
cout<<"\nsmaller than : ";
show (string1);
cout<<"\n";
}
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 23/11/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.25.CPP"<<endl;
getch();
return 0;
}
OUTPUT:-
[99]
PRACTICAL –26
CODING:-
#include<iostream.h>
#include<conio.h>
#include<process.h>
class MATRIX
{
float **a,r,c;
public:
MATRIX(float r=3,float c=3);
friend istream &operator >>(istream &,MATRIX &);
friend ostream &operator <<(ostream &,MATRIX &);
MATRIX operator +(MATRIX);
MATRIX operator -(MATRIX);
MATRIX operator *(MATRIX);
};
MATRIX::MATRIX(float r,float c)
{
[100]
this->r=r;
this->c=c;
a=new float*[r];
for(int i=0;i<r;i++)
{
a[i]=new float [c];
}
}
istream &operator >>(istream &in,MATRIX &obj)
{
cout<<"\n ENTER "<<obj.r*obj.c<<" ELEMENTS FOR
MATRIX \n";
for(int i=0;i<obj.r;i++)
for(int j=0;j<obj.c;j++)
cin>>obj.a[i][j];
return in;
}
ostream &operator <<(ostream &os,MATRIX &obj)
{
cout<<"\n RESULT:- \n";
for(int i=0;i<obj.r;i++)
{
for(int j=0;j<obj.c;j++)
cout<<"\t"<<obj.a[i][j];
cout<<"\n";
}
return os;
[101]
}
MATRIX MATRIX::operator +(MATRIX obj)
{
MATRIX temp;
if(r!=obj.r || c!=obj.c)
{
cout<<"\naddition not possible";
exit(1);
}
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
temp.a[i][j]=a[i][j]+obj.a[i][j];
}
return temp;
}
MATRIX MATRIX::operator -(MATRIX obj)
{
MATRIX temp;
if(r!=obj.r || c!=obj.c)
{
cout<<"\n subtraction not possible";
exit(1);
}
for(int i=0;i<r;i++)
{
[102]
for(int j=0;j<c;j++) temp.a[i]
[j]=a[i][j]-obj.a[i][j];
}
return temp;
}
MATRIX MATRIX::operator *(MATRIX obj)
{
MATRIX temp;
if(r!=obj.c)
{
cout<<"\n multiplication not possible";
exit(1);
}
temp.r=r;
temp.c=obj.c;
for(int i=0;i<r;i++)
{
for(int k=0;k<obj.c;k++)
{
temp.a[i][k]=0;
for(int j=0;j<obj.r;j++)
temp.a[i][k]=a[i][k]+a[i][j]*obj.a[j][k];
}
}
return temp;
}
void main()
[103]
{
clrscr();
MATRIX p,q,r;
cin>>p;
cin>>q;
r=p+q;
cout<<"\n RESULT OF ADDITION OF 2 MATRIX IS : \n";
cout<<r;
r=p-q;
cout<<"\n RESULT OF SUBSTRACTION OF 2 MATRIX
IS : \n";
cout<<r;
r=p*q;
cout<<"\n RESULT OF MULTIPLICATION OF 2 MATRIX
IS :\n";
cout<<r;
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 25/11/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.26.CPP"<<endl;
getch();
}
OUTPUT:-
[104]
[105]
PRACTICAL –27
CODING:-
#include<conio.h>
#include<iostream.h>
class polar
{
float radius;
int angle;
public:
polar(float r,int an)
{
radius=r;
angle=an;
}
polar(polar &in)
{
radius=in.radius;
angle=in.angle;
[106]
}
float ret()
{
return radius+angle;
}
void getdata()
{
cout<<"enter radius:-";
cin>>radius;
cout<<"enter angle:-";
cin>>angle;
}
float display()
{
cout<<"radius="<<radius<<endl;
cout<<"angle="<<angle<<endl;
return radius+angle;
}
float operator+()
{
return ret()+display();
}
};
void main()
{
[107]
float r;
int an;
clrscr();
polar P(r,an);
polar Q(P);
Q.getdata();
Q.display();
cout<<"addition of coordnates:"<<+Q<<endl;
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 26/11/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.27.CPP"<<endl;
getch();
}
OUTPUT:-
[108]
PRACTICAL –28
CODING:-
#include<iostream.h>
#include<conio.h>
class DegreeCelcius
{
public:
int cel;
friend void operator>>(istream &,DegreeCelcius &);
friend void operator<<(istream &,DegreeCelcius &);
void operator ++()
{
cel++;
}
void operator ++(int)
{
cel++;
}
[109]
void operator --()
{
cel--;
}
void operator --(int)
{
cel--;
}};
void operator>>(istream &in,DegreeCelcius &d)
{
cout<<"\nenter temperature in celcius\n";
in>>d.cel;
}
void operator<<(ostream &out,DegreeCelcius &d)
{
out<<d.cel;
}
void main()
{
clrscr();
DegreeCelcius d,u;
cin>>d;
u=d;
d++;
cout<<"\nvalue after increment by post-increment
operator="<<endl;
cout<<d;
[110]
++d;
cout<<"\nvalue after increment by pre-increment
operator="<<endl;
cout<<d;
u--;
cout<<"\nvalue after decrement by post-decrement
operator="<<endl;
cout<<u;
--u;
cout<<"\nvalue after decrement by pre-decrement
operator="<<endl;
cout<<u;
cout<<"\n";
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 29/11/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.28.CPP"<<endl;
getch();
}
OUTPUT:-
[111]
PRACTICAL –29
Q.29 create a class polar that contains data member radius and
angle. Create another class cartesian in the same program and
provide following facilities:
• It should be possible to assign object of polar class to object
of cartesian class.
• It should be possible to assign object of cartesian class to
object of polar class.
CODING:-
#include<conio.h>
#include<iostream.h>
class polar
{
int radius[10];
int angle[10];
int i,j,k,s1,s2;
public:
void getdata()
{
cout<<"Enter number of first element :-"<,endl;
cin>>s1;
cout<<"Enter number of second element :-"<<endl;
cin>>s2;
cout<<"\n Enter element for 1st set \n ";
for(i=0;i<s1;i++)
{
[112]
cin>>angle[i];
}
cout<<"Enter element for 2nd set \n";
for(i=0;i<s2;i++)
{
cin>>radius[i];
}
};
void putdata()
{
cout<<"\nCartesian product of angle and radius \n";
[113]
int angle[10];
int i,j,k,s1,s2;
public:
void getdata()
{
cout<<"Enter number of first element:-"<<endl;
cin>>s1;
cout<<"Enter number ofsecond element:-"<<endl;
cin>>s2;
cout<<"\n Enter element for 1st set:- \n ";
for(i=0;i<s1;i++)
{
cin>>angle[i];
}
cout<<"Enter element for 2nd set:-\n";
for(i=0;i<s2;i++)
{
cin>>radius[i];
}
}
void putdata()
{
cout<<"\nCartesian product of angle and radius :-\n";
[114]
{
for(j=0;j<s2;j++)
{
cout<<"("<<angle[i]<<","<<radius[j]<<") , ";
}
}
cout<<" }" ;
}
};
void main()
{
polar p1;
cartesian c;
clrscr();
p1.getdata();
p1.putdata();
c.getdata();
c.putdata();
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 30/11/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.29.CPP"<<endl;
getch();
}
[115]
OUTPUT:-
[116]
PRACTICAL –30
CODING:-
#include<conio.h>
#include<iostream.h>
class fah;
class cel
{
public:
float c;
void input()
{
cout<<"Enter value of celsius-\n";
cin>>c ;
}
void output()
{
cout<<"celsius value"<<c<<endl;
}
[117]
friend cel convert(cel x,fah y);
friend void compare(cel x, fah y);
};
class fah
{
public:
float f;
void input()
{
cout<<"Enter value of fehraeheit-\n";
cin>>f;
}
void display()
{
cout<<"fah value"<<f<<endl;
}
void operator =(const cel &c)
{
f=(9*c.c)/5+32;
display();
}
friend cel convert(cel x,fah y);
friend void compare(cel x, fah y);
};
cel convert(cel x,fah y)
{
[118]
x.c=((y.f-32)/1.8);
cout<<"celsius value after conversion"<<x.c<<endl;
return x;
}
void compare(cel x, fah y)
{
cel z;
x.input();
y.input();
z=convert(x,y);
if(x.c>z.c)
cout<<"maximum temperature is celsius="<<x.c<<endl;
else
cout<<"maximum temperature farehnheit is="<<z.c<<endl;
}
void main()
{
clrscr();
cel c;
fah f;
c.input();
f=c;
f.input();
c=convert(c,f);
c.output();
compare(c,f);
[119]
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 01/12/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.30.CPP"<<endl;
getch();
}
OUTPUT:-
[120]
PRACTICAL –31
CODING:-
#include<iostreamio.h>
#include<conio.h>
class pointer
{
int a;
float b;
void *ptr;
public:
void getint()
{
cout<<"Enter Integer Value: ";
cin>>a;
ptr=0;
ptr=&a;
cout<<"\nValue Of a = "<<a;
cout<<"\nAddress Of a = "<<ptr ;
cout<<"\nValue Of a Using Pointer a = "<< *((int*)ptr);
}
[121]
void getfloat()
{
cout<<"\n";
cout<<"\nEnter Float Value: ";
cin>>b;
ptr=0;
ptr=&b;
cout<<"\nValue Of b = "<<b;
cout<<"\nAddress of b = "<<ptr ;
cout<<"\nValue Of b Using Pointer b = "<< *((float*)ptr);
}
void program()
{
cout<<"\n";
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 02/12/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.31.CPP"<<endl;
}
};
void main()
{
pointer p1;
clrscr();
p1.getint();
p1.getfloat();
p1.program();
[122]
getch();
}
OUTPUT:-
[123]
PRACTICAL –32
CODING:-
#include <iostream.h>
#include <conio.h>
#include <math.h>
class BIGGEST_NUMBER
{
public:
void OPERATION(int A,int B,int C,int *pointer)
{
if(A>B)
if(A>C)
*pointer=A;
else
*pointer=B;
else
if(B>C)
*pointer=B;
else
*pointer=C;
}
};
[124]
void main()
{
clrscr();
BIGGEST_NUMBER E;
int a,b,c,d;
cout<<"\n ENTER 3 NUMBERS : \n";
cin>>a>>b>>c;
E.OPERATION(a,b,c,&d);
cout<<"\n BIGGEST NUMBER IS = "<<d;
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 03/12/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.32.CPP"<<endl;
getch();
}
OUTPUT:-
[125]
PRACTICAL –33
CODING:-
#include<conio.h>
#include<iostream.h>
class address
{
public:
static int a,b;
static void swap(int *a,int *b)
{
int *c;
*c=*a;
*a=*b;
*b=*a;
cout<<"\nAfter swaping value of A and B-\n";
cout<<"\n Value of a-"<<*a;
cout<<"\n Value of b-" <<*b;
}
static void swap(float *x,float *y)
{
float *z;
*z=*x;
*x=*y;
[126]
*y=*z;
cout<<"\nAfter swaping value of X and Y-\n";
cout<<"\n Value of x-"<<*x;
cout<<"\n Value of y-"<<*y;
}
};
class reference
{
public:
//static int a,b;
static void swap(int &a,int &b)
{
int c;
c=a;
a=b;
b=a;
cout<<"\nAfter swaping value of A and B-\n";
cout<<"\n Value of a-"<<a;
cout<<"\n Value of b-" <<b;
}
static void swap(float &x,float &y)
{
float z;
z=x;
x=y;
y=z;
[127]
cout<<"\nAfter swaping value of X and Y-\n";
cout<<"\n Value of x-"<<x;
cout<<"\n Value of y-"<<y;
}
};
class value
{
public:
static void swap(int a,int b)
{
int c;
c=a;
a=b;
b=c;
cout<<"\nAfter swaping value of A and B-\n";
cout<<"\n Value of A-"<<a;
cout<<"\n Value of B-"<<b;
}
static void swap(float x,float y)
{
float z;
z=x;
x=y;
y=z;
cout<<"\n After swaping value of X and Y-\n";
cout<<"\nValue of X-"<<x;
[128]
cout<<"\nValue of Y-"<<y;
}
};
void main()
{
value ob1;
reference ob2;
address ob3;
clrscr();
static int a,b;
static float x,y;
cout<<"For by address-\n";
cout<<"Enter value of A-\n";
cin>>a;
cout<<"Enter value of B-\n";
cin>>b;
cout<<"\nBefore swaping\n value of A-"<<a;
cout<<"\nvalue of B-"<<b;
ob3.swap(&a,&b);
cout<<"\nEnter value of x-\n";
cin>>x;
cout<<"\nEnter value of y-\n";
cin>>y;
cout<<"\nBefore swaping\n value of a-"<<x;
cout<<"\nValue of b-"<<y;
ob3.swap(&x,&y);
[129]
cout<<"\n\nFor by reference-\n";
cout<<"Ennter value of A-\n";
cin>>a;
cout<<"\nEnter value of B-\n";
cin>>b;
cout<<"\nBEfore swaoing\n value of A-"<<a;
cout<<"\nValue of B-"<<b;
ob2.swap(a,b);
cout<<"\n for by value-\n";
cout<<"Enter value of A-\n";
cin>>a;
cout<<"\nEnter value of B-\n";
cin>>b;
cout<<"\nBefore swaping \nvalue of A-"<<a;
cout<<"Value of B-"<<b;
ob1.swap(a,b);
cout<<"\nEnter value of X-\n";
cin>>x;
cout<<"\nEnter vakue of Y-\n";
cin>>y;
cout<<"\nBefore swaping\n value of X-" <<x ;
cout<<"\nValue of y-"<<y;
ob1.swap(x,y);
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 06/12/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.33.CPP"<<endl;
[130]
getch();
}
OUTPUT:-
[131]
[132]
PRACTICAL –35
CODING:-
#include<iostream.h>
#include<conio.h>
class item
{
public:
void Programer()
{
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 08/12/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.35.CPP"<<endl;
}
};
inline float calculate(int r)
{
return 3.14*r*r;
}
void main()
{
item i;
int radius;
float area;
[133]
clrscr();
cout<<"\nEnter radius of a circle: ";
cin>>radius;
area=calculate(radius);
cout<<"\n\nArea of of cricle is: "<<area;
i.Programer();
getch();
}
OUTPUT:-
[134]
PRACTICAL –36
CODING:-
#include<conio.h>
#include<iostream.h>
class item1
{
public:
void Programer()
{
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 09/12/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.36.CPP"<<endl;
}
};-
inline int min(int x,int y)
{
return(x<y)?x:y;
}
inline int max(int x,int y)
{
return (x>y)?x:y;
}
void main()
[135]
{
clrscr();
item1 i1;
cout<<"\nMin(20,10): "<<min(20,10);
cout<<"\nMax(30,50): "<<max(30,50);
i1.Programer();
getch();
}
OUTPUT:-
[136]
PRACTICAL –38
CODING:-
#include<iostream.h>
#include<conio.h>
class circle
{
private:
float radius;
int r;
public:
int input()
{
cout<<"\nEnter value of radius-\n";
cin>>r;
return r;
}
void area()
{
int r1;
r1=input();
radius=((3.147)*r1*r1);
[137]
}
void output()
{
cout<<"area="<<radius;
}
};
class sphere:public circle
{
private:
float v;
public:
void volume()
{
int r;
r=input();
v=(1.333)*(3.147)*r*r*r;
}
};
int main()
{
clrscr();
circle c;
sphere s;
c.area();
c.output();
s.volume();
[138]
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 13/12/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.38.CPP"<<endl;
getch();
return 0;
}
OUTPUT:-
PRACTICAL –39
[139]
Q.39 Consider an example of declaring the examination result
design three classes student exam and result the student class has
data member such as that representing roll number name of
student create the class exam which contain data members
representing name of subject minimum marks maximum marks
obtained marks for 3 subjects derived class result from both
student and exam classes test the result class in main function.
CODING:-
#include<conio.h>
#include<iostream.h>
class stu
{
protected:
int roll;
char name[10];
public:
void input_s()
{
cout<<"Enter Name of student-\n";
cin>>name;
cout<<"Enter Roll number of student-\n";
cin>>roll;
}};
class exam
{
protected:
[140]
int s1,s2,s3;
public:
void input_e()
{
cout<<"Enter marks of three sub-\n";
cin>>s1>>s2>>s3;
}};
class result:public exam,public stu
{
public:
int t;
void output()
{
t=s1+s2+s3;
cout<<"Entered Name-"<<name<<endl;
cout<<"Entered Roll no.-"<<roll<<endl;
cout<<"sub. Name min max obtain"<<endl;
cout<<"c++ 40 100 "<<s1<<endl;
cout<<"Dbms 40 100 "<<s2<<endl;
cout<<"linux 40 100 "<<s3<<endl;
if(t>119)
{
cout<<"result=pass";
}
else
{
[141]
cout<<"result=fail";
} }
}o1;
void main()
{
clrscr();
o1.input_s();
o1.input_e();
o1.output();
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 14/12/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.39.CPP"<<endl;
getch();
}
OUTPUT:-
[142]
PRACTICAL –40
Q.40 Create a base class shape having two data members with
two-member function getdata (pure virtual function) and print
area (not pure virtual function). Derive classes triangle and
rectangle from class shape and redefine member function print
area in both classes triangle and rectangle and test the
functioning of classes using pointer to base class objects and
normal objects.
CODING:-
#include<iostream.h>
#include<conio.h>
class shape
{
protected:
float b,h,l;
public:
virtual void getData()=0;
virtual void printarea()
{
}
};
class triangle:public shape
{
public:
[143]
void getData()
{
cout<<"\n ENTER BASE AND HEIGHT OF THE
RECTANGLE : \n ";
cin>>b>>h;
}
void printarea()
{
cout<<"\n AREA OF RECTANGLE IS : \n"<<1.0/2*b*h;
}};
class rectangle:public shape
{
public:
void getData()
{
cout<<"\n ENTER LENGTH AND BREADTH OF
RECTANGLE :\n";
cin>>b>>l;
}
void printarea()
{
cout<<"\n AREA OF RECTANGLE IS :"<<b*l;
}
[144]
};
void main()
{
clrscr();
triangle *t=new triangle;
rectangle *r=new rectangle;
t->getData();
t->printarea();
r->getData();
r->printarea();
shape *s;
s=t;
s->getData();
s->printarea();
s=r;
s->getData();
s->printarea();
cout<<"NAME - SURYKANT DEWANGAN"<<endl;
cout<<"DATE - 15/12/2021"<<endl;
cout<<"PATH - C:\\TUROC\\BIN\\Q.40.CPP"<<endl;
getch();
}
[145]
OUTPUT:-
[146]