0% found this document useful (0 votes)
152 views

C++ LAB Assignment: Vrinda Kaushal 2 Semester Section - A Bba (Cam) 1031211908

C++ LAB ASSIGNMENT VRINDA KAUSHAL 2ND SEMESTER SECTION - A BBA (CAM) 1031211908 1. TO PRINT “HELLO” :- #include #include void main() { clrscr(); cout<<" HELLO"; getch(); } 2. TO PRINT A=10 :#include #include void main() { clrscr(); int a=10; cout< #include void main() { clrscr(); int a=10; cout<<"a="< #include

Uploaded by

kaushalvrinda
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views

C++ LAB Assignment: Vrinda Kaushal 2 Semester Section - A Bba (Cam) 1031211908

C++ LAB ASSIGNMENT VRINDA KAUSHAL 2ND SEMESTER SECTION - A BBA (CAM) 1031211908 1. TO PRINT “HELLO” :- #include #include void main() { clrscr(); cout<<" HELLO"; getch(); } 2. TO PRINT A=10 :#include #include void main() { clrscr(); int a=10; cout< #include void main() { clrscr(); int a=10; cout<<"a="< #include

Uploaded by

kaushalvrinda
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 67

C++

LAB
ASSIGNMENT

VRINDA KAUSHAL
2ND SEMESTER
SECTION - A
BBA (CAM)
1031211908
1. TO PRINT “HELLO” :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" HELLO";
getch();
}

2. TO PRINT A=10 :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=10;
cout<<a;
getch();
}

3. TO PRINT “A=10” :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=10;
cout<<"a="<<a;
getch();
}

4. TO PRINT CHARACTER :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char a='z';
cout<<a;
getch();
}

5. TO PRINT FLOAT VALUE :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float a=26935.635;
cout<<a;
getch();
}
6. TO PRINT THE VALUE OF TWO NUMBERS :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"Enter the value of a";
cin>>a;
cout<<"Enter the value of b";
cin>>b;
getch();
}

7. TO PRINT THE SUM OF TWO NUMBERS :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"Enter the value of a";
cin>>a;
cout<<"Enter the value of b";
cin>>b;
c=a+b;
cout<<"c="<<c;
getch();
}
8. TO SWAP THE VALUES OF TWO NUMBERS USING THIRD
VARIABLE :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"Enter the value of a";
cin>>a;
cout<<"Enter the value of b";
cin>>b;
c=a;
a=b;
b=c;
cout<<a<<endl;
cout<<b<<endl;
getch();
}

9. TO SWAP THE VALUES OF TWO NUMBERS WITHOUT USING


THIRD VARIABLE :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"Enter the value of a";
cin>>a;
cout<<"Enter the value of b";
cin>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<a<<endl;
cout<<b<<endl;
getch();
}
10. TO ENTER BASIC SALARY OF AN EMPLOYEE :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int basic,hra,pf,da,total;
cout<<"Enter the value of basic";
cin>>basic;
hra=basic*0.12;
cout<<"hra="<<hra<<endl;
pf=basic*0.09;
cout<<"pf="<<pf<<endl;
da=basic*0.14;
cout<<"da="<<da<<endl;
total=basic+hra+pf+da;
cout<<"total="<<total<<endl;
getch();
}

11. TO SHOW THE USE OF INCREMENT/DECREMENT OPERATOR :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=12,b;
b=++a;
cout<<a<<endl;
cout<<b<<endl;
b=a++;
cout<<a<<endl;
cout<<b<<endl;
b=--a;
cout<<a<<endl;
cout<<b<<endl;
b=a--;
cout<<a<<endl;
cout<<b<<endl;
getch();
}

12. TO SHOW THE USE OF ARTHIMETIC OPERATORS :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i=20,j=10,a,s,m,d;
a=i+j;
cout<<"a="<<a<<endl;
s=i-j;
cout<<"s="<<s<<endl;
m=i*j;
cout<<"m="<<m<<endl;
d=i/j;
cout<<"d="<<d<<endl;
getch();
}
13. TO PRINT THE BASIC SALARY WITH A OR B GRADES :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int basic;
cout<<"Enter the employee basic";
cin>>basic;
if(basic<5000)
cout<<"B";
else
cout<<"A";
getch();
}

14. TO PRINT THE BASIC SALARY WITH A, B OR C GRADES :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int basic;
cout<<"Enter the employee basic";
cin>>basic;
if(basic<=5000)
cout<<"C";
else if(basic>=5000 && basic<15000)
cout<<"B";
else
cout<<"A";
getch();
}
15. TO CHECK WHETHER THE GIVEN YEAR IS LEAP YEAR OR NOT:-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int year;
cout<<"Enter the Year";
cin>>year;
if(year%4==0)
cout<<"Leap Year";
else
cout<<"Not a Leap Year";
getch();
}

16. TO CHECK WHETHER THE GIVEN CHARACTER IS VOWEL OR


CONSONANT :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char z;
cout<<"Enter the character of z";
cin>>z;
if(z=='a'||z=='e'||z=='i'||z=='o'||z=='u')
cout<<"Vowel";
else
cout<<"Consonant";
getch();
}
17. TO PRINT THE TABLE :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x,y=1;
cout<<"Enter the value of x";
cin>>x;
while(y<=10)
{
cout<<x*y<<endl;
y++;
}
getch();
}

18. TO PRINT THE NUMBERS FROM 1 TO 20 :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int y=1;
while(y<=20)
{
cout<<y<<endl;
y++;
}
getch();
}

19. TO SUM UP FROM 1 TO 20 AND PRINT IT :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int y=1,sum=0;
while(y<=20)
{
cout<<y<<endl;
sum=sum+y;
y++;
}
cout<<"sum="<<sum;
getch();
}
20. TO REVERSE THE VALUE OF A NUMBER :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"Enter the value of a";
cin>>a;
while(a!=0)
{
b=a%10;
cout<<b;
a=a/10;
}
getch();
}

21. TO PRINT FROM 1 TO 50 WITH EVEN OR ODD :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int y=1;
while(y<=50)
{
if(y%2==0)
cout<<" Even"<<endl;
else
cout<<" Odd"<<endl;
cout<<y;
y++;
}
getch();
}

22.TO CHECK THE CONDITION OF WHILE :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=12;
do
{
cout<<a<<endl;
a++;
}
while(a<=10);
getch();
}
23. TO PRINT FROM 1 TO 10 USING WHILE LOOP :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=1;
do
{
cout<<a<<endl;
a++;
}
while(a<=10);
getch();
}

24. TO CHECK WHATHER THE NUMBER IS EVEN OR ODD :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
cout<<"Enter the value of n";
cin>>n;
if(n%2==0)
cout<<"Even number";
else
cout<<"Odd number";
getch();
}

25. TO PRINT THE TOTAL OF A NUMBER :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,sum=0;
cout<<"Enter the value of a";
cin>>a;
while(a!=0)
{
b=a%10;
sum=sum+b;
a=a/10;
}
cout<<sum;
getch();
}

26.TO PRINT FROM A TO Z USING FOR :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char a;
for(a=65;a<=90;a++)
{
cout<<a<<endl;
}
getch();
}

27. TO PRINT A NUMBER TRIANGLE :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
for(a=1;a<=6;a++)
{
for(b=1;b<=a;b++)
{
cout<<b;
}
cout<<endl;
}
getch();
}
28. TO PRINT TABLE USING FOR LOOP :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"Enter the value of a";
cin>>a;
for(b=1;b<=10;b++)
{
cout<<a*b<<endl;
}
getch();
}

29. TO CHECK WHETHER THE NUMBER IS EVEN OR ODD AND ASK


TO CONTINU FURTHER OR NOT :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
char z;
do
{
cout<<"Enter the value of a";
cin>>a;
if(a%2==0)
cout<<"Even no."<<endl;
else
cout<<"Odd no."<<endl;
cout<<"Do you want to continue Y/N";
cin>>z;
}
while(z=='y'||z=='Y');
getch();
}

30. TO PRINT FROM Z TO A :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char z;
for(z=90;z>=65;z--)
{
cout<<z<<endl;
}
getch();
}
31. TO PRINT A TRIANGLE OFCHARACTERS :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char a;
int i;
for(i=0;i<=6;i++)
{
for(a=65;a<=70-i;a++)
{
cout<<a;
}
cout<<endl;
}
getch();
}
32. TO PRINT CHARACTERS - DOWNWARD TRIANGLE :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char a;
int i,j;
for(i=0;i<=6;i++)
{
for(a=65;a<=70-i;a++)
{
cout<<a;
}
for(j=0;j<2*i;j++)
{
cout<<" ";
}
for(a=70-i;a>=65;a--)
{
cout<<a;
}
cout<<endl;
}
getch();
}

33. TO PRINT CHARACTERS – UPWARD TRIANGLE :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char a;
int i,j;
for(i=6;i>=0;i--)
{
for(a=65;a<=70-i;a++)
{
cout<<a;
}
for(j=2*i;j>0;j--)
{
cout<<" ";
}
for(a=70-i;a>=65;a--)
{
cout<<a;
}
cout<<endl;
}
getch();
}

34. TO SUM UP THE NUMBERS AND PRINT THEM :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,a=0,b=1,c;
cout<<a<<endl;
cout<<b<<endl;
for (i=0;i<10;i++)
{
c=a+b;
a=b;
b=c;
cout<<c<<endl;
}
getch();
}
35. TO PRINT LEFTSIDE TRIANGLE OF NUMBERS :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k,l;
for(i=1;i<=6;i++)
{
for(j=1;j<=i;j++)
{
cout<<j;
}
cout<<endl;
}
for(k=5;k>=1;k--)
{
for(l=1;l<=k;l++)
{
cout<<l;
}
cout<<endl;
}
getch();
}
36. TO PRINT THE NUMBERS AS A TRIANGLE AND OF ONE KIND IN
ONE ROW :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j;
for(i=1;i<=6;i++)
{
for(j=1;j<=i;j++)
{
cout<<i;
}
cout<<endl;
}
getch();
}

37. TO PRINT “HELLO” IN A CONTINUATION :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j;
for(i=1;i<=6;i++)
{
for(j=1;j<=i;j++)
{
cout<<"Hello";
}
cout<<endl;
}
getch();
}

38. TO PRINT THE CHARACTERS AS A TRIANGLE AND OF ONE


KIND IN ONE ROW :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j;
char a=65;
for(i=1;i<=6;i++)
{
for(j=1;j<=i;j++)
{
cout<<a;
}
a=a+1;
cout<<endl;
}
getch();
}
39. TO PRINT A STAR OF UPWARD TRIANGLE :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k;
for(i=1;i<=6;i++)
{
for(j=i;j<=6;j++)
{
cout<<" ";
}
for(k=1;k<=i;k++)
{
cout<<" *";
}
cout<<endl;
}
getch();
}

40. TO PRINT A STAR OF DOWNWARD TRIANGLE :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k;
for(i=6;i>=1;i--)
{
for(j=i;j<=6;j++)
{
cout<<" ";
}
for(k=1;k<=i;k++)
{
cout<<" *";
}
cout<<endl;
}
getch();
}

41. TO PRINT STARS AS A SHAPE OF DIAMOND :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,e,f;
for(a=1;a<=6;a++)
{
for(b=a;b<=6;b++)
{
cout<<" ";
}
for(c=1;c<=a;c++)
{
cout<<" *";
}
cout<<endl;
}
for(d=5;d>=1;d--)
{
for(e=d;e<=6;e++)
{
cout<<" ";
}
for(f=1;f<=d;f++)
{
cout<<" *";
}
cout<<endl;
}
getch();
}

42. TO PRINT NUMBER TRIANGLE :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d;
for(a=1;a<=7;a++)
{
for(b=a;b<=7;b++)
{
cout<<" ";
}
for(c=1;c<=a;c++)
{
cout<<c;
}
for(d=a-1;d>=1;d--)
{
cout<<d;
}
cout<<endl;
}
getch();
}
43. TO PRINT THE SHAPE OF A HUT :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d;
for(a=1;a<=6;a++)
{
for(b=a;b<=6;b++)
{
cout<<" ";
}
for(c=1;c<=a;c++)
{
cout<<" *";
}
cout<<endl;
}
for(d=1;d<=6;d++)
{
cout<<" * * * *";
cout<<endl;
}
getch();
}
44. TO PRINT THE SHAPE OF DOWNWARD TRIANGLE WITH
NUMBERS :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d;
for(a=0;a<=6;a++)
{
for(b=1;b<=6-a;b++)
{
cout<<b;
}
for(c=0;c<2*a;c++)
{
cout<<" ";
}
for(d=6-a;d>=1;d--)
{
cout<<d;
}
cout<<endl;
}
getch();
}
45. TO PRINT TWO NUMBERS AND USE THE SWITCH CASE :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"Enter the value of a";
cin>>a;
cout<<"Enter the value of b";
cin>>b;
cout<<"Enter the case";
cin>>c;
switch(c)
{
case 1:
cout<<a*b;
break;
case 2:
cout<<a-b;
break;
case 3:
cout<<a+b;
break;
case 4:
cout<<a/b;
break;
default:
cout<<"No match case";
}
getch();
}

46. TO USE SWITCH CASE WITH DO – WHILE :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char a,z;
do
{
cout<<"Enter the case";
cin>>a;
switch(a)
{
case 'A':
cout<<"Sunday";
break;
case'B':
cout<<"Monday";
break;
case 'C':
cout<<"Tuesday";
break;
case 'D':
cout<<"Wednesday";
break;
case 'E':
cout<<"Thrusday";
break;
case 'F':
cout<<"Friday";
break;
case 'G':
cout<<"Saturday";
break;
default:
cout<<"No match case";
}

47. TO SHOW THE USE OF GOTO :-

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
char c;
x:
cout<<"Enter the value of a";
cin>>a;
cout<<"Enter the value of b";
cin>>b;
a=a+b;
cout<<"\n\Do you want to continue Y/N";
cin>>c;
if(c=='y'||c=='Y')
goto x;
getch();
}

48. TO DECLARE & DEFINE THE FUNCTIONS WITH NO


ARGUMENTS AND NO RETURN VALUES.

#include<iostream.h>
#include<conio.h>
void add()
{
int a,b;
cout<<"Enter the value of a & b";
cin>>a>>b;
cout<<a+b<<endl;
}
void getdata()
{
int a,i;
cout<<"Enter the value of a";
cin>>a;
for(i=1;i<=10;i++)
{
cout<<a*i<<endl;
}
}
void put()
{
int a;
cout<<"Enter the value of a";
cin>>a;
if(a%2==0)
{
cout<<"Even no."<<endl;
}
else
{
cout<<"Odd n."<<endl;
}
}
void main()
{
put();
getdata();
add();
getch();
}

49. USE OF SWICTH CASE WITH FUNCTIONS HAVING NO


ARGUMENTS AND RETURN VALUE.

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void add()
{
int a,b;
cout<<"Enter the value of a & b";
cin>>a>>b;
cout<<a+b<<endl;
}
void getdata()
{
int a,i;
cout<<"Enter the value of a";
cin>>a;
for(i=1;i<=10;i++)
{
cout<<a*i<<endl;
}
}
void put()
{
int a;
cout<<"Enter the value of a";
cin>>a;
if(a%2==0)
{
cout<<"Even no."<<endl;
}
else
{
cout<<"Odd n."<<endl;
}
}
void main()
{
int z=0;
clrscr();
while (z<5)
{
cout<<"1 add \n 2 getdata \n 3 put \n 4 exit \n";
cout<<"Enter the choice ";
cin>>z;
switch(z)
{
case 1:
add();
break;
case 2:
getdata();
break;
case 3:
put();
break;
case 4:
exit(0);
}
getch();
}
}
50. DECLARE & DEFINE FUNCTION WITH ARGUMENTS AND NO
RETURN VALUE.

#include<iostream.h>
#include<conio.h>
sum (int x,int y);
void main ()
{
int a,b;
cout<<"Enter the value of a & b";
cin>>a>>b;
sum (a,b);
getch();
}
sum (int x, int y)
{
int p = x+y;
cout<<p;
}

51. DECLARE & DEFINE FUNCTION WITH ARGUMENTS AND


RETURN VALUE.
#include<iostream.h>
#include<conio.h>
sum(int x,int y);
void main ()
{
int a,b;
cout<<"Enter the value of a & b";
cin>>a>>b;
sum(a,b);
cout<<sum(a,b);
}
sum(int x,int y)
{
int p = x+y;
return(p);
}

52. CALLING OF A FUNCTION WITHIN ANOTHER FUNCTION.

#include<iotream.h>
#include<conio.h>
sum(int x,int y);
sub(int x,int y);
mul(int x,int y);
div(int x,int y);
void main()
{
clrscr();
int a,b,c;
cout<<"Enter the value of a & b";
cin>>a>>b;
c=sum(a,b);
cout<<"Sum="<<c<<endl;
getch();
}
sum(int x,int y)
{
int d,e=x+y;
d=sub(x,y)
cout<<"Sub="<<d<<endl;
return(e);
}
sub(int x,int y)
{
int f,g=x-y;
f=mul(x,y);
cout<<"Mul="<<f<<endl;
return(g);
}
mul(int x,int y)
{
int h,i=x*y;
h=div(x,y);
cout<<"Div="<<h<<endl;
retun(i);
}
div(int x,int y)
{
int j=x/y;
return(j);
}

53. USE OF ONE DIMENSIONAL ARRAY.

#include<iostream.h>
#include<conio.h>
int a[5],i;
for (i=0;i<=4;i++)
{
cout<<”Enter the elements”;
cin>>a[i];
}
for (i=0;i<=4;i++)
{
cout<<a[i]<<endl;
}
getch();
}
54. REVERSE THE ORDER WITH THE HELP OF ARRAYS.

#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],i;
for (i=0;i<=4;i++)
{
cout<<"Enter the elements";
cin>>a[i];
}
for (i=4;i>=0;i--)
{
cout<<a[i]<<endl;
}
getch();
}

55. TO FIND THE SUM OF ARRAYS.

#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],i,sum=0;
for (i=0;i<=4;i++)
{
cout<<"Enter the elements";
cin>>a[i];
}
for (i=0;i<=4;i++)
{
sum=sum+a[i];
}
cout<<sum;
getch();
}

56. TO FIND EVEN AND ODD WITH THE HELP OF ARRAYS.

#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],i;
for (i=0;i<=4;i++)
{
cout<<"Enter the elements";
cin>>a[i];
}
for (i=0;i<=4;i++)
{
if(a[i]%2==0)
{
cout<<"Even no."<<a[i]<<endl;
}
else
{
cout<<"Odd no."<<a[i]<<endl;
}
}
getch();
}
57. SORT THE ORDER WITH THE HELP OF ARRAYS.

#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],i,j,k;
for (i=0;i<=4;i++)
{
cout<<"Enter the elements";
cin>>a[i];
}
for (i=0;i<=4;i++)
{
for (j=i;j<=4;j++)
{
if(a[i]>a[j])
{
k=a[i];
a[i]=a[j];
a[j]=k
}
}
}
for (i=0;i<=4;i++)
{
cout<<a[i]<<endl;
}
getch();
}
58. SHOW THE USE OF TWO DIMENSIONAL ARRAYS.

#include<iostream.h>
#include<conio.h>
void main()
{
int a[3][3],i,j;
for (i=0;i<3;i++)
{
for (j=0;j<3;j++)
{
cin>>a[i][j];
}
}
for (i=0;i<3;i++)
{
for (j=0;j<3;j++)
{
cout<<a[i][j]<<endl;
}
}
getch();
}

59. SHOW THE USE OF STRING IN ONE DIMENSIONAL ARRAY.

#include<iostream.h>
#include<conio.h>
void main()
{
char name[10];
cout<<"Enter the name";
cin>>name;
cout<<name;
getch();
}

60. SHOW THE USE OF STRINGS IN TWO DIMENSIONAL ARRAYS.

#include<iostream.h>
#include<conio.h>
void main()
{
char name[5][10];
int i;
for(i=0;i<5;i++)
{
cout<<"Enter the name";
cin>>name[i];
}
for(i=0;i<5;i++)
{
cout<<name[i]<<endl;
}
getch();
}

61. SHOW THE USE OF STRING LENGTH FUNCTION.

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char name[10];
int l;
cout<<"Enter the name";
cin>>name;
l = str len(name);
cout<<l;
getch();
}

62. SHOW THE USE OF STRING COPY FUNCTION.

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char z[10],y[10];
cout<<"Enter the string of z";
cin>>z;
str cpy(y,z);
cout<<y;
getch();
}

63. COMPARE TO FUNCTIONS WITH THE HELP OF STRING


COMPARE FUNCTION.

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char z[10],y[10];
cout<<"Enter the string of z";
cin>>z;
cout<<"Enter the string of y";
cin>>y;
if(str cmp(z,y)==0)
cout<<"String is equal";
else
cout<<"String is not equal";
getch();
}

64. SHOW THE USE OF STRING REVERSE FUNCTION.

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char z[10];
int *p;
cout<<"Enter the name";
cin>>z;
p =str rev(z)
cout<<p;
getch();
}

65. SHOW THE USE OF STRING CONCATENATION FUNCTION.

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char z[10],y[10],p[20];
int *p;
cout<<"Enter the string of z";
cin>>z;
cout<<"Enter the string of y";
cin>>y;
str cat(p,z)
str cat(p,y)
cout<<p;
getch();
}

66. USE OF POINTER.

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
int a=10,*p,z;
p = &a;
z = *p;
*p = 40;
cout<<"a="<<a<<endl;
cout<<"*p="<<*p<<endl;
cout<<"z="<<z;
getch();
}

67. POINTER TO POINTER VARIABLE.

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
int a=20,*p,z,**p1;
p = &a;
z = *p;
p1 = &p;
**p1 = 50;
cout<<"a="<<a<<endl;
cout<<"z="<<z<<endl;
cout<<"*p="<<*p<<endl;
cout<<"**p="<<**p<<endl;
getch();
}

68. CALL BY REFERENCE.

#include<iostream.h>
#include<conio.h>
swap(int x,int y);
void main()
{
int a,b;
cout<<"Enter the value of a";
cin>>a;
cout<<"Enter the value of b";
cin>>b;
swap(&a , &b)
getch();
}
swap(int *x,int *y)
{
int p = *x;
*x = *y;
*y = p;
cout<<"*x="<<*x<<endl;
cout<<"*y="<<*y<<endl;
}

69. TO DEFINE A STRUCTURE.

#include<iostream.h>
#include<conio.h>
void main()
{
struct emp
{
int code;
char name[10];
}e;
cout<<"Enter the emp code";
cin>>e.code;
cout<<"Enter the emp name";
cin>>e.name;
cout<<"Emp code="<<code<<endl;
cout<<"Emp name="<<name<<endl;
getch();
}

70. SHOW ARRAY OF A STRUCTURE.

#include<iostream.h>
#include<conio.h>
void main()
{
struct emp
{
int code;
char name[10];
}e[5];
int i;
for(i=0;i<5;i++)
{
cout<<"Enter the emp code";
cin>>e.code;
cout<<"Enter the emp name";
cin>>e.name;
}
for(i=0;i<5;i++)
{
cout<<"Emp code="<<e[i].code<<endl;
cout<<"Emp name="<<e[i].name<<endl;
}
getch();
}
71. SHOW ARRAY OF POINTERS.

#include<iostream.h>
#include<conio.h>
void main()
{
int a=10, b=20, c=30, d=40, e=50;
int *ar[5],i;
ar[0] = &a;
ar[1] = &b;
ar[2] = &c;
ar[3] = &d;
ar[4] = &e;
for(i=0;i<=4;i++)
{
cout<<"Value="<<*ar[i]<<"Add="<<ar[i]<<endl;
}
getch();
}

72. TO DEFINE A STRUCTURE WITHIN ANOTHER STRUCTURE.

#include<iostream.h>
#include<conio.h>
void main()
{
struct emp
{
int code;
char name[10];
};
struct student
int roll no.,
char name[10];
struct emp e;
}s;
cout<<"Enter the student roll no.";
cin>>s.roll no.;
cout<<"Enter the student name";
cin>>s.name;
cout<<"Enter the emp code";
cin<<s.e.code;
cout<<"Enter the emp name";
cin>>s.e.name;
cout<<"St. Rollno.="<<s.roll no.<<endl;
cout<<"St. Name="<<s.name<<endl;
cout<<"Emp Code="<<s.e.code<<endl;
cout<<"Emp Name="<<s.e.name<<endl;
getch();
}

73. TO DEFINE A STRUCTURE WITH THE USE OF ARRAYS.

#include<iostream.h>
#include<conio.h>
void main()
{
struct emp
{
int code;
char name[10];
};
struct student
int roll no.,
char name[10];
struct emp e;
}s[5];
int i;
for(i=0;i<5;i++)
{
cout<<"Enter the student roll no.";
cin>>s.roll no.;
cout<<"Enter the student name";
cin>>s.name;
cout<<"Enter the emp code";
cin<<s.e.code;
cout<<"Enter the emp name";
cin>>s.e.name;
}
for(i=0;i<5;i++)
{
cout<<"St. Rollno.="<<s.roll no.<<endl;
cout<<"St. Name="<<s.name<<endl;
cout<<"Emp Code="<<s.e.code<<endl;
cout<<"Emp Name="<<s.e.name<<endl;
}
getch();
}

74.TO DECLARE A CLASS.

#include<iostream.h>
#include<conio.h>
class emp
{
int code;
char name[10];
public:
void getdata()
{
cout<<"Enter the emp code";
cin<<code;
cout<<"Enter the emp name";
cin>>name;
}
void put()
{
cout<<"Emp Code="<<code<<endl;
cout<<"Emp Name="<<name<<endl;
}
};
void main()
{
emp e;
e.getdata();
e.put();
getch();
}

75. TO DECLARE A WITH THE HELP OF ARRAY.

#include<iostream.h>
#include<conio.h>
class emp
{
int code;
char name[10];
public:
void getdata()
{
cout<<"Enter the emp code";
cin<<code;
cout<<"Enter the emp name";
cin>>name;
}
void put()
{
cout<<"Emp Code="<<code<<endl;
cout<<"Emp Name="<<name<<endl;
}
};
void main()
{
emp e[5];
int i;
for(i=0;i>5;i++)
{
e[i].getdata();
}
for(i=0;i>5;i++)
{
e[i].put();
}
getch();s
}

76. TO PASS THE VALUE TO THE OBJECT.

#include<iostream.h>
#include<conio.h>
#include<string.h>
class emp
{
int code;
char name[10];
public:
void add(int x, char *p)
{
code = x;
str cpy (name,p)
}
void show()
{
cout<<"Emp Code="<<code<<endl;
cout<<"Emp Name="<<name<<endl;
}
};
void main()
{
emp e;
e.add(10,"Rahul");
e.show();
getch();
}

77. TO CREATE A CONSTRUCTOR.

#include<iostream.h>
#include<conio.h>
class A
{
int a;
public:
A()
{
a=10;
}
void show()
{
cout<<a*a;
}
};
void main()
{
A a2;
a2.show();
getch();
}

78. TO CREATE A CONSTRUCTOR WITH THE ARGUMENT.

#include<iostream.h>
#include<conio.h>
class A
{
int a;
public:
A(int x)
{
a= x;
}
void show()
{
cout<<a*a;
}
};
void main()
{
A a2(10);
a2.show();
getch();
}

79. TO CREATE A DESTRUCTOR.

#include<iostream.h>
#include<conio.h>
class A
{
int a;
public:
A(int x)
{
a= x;
}
void show()
{
cout<<a*a;
}
~A
{
cout<<"Destroy";
}
};
void main()
{
A a2(10);
a2.show();
getch();
}
80. TO CREATE A FRIEND FUNCTION.

#include<iostream.h>
#include<conio.h>
class B;
class A
{
int a;
public:
A()
{
a=10;
}
void friend show(A,B);
};
class B
{
int z;
public:
B()
{
z=20;
}
void friend show(A,B);
};
void show(A a2, B b2)
{
cout<<A.a2+B.b2;
}
void main()
{
A a3;
B b3;
show(a3,b3);
getch();
}

81. TO CREATE A FUNCTION MEMBER OVERLOADING.


#include<iostream.h>
#include<conio.h>
class A
{
public:
void add()
{
cout<<"Rahul"<<endl;
}
void add(int x)
{
cout<<x<<endl;
}
void add(int x, int y)
{
cout<<x+y;
}
};
void main()
{
A a2;
a2.add();
a2.add(10);
a2.add(10,20);
getch();
}

82. TO CREATE A CONSTRUCTOR OVERLOADING WITH


ARGUMENTS.

#include<iostream.h>
#include<conio.h>
class A
{
public:
A (char *p)
{
cout<<p<<endl;
}
A(int x)
{
cout<<x<<endl;
}
A (int x, int y)
{
cout<<x+y;
}
};
void main()
{
A a2("Rahul");
A a3(10);
A a4(10,20);
getch();
}

83. TO CREATE A CONSTRUCTOR OVERLOADING WITHOUT


ARGUMENTS.

#include<iostream.h>
#include<conio.h>
class A
{
public:
A (char *p)
{
cout<<p<<endl;
}
A(int x)
{
cout<<x<<endl;
}
A (int x, int y)
{
cout<<x+y;
}
};
void main()
{
A a2;
A a3(10);
A a4(10,20);
getch();
}

84. TO CREATE A OPERATOR OVERLOADING.

#include<iostream.h>
#include<conio.h>
class A
{
public:
int a;
A()
{
a = 10;
}
void operator ++()
{
a++;
}
void show()
{
cout<<a;
}
void operator ++(int x)
{
cout<<x * x;
}
void main()
{
A a2;
++ a2;
a2.show();
a2.operator ++(20);
getch();
}

85. TO CREATE A STATIC DATA MEMBERS.


#include<iostream.h>
#include<conio.h>
class A
{
static int a;
public:
void add()
{
a++;
}
void show()
{
cout<<a<<endl;
}
};
int A :: a;
void main()
{
A a2,a3,a4;
a2.show();
a3.add();
a4.add();
a4.show();
getch();
}

86. TO CREATE A SINGLE-LEVEL INHERITANCE.

#include<iostream.h>
#include<conio.h>
class A
{
public:
void show()
{
cout<<"Class A"<<endl;
}
};
class B: class A
{
public:
void put()
{
cout<<”Class B”;
}
};
void main()
{
B b2;
b2.show();
b2.put();
getch();
}

87. TO CREATE A MULTI-LEVEL INHERITANCE.

#include<iostream.h>
#include<conio.h>
class A
{
public:
void show()
{
cout<<"Class A"<<endl;
}
};
class B: class A
{
public:
void show1()
{
cout<<”Class B”<<endl;
}
};
class C : public B
{
public:
void show2()
{
cout<<”Class C”;
}
};
void main()
{
C e;
e.show();
e.show1();
e.show2();
getch();
}

88. TO CREATE A MULTIPLE-LEVEL INHERITANCE.

#include<iostream.h>
#include<conio.h>
class A
{
public:
void show()
{
cout<<"Class A"<<endl;
}
};
class B
{
public:
void show1()
{
cout<<”Class B”<<endl;
}
};
class C : public A, public B
{
public:
void show2()
{
cout<<”Class C”;
}
};
void main()
{
C e;
e.show();
e.show1();
e.show2();
getch();
}
89. TO CREATE A HYBRID INHERITANCE.

#include<iostream.h>
#include<conio.h>
class A
{
public:
void show()
{
cout<<"Class A"<<endl;
}
};
class B: class A
{
public:
void get()
{
cout<<”Class B”<<endl;
}
};
class C : public A
{
public:
void put()
{
cout<<”Class C”<<endl;
}
};
void main()
{
B b2;
C c1;
b2.show();
b2.get();
c2.put();
getch();
}
90. TO CREATE A HIERARCHIAL INHERITANCE.

#include<iostream.h>
#include<conio.h>
class A
{
int a;
public:
void add()
{
cout<<"Enter the value of a”;
cin>>a;
}
};
void sum()
{
cout<<a + a;
}
};
class B : virtual public A
{
protected:
float a,b;
public:
void put()
{
cout <<"Enter the value of a & b”;
cin>>a>>b;
}
};
class C : public virtual A
{
protected:
float p;
public:
void getdata()
{
cout <<"Enter the value of p”;
cin>>p;
}
};
class D: public B , public C
{
int total;
public:
void display()
{
total=a+b+p;
cout<<total<<endl;
}
};
void main()
{
D dl;
dl.add();
dl.sum();
dl.put();
dl.getdata();
d1.display();
getch();
}

91. TO SHOW POLYMORPHISM.

#include<iostream.h>
#include<conio.h>
class A
{
public:
void virtual show()
{
cout<<"class A”<<endl;
}
};
class B : public A
{
public:
void show()
{
cout <<"class B”<<endl;
}
};
class C : public A
{
public:
void show ()
{
cout <<"class C ”<<endl;
}
};
void main()
{
A *p;
B b1;
C c1;
p = &b1
p → show();
p = &c1;
p → show();
getch();
}

92. TO CREATE A PURE VIRTUAL FUNCTION.

#include<iostream.h>
#include<conio.h>
class A
{
public:
void virtual show() = 0;
};
class B : public A
{
public:
void show()
{
cout <<"class B”<<endl;
}
};
class C : public A
{
public:
void show ()
{
cout <<"class C ”<<endl;
}
};
void main()
{
A *p;
B b1;
C c1;
p = &b1
p → show();
p = &c1;
p → show();
getch();
}

93. TO SHOW THE USE OF GET().

#include<iostream.h>
#include<conio.h>
void main()
{
char a;
cout<<”Enter the char of a”;
cin.get(a);
cout<<a;
getch();
}

94. TO SHOW THE USE OF PUT().

#include<iostream.h>
#include<conio.h>
void main()
{
char a = ‘z’;
cin.get(a);
cout<<a;
cout.put(a);
getch();
}
95. TO SHOW THE USE OF GETLINE().

#include<iostream.h>
#include<conio.h>
void main()
{
char name[10];
cout<<”Enter the name”;
cin.getline(name,10);
cout<<name;
getch();
}

96. TO SHOW THE USE OF WRITE().

#include<iostream.h>
#include<conio.h>
void main()
{
char name[10] = “RAHUL”;
cout.write(name,10);
getch();
}

You might also like