Sie sind auf Seite 1von 96

****************** C++ PROGRAMS ****************

===========================================================================
------------------------- SIMPLE C PROGRAM ------------------------------#include<stdio.h>
#include<conio.h>
void main()
{
float a;
clrscr();
a=50;
printf("the value of a is:%f",a);
getch();
}
======================================================================
#include<stdio.h>
#include<conio.h>
void main ()
{
clrscr ();
printf("\n division operation
Results " );
printf("\n two integers (5 &2)
: %d ", 5/2);
printf("\n one int & one float (5.5 & 2) : %g ", 5.5/2);
printf("\n two integers (5 & 2)
: %g ",(float)5/2);
getch;
}
======================================================================
******************************* C++ PROGRAM **************************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" hello india \n how r u ";
cout<<"\n GOOD MORNING INDIA ";
getch();
}
=======================================================================
************************** STORE VALUE IN A VARIABLE ******************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
a=49;
cout<<"value of a is :
"<<a;
getch();
}
======================================================================
*********** A VARIBLE STORE ONLY SINGLE VALUE AT A TIME **************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
a=49;
a=56;
a=80;
cout<<"value of a is :
"<<a;
getch();
}
======================================================================

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
a=49;
a=56;
a=80;
cout<<"value of a is :
"<<a<<endl;
cout<<" value of a is :
"<<a<<endl;
cout<<" value of a is :
"<<a<<endl;
getch();
}
==================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
a=49;
cout<<" value of a is :
"<<a<<endl;
a=60;
cout<<" value of a is :
"<<a<<endl;
a=79;
cout<<" value of a is :
"<<a<<endl;
getch();
}
=================================================================
*********** SWAP VALUE FROM ONE VARIABLE TO ANOTHER **********
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a ,b ,c ,d;
a=49;
b=86;
c=89;
d=101;
a=b;
b=c;
c=a;
d=c;
cout<<" value of a is
: "<<a<<endl ;
cout<<" value of b is
: "<<b<<endl ;
cout<<" value of c is
: "<<c<<endl;
cout<<" value of d is
: "<<d<<endl;
getch();
}
=================================================================

// sum of two numbers.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a ,b ;
a=15;
b=18;
cout<<"sum of a and b is
:
"<<a+b;
getch();
}
=============================================================

// sum of two numbers.


#include<iostream.h>
#include<conio.h>
void main()
{
int a ,b ,sum;
cout<<" pl'z enter the value of first number
: ";
cin>>a;
cout<<"\n pl'z enter the value of 2nd number
: ";
cin>>b;
sum=a+b;
cout<<"\n \t\t sum of a and b is
:
"<<sum;
}
======================================================================

// SUM OF TWO NUMBERS


#include"iostream.h"
#include"conio.h"
void main()
{
clrscr();
int a,b,s ;
textcolor(GREEN);
textbackground(YELLOW);
cout<<"\n\n\t\t Program of Sum of Two Numbers "<<endl;
cout<<"\n\n\t\t\t pl'z enter to start ";
getch();
cout<<"\n\n\t pl'z enter the value of A : ";
cin>>a;
cout<<"\n\t pl'z enter the value of B : ";
cin>>b;
clrscr();
s=a+b;
cout<<"\n\n\t\t pl'z press enter to see the value of A ";
getch();
textcolor(RED);
textbackground(GREEN);
cout<<"\n\n\t\t Value of A is : "<<a<<endl;
cout<<"\n\n\t\t pl'z press enter to see the value of B ";
getch();
cout<<"\n\n\t\t Value of B is : "<<b<<endl;
cout<<"\n\n\t\t pl'z press enter, this time i will tell you the sum of A & B ";
getch();
clrscr();
cout<<"\n\t\t\a\a sum of two number is : "<<s;
getch();
}
==========================================================================
************************** IF & ELSE PROGRAM *************************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
cout<<"pl'z enter the number ";
cin>>a;
if(a%2==0)
{
cout<<" number is even ";
}
else
{
cout<<" number is odd ";
}
getch();

}
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int year;
cout<<"pl'z enter the year ";
cin>>year;
if(year%4==0)
{
cout<<" this is a leap year ";
}
else
{
cout<<" this is not a leap year ";
}
getch();
}
====================================================================
********************* GRETAER BETWEEN TWO NUMBER *******************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"pl'z enter the value of a : ";
cin>>a;
cout<<"pl'z enter the value of b : ";
cin>>b;
if(a>b)
{
cout<<" a is greater ";
}
else if(b>a)
{
cout<<" b is greater ";
}
else
{
cout<<"both are equal ";
}
getch();
}
==================================================================
**************************** VOWEL LETTERS ***********************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char w;
cout<<"pl'z enter the letter : ";
cin>>w;
if(w=='a' || w=='e' || w=='i' || w=='o' || w=='u')
{
cout<<" it is vowel letter ";
}
else
{
cout<<" it is not a vowel letter ";
}
getch();
}

=================================================================
**************************** GREATER FROM THREE NUMBERS ********************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"pl'z enter the value of a :
cin>>a;
cout<<"pl'z enter the value of b :
cin>>b;
cout<<"pl'z enter the value of c :
cin>>c;
if(a>b && a>c)
{
cout<<" a is greater ";
}
else if(b>a && b>c)
{
cout<<" b is greater ";
}
else if (c>a && c>b)
{
cout<<"c is greater ";
}
else if (a==b && a==c )
{
cout<<" all numbers are equal ";
}
else if (a==b && c<a)
{
cout<<" a and b are equal ";
}
else if (b==c && a<b)
{
cout<<"b and c are equal ";
}
else if (a==c && b<c)
{
cout<<"a and c are equal ";
}
getch();
}

";
";
";

====================================================================
************************** CONDITIONAL OPERATOR *******************
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
clrscr();
cout<<" Enter any number= ";
cin>>a;
a=(a%2==0) ? (a+=5) : (a=a+20);
cout<<" value of a is "<<a;
getch();
}
===================================================================

************************* TO FIND DATS IN A MONTH ******************


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int month;
cout<<"pl'z enter the number of month(1-12) : ";
cin>>month;
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{
cout<<" this month contains 31 days ";
}
else if (month==4||month==6||month==9||month==11)
{
cout<<"this month contains 30 days ";
}
else if (month==2)
{
cout<<" this month contains 28 or 29 days depends upon leap year ";
}
else
{
cout<<" there are only 12 months in a year ";
}
getch();
}
====================================================================
****************************** ARRAY ******************************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[3];
cout<<"pl'z enter the first number : ";
cin>>a[0];
cout<<"pl'z enter the 2nd number : ";
cin>>a[1];
cout<<"pl'z enter the 3rd number : ";
cin>>a[2];
int sum=a[0]+a[1]+a[2];
cout<<"sum of three number is : "<<sum;
getch();
}
===============================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10]={45,65,98,45,68,75,95,62,25,10};
for(int i=0;i<=9;i++)
{
cout<<"number is
: "<<a[i]<<endl;
}
getch();
}
==============================================================

==============================================================
--------------------------- use of char* --------------------#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char* a;
a="Atika";
cout<<endl<<a;
getch();
}
==============================================================
************************** Array *****************************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char a[6]={'a','t','i','k','a'};
cout<<endl<<a;
getch();
}
===============================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[4]={45,62,75,85};
cout<<"first value is : "<<a[0]<<endl;
cout<<"second value is : "<<a[1]<<endl;
cout<<"third value is : "<<a[2]<<endl;
cout<<"forth value is : "<<a[3]<<endl;
getch();
}
==============================================================
******************* sum using Arrays ************************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[3],s;
cout<< " enter first number ";
cin>>a[0];
cout<<"enter second number ";
cin>>a[1];
cout<<"enter third number ";
cin>>a[2];
s=a[0]+a[1]+a[2];
cout<<"sum of three number is :"<<s;
getch();
}
=============================================================

**************************** using Array ********************


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10],i;
for(i=0;i<=9;i++)
{
cout<< " enter marks of student "<<i+1<<" is : ";
cin>>a[i];
}
for(i=0;i<=9;i++)
{
cout<<"marks of student "<<i+1<<" is : "<<a[i]<<endl;
}
getch();
}
============================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char a[6];
cout<<"pl'z enter the name : ";
cin>>a;
cout<<endl<<"the name of student is : "<<a;
getch();
}
=============================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[]={15,12,52,16,14,82,56,42,45,20};
for(int i=0 ; i<=9;i++)
{
cout<<a[i]<<endl;
}
getch();
}
==============================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10],i;
for(i=0 ;i<=9;i++)
{
cout<<"pl'z enter the marks : ";
cin>>a[i];
}
for(i=0;i<=9;i++)
{
cout<<"marks is
: "<<a[i]<<endl;
}
getch();
}

===============================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[3];
cout<<"pl'z enter the first number : ";
cin>>a[0];
cout<<"pl'z enter the second number : ";
cin>>a[1];
cout<<"pl'z enter the third number : ";
cin>>a[2];
int sum=a[0]+a[1]+a[2];
cout<<"sum of three number is : "<<sum;
getch();
}
================================================================
*********************** LOOPS **********************************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
for(a=0;a<=10;a++)
{
cout<<"
"<<a<<endl;
}
getch();
}
===================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
for(a=0;a<=50;a=a+3)
{
cout<<"
"<<a<<endl<<endl;
}
}
====================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
char a;
for(a='A';a<='Z';a++)
{
cout<<"
"<<a<<endl<<endl;
}
}
===================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
char a;
for(a='a';a<='z';a=a+3)
{
cout<<"
"<<a<<endl<<endl;
}
getch();
}

=====================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char a;
for(a='a';a<='z';a=a+2)
{
cout<<a<<endl;
}
getch();
}
===============================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++)
{
cout<<" * ";
}
cout<<" "<<endl;
}
getch();
}
===============================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
for(a=10;a>=1;a--)
{
for(b=1;b<=a;b++)
{
cout<<" * ";
}
cout<<" "<<endl;
}
getch();
}
===============================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
for(a=1;a<=10;a++)
{
for(b=1;b<=a;b++)
{
cout<<" * ";
}
cout<<endl;
}
getch();
}

================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
for(a=1;a<=10;a++)
{
for(b=1;b<=a;b++)
{
cout<<" "<<b;
}
cout<<endl;
}
getch();
}
================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b;
for(a=10;a>=1;a--)
{
for(b=1;b<=a;b++)
{
cout<<" * ";
}
cout<<endl;
}
getch();
}
================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b;
for(a=10;a>=1;a--)
{
for(b=1;b<=a;b++)
{
cout<<" * ";
}
cout<<" "<<endl;
}
}
=============================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num;
cout<<"enter the number :
";
cin>>num;
for(int i=1;i<=num/2;i++)
{
if(num%i==0)
cout<<i<<endl;
}
getch();

}
============================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[3], sum;
for(int i=0 ;i<=2;i++)
{
cout<<"pl'z enter number : ";
cin>>a[i] ;
}
sum=a[0]+a[1]+a[2];
cout<<"\n sum of three number is "<<sum;
getch();
}
==========================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10];
for(int i =0 ;i<=9 ;i++)
{
cout<<"pl'z enter marks : ";
cin>>a[i];
}
for(i=0;i<=9;i++)
{
cout<<"\n marks of student is "<<a[i];
}
getch();
}
=================================================================
************************* POWER *********************************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
int b;
int c;
unsigned int d=1;
cout<<"pl'z enter the number ";
cin>>a;
cout<<"\n pl'z enter the power ";
cin>>b;
for(c=1;c<=b;c++)
{
d=d*a;
cout<<"\n when c = "<<c;
cout<<"\n answer is : "<<d;
}
getch();
}
==================================================================
************************* power *********************************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;

int b;
int c;
unsigned int d=1;
cout<<"pl'z enter the number ";
cin>>a;
cout<<"\n pl'z enter the power ";
cin>>b;
for(c=1;c<=b;c++)
{
d=d*a;
}
cout<<"\n answer is : "<<d;
getch();
}
===================================================================
********************* MEMBER FUNCTION *****************************
#include<iostream.h>
#include<conio.h>
int a,b;
void sum()
{
int s;
a=45;
b=65;
s=a+b;
cout<<"sum
}

is : "<<s;

void loop()
{
for(a=1;a<=10;a++)
{
cout<<a<<endl;
}
}
void main()
{
clrscr();
loop();
sum();
cout<<"\nthe calculation is over ";
getch();
}
=========================================================
#include<iostream.h>
#include<conio.h>
int a , b;
void sum()
{
int sum;
cout<<"\n now we add a and b ";
cout<<"\n pl'z enter the value of a :";
cin>>a;
cout<<" \n pl'z enter the value of b :";
cin>>b;
sum=a+b;
cout<<"\n sum of a and b is : "<<sum;
}
void minus()
{
int minus;
cout<<"\n now we subtract a and b

";

cout<<"\n pl'z enter the value of a :";


cin>>a;
cout<<" \n pl'z enter the value of b :";
cin>>b;
minus=a-b;
cout<<"\n minus of a and b is : "<<minus;
}
void multiply()
{
int mul;
cout<<"\n now we multiply a and b ";
cout<<"\n pl'z enter the value of a :";
cin>>a;
cout<<" \n pl'z enter the value of b :";
cin>>b;
mul=a*b;
cout<<"\n sum of a and b is : "<<mul;
}
void main()
{
clrscr();
sum();
multiply();
minus();
getch();
}
================================================================
************************ SWITCH CASE ***************************
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int week;
printf("pl'z enter the number of a week(1-7) : ");
scanf("%d" ,&week);
switch(week)
{
case 1 : printf("monday");
break;
case 2: printf("tuesday");
break;
case 3: printf("wednesday");
break;
case 4: printf("thursday");
break;
case 5: printf("friday");
break;
case 6: printf("saturday");
break;
case 7: printf("sunday");
break;
default:printf("wroung entry");
}
getch();
}
=============================================================
#include<iostream.h>
#include<conio.h>
void main()
{

clrscr();
int week;
cout<<" pl'z enter the number of day of a week(1-7)
cin>>week;
switch(week)
{
case 1: cout<<"monday";
break;
case 2: cout<<"tuesday ";
break;
case 3: cout<<"wednesday";
break;
case 4: cout<<"thursday";
break;
case 5: cout<<"friday ";
break;
case 6: cout<<"saturday";
break;
case 7:cout<<"sunday";
break;
default: cout<<" there r only 7 days in a week ";

";

}
getch();
}
================================================================
************************** MENU ********************************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int choice ,a ,b ,sum,multiply ,divide,remainder,subtract;
do
{
clrscr();
cout<<"\n\n\t AIRTHMETIC MENU FOR CALCULATION ";
cout<<"\n\n\t 1. SUM ";
cout<<"\n\n\t 2. MULTIPLY ";
cout<<"\n\n\t 3. DIVIDE ";
cout<<"\n\n\t 4. SUBTRACT ";
cout<<"\n\n\t 5. REMAINDER ";
cout<<"\n\n\t 6. EXIT ";
cout<<"\n\n\t PL'Z ENTER YOUR CHOICE(1-6) : ";
cin>>choice;
if(choice==1||choice==2||choice==3||choice==4||choice==5)
{
cout<<"\n\n pl'z enter first number : ";
cin>>a;
cout<<"\n\n pl'z enter 2nd number : ";
cin>>b;
}
switch(choice)
{
case 1 : sum=a+b;
cout<<"\n sum of two number is : "<<sum;
getch();
break;
case 2 : multiply =a*b;
cout<<"\n multiplication of two number is : "<<multiply;
getch();
break;
case 3 : divide=a/b;
cout<<"\n division of a and b is : "<<divide;
getch();

break;
case 4 : subtract= a-b;
cout<<"\n subtraction of a and b is : "<<subtract;
getch();
break;
case 5 : remainder=a%b;
cout<<"\n remainder of a and b is : "<<remainder;
getch();
break;
}
}
while(choice==1||choice==2||choice==3||choice==4||choice==5);
getch();
}
===============================================================
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int ch;
float l, b , area ,perimeter ,diagonal;
do
{
clrscr();
cout<<"\n\t\t\t Rectangle Menu ";
cout<<"\n\n\t\t\t 1) Area ";
cout<<"\n\n\t\t\t 2) perimeter ";
cout<<"\n\n\t\t\t 3) Diagonal ";
cout<<"\n\n\t\t\t 4) Exit. ";
cout<<"\n\n\n\t\t\t Pl'z enter your choice
:
";
cin>>ch;
if(ch==1 || ch==2 || ch==3)
{
cout<<"\n pl'z enter the length of a rectangle :
";
cin>>l;
cout<<" \n pl'z enter the breadth of a reactangle
: ";
cin>>b;
}
switch(ch)
{
case 1 : area=l*b;
cout<<"Area of a reactangle is
:
"<<area;
break;
case 2 : perimeter=2*(l+b);
cout<<"Perimeter of a reactangle is : "<<perimeter;
break ;
case 3 : diagonal =sqrt(l*l+b*b);
cout<<"diagonal of a reactangle is : "<<diagonal;
break;
}
getch();
}
while(ch==1 || ch==2 || ch==3);
getch();
}
=================================================================
#include<iostream.h>
#include<conio.h>
void main()
{

clrscr();
int choice ,a ,b;
cout<<"\n AIRTHMATIC OPERATIONS ARE USED FOR CALCULATION "<<endl;
cout<<" \n 1. TO FIND SUM"<<endl;
cout<<" \n 2. TO FIND PERCENTAGE "<<endl;
cout<<" \n 3. TO FIND NUMBER IS EVEN OR NOT "<<endl;
cout<<" \n 4. TO FIND FACTORIAL "<<endl;
cout<<" \n 5. TO FIND POWER "<<endl;
cout<<" \n 6. TO EXIT "<<endl;
cout<<" \n
PL'Z ENTER YOUR CHOICE (1-5) : ";
cin>>choice;
if (choice==1)
{
int sum;
cout<<"\n\n 1. TO FIND SUM "<<endl;
cout<<"\n\n pl'z enter the value of a : ";
cin>>a;
cout<<"\n pl'z enter the value of b : ";
cin>>b;
sum=a+b;
cout<<"
\n
sum of a and b is :
"<<sum;
}
else if(choice==2)
{
int hindi, math ,phy,chem,eng,total;
float percentage;
cout<<" \n\n 2. TO FIND PERCENTAGE "<<endl;
cout<<"\n pl'z enter the marks of hindi : ";
cin>>hindi;
cout<<"\n pl'z enter the marks of math : ";
cin>>math;
cout<<"\n pl'z enter the marks of physics : ";
cin>>phy;
cout<<"\n pl'z enter the marks of chemistry : ";
cin>>chem;
cout<<"\n pl'z enter the marks of english : ";
cin>>eng;
total=hindi+math+phy+chem+eng;
percentage=total/5;
cout<<"\n PERCENTAGE IS
:
"<<percentage;
}
else if(choice==3)
{
cout<<"\n\n 3. TO FIND NUMBER IS EVEN OR NOT ";
cout<<"\n\n\t pl'z enter the number ";
cin>>a;
if(a%2==0)
{
cout<<" \n\t the number is even ";
}
else
{
cout<<"\n\t the number is not even ";
}
}
else if(choice==4)
{
cout<<" \n\n 4. TO FIND FACTORIAL ";
int c=1;
cout<<" \n\n pl'z enter the number : ";
cin>>a;
for(b=1;b<=a;b++)
{
c=c*b;
}

cout<<"\n\n \t\t\t\t factorial is

"<<c;

}
else if(choice==5)
{
cout<<"\n\n 5. TO FIND POWER ";
int c;
unsigned int d=1;
cout<<"\n\n pl'z enter the number ";
cin>>a;
cout<<"\n pl'z enter the power ";
cin>>b;
for(c=1;c<=b;c++)
{
d=d*a;
}
cout<<"\n \n \t POWER IS : "<<d;
}
getch();
}
====================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"EVEN NUMBER
int a=1;
for(a;a<=20;a++)
{
if(a%2==0)
cout<<" "<<endl<<a<<endl;
else
{
cout<<"\n
}

ODD NUMBER "<<endl;

"<<a<<endl;

}
getch();
}
=====================================================================================
# include<iostream.h>
# include<conio.h>
#include<math.h>
void main()
{
clrscr();
char ch;
float l, b , area ,perimeter ,diagonal;
do
{
clrscr();
cout<<"\n\t\t\t Rectangle Menu ";
cout<<"\n\n\t\t\t 1) Area ";
cout<<"\n\n\t\t\t 2) perimeter ";
cout<<"\n\n\t\t\t 3) Diagonal ";
cout<<"\n\n\t\t\t 4) Exit. ";
cout<<"\n\n\n\t\t\t Pl'z enter your choice
:
cin>>ch;
if(ch=='1' || ch=='2' || ch=='3')
{
cout<<"\n pl'z enter the length of a rectangle

";

";

cin>>l;
cout<<" \n pl'z enter the breadth of a reactangle
: ";
cin>>b;
}
switch(ch)
{
case '1' : area=l*b;
cout<<"Area of a reactangle is
:
"<<area;
getch();
break;
case '2' : perimeter=2*(l+b);
cout<<"Perimeter of a reactangle is : "<<perimeter;
getch();
break ;
case '3' : diagonal =sqrt(l*l+b*b);
cout<<"diagonal of a reactangle is : "<<diagonal;
getch();
break;
default : cout<< " wrong entry dear ";
}
}
while(ch=='1' || ch=='2' || ch=='3');
getch();
}
=============================================================================
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int ch,l,b,area,perimeter,diagonal;
do
{
cout<<"\n\n\t\t\t Rectangle menu ";
cout<<"\n\n\t\t\t 1. Area ";
cout<<"\n\n\t\t\t 2. Perimeter ";
cout<<"\n\n\t\t\t 3. Diagonal ";
cout<<"\n\n\t\t\t 4. Exit ";
cout<<"\n\n\t\t\t pl'z enter your choice
:
";
cin>>ch;
if(ch==1||ch==2||ch==3)
{
cout<<"\n\n\t\t\t pl'z enter the length : ";
cin>>l;
cout<<"\n\n\t\t\t pl'z enter the breadth : ";
cin>>b;
}
switch(ch)
{
case 1 : area=l*b;
cout<<"\n\n\t\t\t Area of Reactangle is : "<<area;
cout<<"\n\t\t======================================================="<<endl;
break;
case 2 : perimeter=2*(l+b);
cout<<"\n\n\t\t\t Perimeter of Reactangle is : "<<perimeter;
cout<<"\n\t\t======================================================="<<endl;
break;
case 3 : diagonal=sqrt(l*l+b*b);
cout<<"\n\n\t\t\t Diagonal of Reactangle is : "<<diagonal;
cout<<"\n\t\t======================================================="<<endl;
}

}
while(ch==1||ch==2||ch==3);
getch();
}
=================================================================================
// Star Reverse
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
for(a=1;a<=10;a++)
{
for(b=10;b>=a;b--)
{
cout<<"

";

}
for(c=1;c<=a;c++)
{
cout<< " " <<c;
}
cout<<endl;
}
getch();
}
====================================================================
// Star Square
#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int a,b,c,n;
for(n=1;n<10;)
{
c=0+1;
n++ ;
45;lg
:
b=c+n;
getch();
cout<<b;
}
getch();
}
====================================================================
*************************** POWER **********************************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d=1;
cout<<"pl'z enter the number :
cin>>a;
cout<<"pl'z enter the power
cin>>b;

";
";

for(c=1;c<=b;c++)
{
d=a*d;
}
cout<<" answer is :

"<<d<<endl;

getch();
}
==================================================================
************************* FACTORIAL ******************************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a , b ,c=1;
cout<<"pl'z enter the number : ";
cin>>a;
for(b=1;b<=a;b++)
{
c=c*b;
}
cout<<"\n factorial is : "<<c;
getch();
}
===================================================================
#include<iostream.h>
#include<conio.h>
int a ,b;
void sum()
{
int sum;
cout<<"\n here we add a and b :";
cout<<"\n pl'z enter value of a : ";
cin>>a;
cout<<"pl'z enter value of b : ";
cin>>b;
sum=a+b;
cout<<"sum of a and b is : "<<sum;
}
void minus()
{
int minus;
cout<<"\n now we subtract a and
cout<<"\n pl'z enter value of a
cin>>a;
cout<<"pl'z enter value of b :
cin>>b;
minus=a-b;
cout<<"\n minus of a and b is
}

b : ";
: ";
";
:

"<<minus;

void multiply()
{
int mul;
cout<<"\n now we are multiply a and b : ";
cout<<"\n pl'z enter value of a : ";
cin>>a;
cout<<"pl'z enter value of b : ";
cin>>b;
mul=a*b;
cout<<"\n multiply of a and b is : "<<mul;

}
void main()
{
clrscr();
multiply();
sum();
minus();
getch();
}
=========================================================================
************************* SQUARE *************************************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
cout<<"pl'z enter the number : ";
cin>>a;
cout<<" square is :
"<<a*a;
getch();
}
=========================================================================

******************************STACKS********************************
#include<iostream.h>
#include<conio.h>
int n ,s[10] ,top;
void push(int m)
{
if(top==9)
{
cout<<"\n\n\t STACK IS FULL ";
getch();
}
else
{
top++;
s[top]=m;
cout<<"\n\n THE NUMBER "<<s[top]<<" IS INSERTED INTO STACK ";
}
getch();
}
void pop()
{
if(top==-1)
{
cout<<"\n\n\t STACK IS EMPTY ";
getch();
}
else
{
cout<<"\n\n\t the value " <<s[top]<< " IS POPED FROM STACK ";
getch();
top--;
}
}
void main()
{
clrscr();
top=-1;
int ch ,i;
textcolor(WHITE);
textbackground(BLACK);

while(ch!=4)
{
clrscr();
cout<<"

\n*************************************";

cout<<"
\n*"<<"\t STACK IMPLIMENTATION "<< "
*";
cout<<"
\n*************************************";
gotoxy(30 ,10);
textcolor(RED);
textbackground(GREEN);
gotoxy(30,15);
cout<<"1. PUSH
";
gotoxy(30,16);
cout<<"2. POP
";
gotoxy(30,17);
cout<<"3. VIEW
";
gotoxy(30,18);
cout<<"4. EXIT
";
gotoxy(30,19);
cout<<"PL'Z ENTER YOUR CHOICE(1-4) : ";
cin>>ch;
switch(ch)
{
case 1: cout<<"\n\n\t PL'Z ENTER A NUMBER FROM YOUR KEYBOARD : ";
cin>>n;
push(n);
break;
case 2: pop();
break;
case 3: clrscr();
for(i=top;i>-1;i--)
{
cout<<"\n\t|"<<s[i]<<"|";
if(i==top)
{
cout<<"
<-------------";
}
cout<<"\n\t----";
}
cout<<"\n\t====";
getch();
}
}
getch();
}
======================================================================
#include<iostream.h>
#include<conio.h>
int n ,s[10] ,top;
void push(int m)
{
if( top==9)
{
cout<<"\n\t STACK IS FULL ";
getch();
}
else
{
top++;
s[top]=m;
cout<<"\n the number "<<s[top] <<" is inserted into stack ";
getch();
}

}
void pop()
{
if(top==-1)
{
cout<<"\n\t STACK IS EMPTY ";
getch();
}
else
{
cout<<"\n the number "<<s[top]<<" is poped from stack ";
getch();
top--;
}
}
void main()
{
clrscr();
top=-1;
int ch ,v;
while(ch!=4)
{
clrscr();
cout<<"\n\t\t STACK IMPLEMENTATION ";
cout<<"\n\n\t\t 1. PUSH ";
cout<<"\n\n\t\t 2. POP ";
cout<<"\n\n\t\t 3. VIEW ";
cout<<"\n\n\t\t 4. EXIT ";
cout<<"\n\n\t\t PL'Z ENTER YOUR CHOICE : ";
cin>> ch;
switch(ch)
{
case 1: cout<<"\n\n\t PL'Z ENTRE THE NUMBER FROM YOUR KEYBOARD :
cin>>n;
push(n);
break;
case 2: pop();
break;
case 3: clrscr();
for(v=top ;v>-1;v--)
{
cout<<"\n\t\t|"<<s[v]<<"|";
if(v==top)
cout<<"
<--------------------";
cout<<"\n\t\t----";
}
cout<<"\n\t\t====";
getch();
break;

";

}
getch();
}
getch();
}
=========================================================================

// half star
#include<iostream.h>
#include<conio.h>
void main()

{
int a,b,c;
clrscr();
for(a=1;a<=5; a++)
{
for(b=5;b>=a;b--)
{
cout<<" ";
}
for(c=1;c<=a;c++)
{
cout<<c<<" ";
}
for(c=a-1;c>=1;c--)
{
cout<<c<<" ";
}
cout<<endl;
}
getch();
}
==============================================================

// full star

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

cout<<c<<" ";
}
cout<<endl;
}
getch();
}
==========================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<" enter starting point to display even/odd number : ";
cin>>a;
cout<<" enter last point to display even/odd number
: ";
cin>>b;
cout<<" Even number
Odd number "<<endl;
for(a=a;a<=b;a++)
{
if(a%2==0)
{
cout<<"
"<<a<<endl;
}
else
{
cout<<"\n
"<<a<<endl;
}
}
getch();
}
========================================================================
*************************** POINTER ************************************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,*ptr1,**ptr2,***ptr3;
ptr1=&a;
ptr2=&ptr1;
ptr3=&ptr2;
cout<<" the address of a : "<<ptr1;
cout<<" \n the address of ptr1 : "<<ptr2;
cout<<" \n the address of ptr2 : "<<ptr3;
cout<<" \n after incrementing the address values ";
ptr1=ptr1+2;
cout<<" \n the address of a : "<<ptr1;
ptr2+=2;
cout<<"\n the address of ptr1 : "<<ptr2;
getch();
}
=====================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=10,*ptr;
ptr=&a;

cout<<" the address of a : "<<a<<endl<<endl;


*ptr=*ptr/2;
cout<<" \n the address of a : "<<*ptr;
getch();
}
======================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num[]={56,75,22,18,90},*ptr;
int i;
cout<<"\n the array values are ";
for(i=0;i<=4;i++)
cout<<endl<<endl<<num[i]<<endl;
ptr=num;
cout<<"\n the value of pointer : "<<*ptr<<endl<<endl;
ptr++;
cout<<"\n the value of pointer : "<<*ptr<<endl<<endl;
ptr--;
cout<<"\n the value of pointer : "<<*ptr<<endl<<endl;
ptr=ptr+2;
cout<<"\n the value of pointer : "<<*ptr<<endl<<endl;
getch();
}
======================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num[50],*ptr;
int i,n;
cout<<"\n pl'z enter count : ";
cin>>n;
cout<<"\n enter the number one by one ";
for(i=0;i<n;i++)
cin>>num[i];
ptr=num;
int sum=0;
for(i=0;i< n;i++)
{
if(*ptr%2==0)
sum=sum+ *ptr;
ptr++;
}
cout<<"\n the sum of numbers : "<<sum;
getch();
}
=====================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num[50],*ptr;
int i,n;
cout<<"\n pl'z enter count : ";
cin>>n;
cout<<"\n enter the number one by one ";

for(i=0;i<n;i++)
cin>>num[i];
ptr=num;
int sum=0;
for(i=0;i< n;i++)
{
if(*ptr%2==0)
sum=sum+ *ptr;
ptr++;
}
cout<<"\n the sum of numbers : "<<sum;
getch();
}
=========================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
unsigned int a,b,c=1;
cout<<"\n pl'z enter the number
: ";
cin>>a;
for(b=1;b<=a;b++)
{
c=b*c;
}
cout<<"factorial is : "<<c<<endl;
getch();
}
=================================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c=1;
cout<<"\n pl'z enter the number
: ";
cin>>a;
for(b=1;b<=a;b++)
{
c=b*c;
cout<<"factorial is : "<<c<<endl;
}
getch();
}
================================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
for(a=1;a<=10;a++)
{
if(a%2==0)
{
cout<<a<<" is even number"<<endl;
}

else
{
cout<<a<<" is odd number "<<endl;
}
}
getch();
}
==================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
for(a=0;a<10;a++)
{
cout<<a<<"\t"<<a+10<<"\t"<<a+20<<"\t"<<a+30<<"\t"<<a+40<<"\t"<<a+50<<"\t"<<a+60<<"\t"
<<a+70<<"\t"<<a+80<<"\t"<<a+90<<endl<<endl;
}
cout<<a+90;
getch();
}
=================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
for(a=30;a>=0;a=a-3)
{
cout<<"
"<<a<<endl<<endl;
}
getch();
}
=================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
char b;
cout<<"\n numbers "<<endl;
for(a=0;a<=100;a++)
{
cout<<"\t\t"<<a;
}
cout<<"\n characters"<<endl;
for(b='A';b<='Z';b++)
{
cout<<" "<<b;
}
getch();
}
==================================================================
#include<stdio.h>
int main()
{
printf("welcome to c language .");
return 0;
}

==================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num,square;

cout<<"\n pl'z entre the number : ";


cin>>num;
clrscr();
square=num*num;
cout<<" \n number is :
"<<num<<endl;
cout<<" square of number is : "<<square;
getch();
}
======================================================================
// store values in a variable .
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
a=85;
b=96;
a=b;
cout<<"\n\t\t\t value of A is :
cout<<"\n\t\t\t value of B is :

"<<a<<endl;
"<<b;

getch();
}
============================================================================
***************************** menu *****************************************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int ch,a,b,r;
cout<<"\n\t\t Calculator Menu ";
cout<<"\n\n\t\t 1. Sum ";
cout<<"\n\n\t\t 2. Minus ";
cout<<"\n\n\t\t 3. Multiply";
cout<<"\n\n\t\t 4. Division ";
cout<<"\n\n\t\t 5. Exit ";
cout<<"\n\n\t\t pl'z enter your choice : ";
cin>>ch;
switch(ch)
{
case 1 :cout<<"\n\n\t\t you have selected ( Sum ) option ";
cout<<"\n\n\t\t pl'z enter first number : ";
cin>>a;
cout<<"\n\n\t\t pl'z enter second number : ";
cin>>b;
r=a+b;
cout<<"\n\n\t\t sum of two number is
:
"<<r;
break;
case 2 :cout<<"\n\n\t\t you have selected ( Minus ) option ";
cout<<"\n\n\t\t pl'z enter first number : ";

cin>>a;
cout<<"\n\n\t\t pl'z enter second number : ";
cin>>b;
r=a-b;
cout<<"\n\n\t\t Minus of two number is
:
"<<r;
break;
case 3 :cout<<"\n\n\t\t you have selected ( Multiply ) option
cout<<"\n\n\t\t pl'z enter first number : ";
cin>>a;
cout<<"\n\n\t\t pl'z enter second number : ";
cin>>b;
r=a*b;
cout<<"\n\n\t\t Multiply of two number is
:
"<<r;
break;
case 4:cout<<"\n\n\t\t you have selected ( Division ) option
cout<<"\n\n\t\t pl'z enter first number : ";
cin>>a;
cout<<"\n\n\t\t pl'z enter second number : ";
cin>>b;
r=a/b;
cout<<"\n\n\t\t Multiply of two number is
:
"<<r;
break;
}

";

";

getch();
}
============================================================================

*************************** MENU *************************


#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int ch,l,b,area,perimeter,diagonal;
do
{
cout<<"\n\n\t\t\t Rectangle menu ";
cout<<"\n\n\t\t\t 1. Area ";
cout<<"\n\n\t\t\t 2. Perimeter ";
cout<<"\n\n\t\t\t 3. Diagonal ";
cout<<"\n\n\t\t\t 4. Exit ";
cout<<"\n\n\t\t\t pl'z enter your choice
:
";
cin>>ch;
if(ch==1||ch==2||ch==3)
{
cout<<"\n\n\t\t\t pl'z enter the length : ";
cin>>l;
cout<<"\n\n\t\t\t pl'z enter the breadth : ";
cin>>b;
}
switch(ch)
{
case 1 : area=l*b;
cout<<"\n\n\t\t\t Area of Reactangle is : "<<area;
cout<<"\n\t\t============================================"<<endl;
break;
case 2 : perimeter=2*(l+b);
cout<<"\n\n\t\t\t Perimeter of Reactangle is : "<<perimeter;
cout<<"\n\t\t============================================"<<endl;
break;

case 3 : diagonal=sqrt(l*l+b*b);
cout<<"\n\n\t\t\t Diagonal of Reactangle is : "<<diagonal;
cout<<"\n\t\t============================================"<<endl;
}
}
while(ch==1||ch==2||ch==3);
getch();
}
========================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int ch,a,b,r;
cout<<"\n\t\t Calculator Menu ";
cout<<"\n\n\t\t 1. Sum ";
cout<<"\n\n\t\t 2. Minus ";
cout<<"\n\n\t\t 3. Multiply";
cout<<"\n\n\t\t 4. Division ";
cout<<"\n\n\t\t 5. Exit ";
cout<<"\n\n\t\t pl'z enter your choice : ";
cin>>ch;
if(ch==1||ch==2||ch==3||ch==4)
{
cout<<"\n\n\t\t pl'z enter first number : ";
cin>>a;
cout<<"\n\n\t\t pl'z enter second number : ";
cin>>b;
}
switch(ch)
{
case 1 : r=a+b;
cout<<"\n\n\t\t
break;
case 2 : r=a-b;
cout<<"\n\n\t\t
break;
case 3 : r=a*b;
cout<<"\n\n\t\t
break;
case 4:
r=a/b;
cout<<"\n\n\t\t
break;
}

sum of two number is

Minus of two number is

"<<r;
:

"<<r;

Multiply of two number is

"<<r;

Multiply of two number is

"<<r;

getch();
}
===========================================================================
#include"iostream.h"
#include"conio.h"
void main()
{
clrscr();
int ch,a,b;
while(ch!=5)
{
clrscr();
cout<<"\n\n\t\t\t Airthmetic Calculation ";
cout<<"\n\n\t\t\t 1. Sum ";
cout<<"\n\n\t\t\t 2. Subtract ";

cout<<"\n\n\t\t\t

3. Multiply ";

cout<<"\n\n\t\t\t 4. Divide ";


cout<<"\n\n\t\t\t 5. Exit ";
cout<<"\n\n\t\t\t Pl'z enter your choice :
";
cin>>ch;
if(ch==1||ch==2||ch==3||ch==4)
{
cout<<"\n\n\t\t\t pl'z enter first number : ";
cin>>a;
cout<<"\n\n\t\t\t pl'z enter Second number : ";
cin>>b;
}
switch(ch)
{
case 1 :int sum=a+b;
cout<<"\n\n\t\t\t sum of two number is : "<<sum;
break;
case 2 :int subtract=a-b;
cout<<"\n\n\t\t\t Subtract of two number is :
break;

"<<subtract;

case 3 :int multiply=a*b;


cout<<"\n\n\t\t\t Multiply of two number is :
break;

"<<multiply;

case 4 :float divide=a/b;


cout<<"\n\n\t\t\t Divide of two number is : "<<divide;
break;
}
getch();
}
getch();
}
====================================================================
********************* DISPLAY NUMBERS USINF WHILE LOOP *************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
a=1;
while(a<=100)
{
cout<<a<<endl;
if(a==20)
break;
a++;
}
getch();
}
===========================================================================
***************************** COLOR ***********************************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
textcolor(RED);
textbackground(GREEN);
gotoxy(20,8);
cprintf(" colour implimentations
" );
gotoxy(20,9);

cprintf(" 1. text color is red

");

gotoxy(20,10);
cprintf(" 2. background color is green");
getch();
}
==============================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char fname[20];
char lname[15];
char age[10];
cout<<"pl'z enter name of student : ";
cin>>fname;
cin>>lname;
cout<<"pl'z enter age of student : ";
cin>>age;
cout<<"\n name of student is : "<<fname<<" "<<lname;
cout<<"\n age of student is : "<<age;
getch();
}
==============================================================================
*************************** USE OF GETLINE() ********************************
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char fname[20];
char age[10];
cout<<"pl'z enter name of student : ";
cin.getline(fname,20);
cout<<"pl'z enter age of student : ";
cin>>age;
cout<<"\n name of student is : "<<fname;
cout<<"\n age of student is : "<<age;
getch();
}
============================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char a,b;
int sum;
cout<<"enter first number : ";
cin>>a;
cout<<"enter second number : ";
cin>>b;
sum=a+b;
cout<<"sum of two number : "<<sum;
getch();
}
=============================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char fname[20];

cout<<" pl'z enter name of person : ";


cin.getline(fname ,20);
cout<<"\n name of person is : "<<fname;
getch();
}
==============================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char fadd[20];
cout<<" pl'z enter address of a person : ";
cin.getline(fadd ,20 ,'N');
cout<<"\n address of person is : "<<fadd;
getch();
}
==============================================================================
***************************class and objects**********************************
==============================================================================
#include<iostream.h>
#include<conio.h>
class A
{
public:
void welcome()
{
cout<<"hello , welcome to class and objects";
}
};
void main()
{
clrscr();
A obj ;
obj.welcome();
getch();
}
=============================================================================
#include<iostream.h>
#include<conio.h>
class calculate
{
private:
int a,b,r;
void get()
{
cout<<"pl'z enter the first number : ";
cin>>a;
cout<<"pl'z enter the second number : ";
cin>>b;
}
void sum()
{
get();
r= a+b;
}
public:
void show()
{
sum();
cout<<" sum of a and b is : "<<r;
}
};

void main()
{
clrscr();
calculate o1;
o1.show();
getch();
}
==================================================================
// sum of two numbers using classes.
#include<iostream.h>
#include<conio.h>
class A
{
public:
int a,b,r;
void get()
{
cout<<"\npl'z enter the value of a :";
cin>>a;
cout<<"pl'z enter the value of b : ";
cin>>b;
}
void sum()
{
r=a+b;
cout<<" \nsum of a and b is : "<<r;
}
void minus()
{
r=a-b;
cout<<"\nminus of a and b is "<<r;
}
};
void main()
{
clrscr();
A obj ;
obj.get();
obj.sum();
cout<<"\n----------------------";
cout<<"\npl'z enter the value of a :";
cin>>obj.a;
cout<<"\n pl'z enter the value of b :";
cin>>obj.b;
obj.minus();
getch();
}
========================================================================
// sum of two numbers using classes.
#include<iostream.h>
#include<conio.h>
int p;
class A
{
public:
int a,b,r;
void get()
{
a=45;
b=65;
}
void sum()

{
r=a+b;
cout<<" \nsum of a and b is : "<<r;
}
void minus()
{
a=12;
b=26;
r=a-b;
cout<<"\nminus of a and b is "<<r;
}
void disp()
{
p=150;
cout<<" value of p in memeber function of class is :"<<p;
}
};
void main()
{
clrscr();
A obj ;
obj.get();
obj.a=100;
obj.b=152;
cout<<"\n-------sum------------------";
obj.sum();
cout<<"\n------minus----------------";
obj.a=10;
obj.b=20;
obj.minus();
cout<<"\n-------value of p ------------";
p=15;
cout<<"\nvalue of p is : "<<p<<endl;
obj.disp();
getch();
}
==========================================================================
// sum of two numbers using classes.
#include<iostream.h>
#include<conio.h>
int p;
class A
{
private:
int a,b,r;
int add()
{
a=45;
b=65;
return a+b;
}
public:
void sum()
{
cout<<" \nsum of a and b is : "<<add();
}
};
void main()
{
clrscr();
A obj ;
obj.sum();
getch();
}

=========================================================================
#include<iostream.h>
#include<conio.h>
class A
{
int a,b;
public:
void sum()
{
int sum;
cout<<"\n pl'z enter the first number ";
cin>>a;
cout<<"pl'z enter the second number ";
cin>>b;
sum=a+b;
cout<<"\n sum of a and b is : "<<sum;
}
void minus()
{
cout<<"\n pl'z enter the first number ";
cin>>a;
cout<<"pl'z enter the second number ";
cin>>b;
cout<<"\n minus of a and b is : "<<a-b;
}
};
void main()
{
clrscr();
A obj,o1;
obj.sum();
cout<<"\n-------------------------------------------------"<<endl;
o1.sum();
cout<<"\n-------------------------------------------------"<<endl;
o1.minus();
cout<<"\n-------------------------------------------------"<<endl;
obj.minus();
getch();
}
=========================================================================
#include<iostream.h>
#include<conio.h>
class calculate
{
int a ,b,r;
public:
void assign()
{
cout<<" enter the value of A : ";
cin>>a;
cout<<" enter the value of B : ";
cin>>b;
}
void sum()
{
int s;
s=a+b;
cout<<" \n sum of A and B is : "<<s;
}
void minus()
{
r=a-b;
cout<<"\n minus of two number is : "<<r;

}
void multiply()
{
r=a*b;
cout<<" \n Multiply of two number is : "<<r;
}
void divide()
{
r=a/b;
cout<<"\n Division of two number is : "<<r;
}
};
void main()
{
clrscr();
calculate o1;
cout<<"\n Enter Two Number : "<<endl;
o1.assign();
cout<<"\n -----------------------Sum-----------------------------"<<endl;
o1.sum();
cout<<"\n -----------------------Minus-----------------------------"<<endl;
o1.minus();
cout<<"\n -----------------------Multiply-----------------------------"<<endl;
o1.multiply();
cout<<"\n -----------------------Division-----------------------------"<<endl;
o1.divide();
getch();
}
=================================================================================
//class and objects
#include<iostream.h>
#include<conio.h>
class A
{
int a,b;
public:
void sum()
{
int sum;
cout<<"pl'z enter the first number ";
cin>>a;
cout<<"pl'z enter the second number ";
cin>>b;
sum=a+b;
cout<<"\n sum of a and b is : "<<sum;
}
void minus()
{
cout<<"\n pl'z enter the first number ";
cin>>a;
cout<<"pl'z enter the second number ";
cin>>b;
cout<<"\n minus of a and b is : "<<a-b;
}
};
void main()
{
clrscr();
A obj;
obj.sum();
obj.minus();
getch();

}
============================================================================
// class with two objects.
#include<iostream.h>
#include<conio.h>
class calculate
{
int a ,b,r;
public:
void assign()
{
cout<<" enter the value of A : ";
cin>>a;
cout<<" enter the value of B : ";
cin>>b;
}
void sum()
{
int s;
s=a+b;
cout<<" \n sum of A and B is : "<<s;
}
};
void main()
{
clrscr();
calculate o1,o2;
cout<<"\n Enter Two Number for first object(o1): "<<endl;
o1.assign();
cout<<"\n Enter Two Number for second object(o2): "<<endl;
o2.assign();
cout<<"\n -----------------------Sum-----------------------------"<<endl;
o1.sum();
o2.sum();
getch();
}
==================================================================================
// global variable use anywhere .
#include<iostream.h>
#include<conio.h>
int global;
class calculate
{
int a,b;
public:
void assign()
{
cout<<" enter the value of A : ";
cin>>a;
cout<<" enter the value of B : ";
cin>>b;
}
void sum()
{
global=a+b;
cout<<" \n sum of A and B is : "<<global;
}
};
void main()
{
clrscr();
cout<<" enter the value of global varible is : ";
cin>>global;
cout<<"\n value of global varible in main function "<<global<<endl;

calculate o1;
cout<<"\n Enter Two Number

"<<endl;

o1.assign();
cout<<"\n -----------------------Sum-----------------------------"<<endl;
o1.sum();
getch();
}
====================================================================================
#include<iostream.h>
#include<conio.h>
int global;
class A
{
int a,b;
public :
void assign()
{
cout<<" \n pl'z enter the value of a : ";
cin>>a;
cout<<" pl'z enter the value of b : ";
cin>>b;
}
void sum()
{
int s;
s=a+b;
cout<<"\n------------------------sum--------------------------"<<endl;
cout<<" sum of a and b is
:
"<<s;
}
void multiply()
{
int m= a*b ;
cout<<"\n --------------------multiply------------------------";
cout<<"\n multiply of a and b is
:
"<<m;
}
void show()
{
global=20;
cout<<"\n value of global variable in memeber function is : "<<global;
}
};
void main()
{
clrscr();
cout<<" enter the value of global variable for main function : ";
cin>>global;
cout<<"\n value of global variable in main function is : "<<global<<endl;
A obj;
cout<<"\n---------------------------------------------------------------"<<endl;
obj.assign();
obj.sum();
obj.multiply();
cout<<"\n---------------------------------------------------------------"<<endl;
obj.show();
getch();
}
=============================================================================
#include <iostream.h>
#include<conio.h>
class Dealer
{
char firstName[25];
char lastName[25];
char city[25];

char phoneNo[11];
public:
void display()
{
cout << "First Name: ";
cout << firstName <<"
";
cout <<"Last name: ";
cout << lastName << endl;
cout << "City: ";
cout << city<<"
";
cout << "Phone number: ";
cout << phoneNo << endl;
}
void get()
{
cout << "First name: ";
cin >> firstName;
cout << endl << "Last Name: ";
cin >> lastName;
cout << endl << "City: ";
cin >> city;
cout << endl << "Residence phone number: ";
cin >> phoneNo;
}
};
int main()
{
Dealer d1;
d1.get();
d1.display();
return 0;
}
=============================================================================
#include <iostream.h>
#include<conio.h>
class flightdetails
{
char flightnum[10];
char dest[20];
char date[8];
public:
void f_accept()
{
cout<<"Enter the flight number:";
cin>>flightnum;
cout<<"Enter the destination:";
cin>>dest;
cout<<"Enter the date:";
cin>>date;
}
void f_display()
{
cout<<"Flight Number:"<<flightnum<<endl;
cout<<"Destination:"<<dest<<endl;
cout<<"Date:"<<date<<endl;
}
};
class passengerdetails
{
char fname[15];
char lname[20];
int age;

char sex;
public:
void p_accept()
{
cout<<"Enter your first name:";
cin>>fname;
cout<<"Enter your last name:";
cin>>lname;
cout<<"Enter your age:";
cin>>age;
cout<<"Enter your sex(m/f):"<<endl;
cin>>sex;
}
void p_display()
{
cout<<"First name:"<<fname<<endl;
cout<<"Last name:"<<lname<<endl;
cout<<"Age:"<<age<<endl;
cout<<"Sex:"<<sex<<endl;
}
};
void main()
{
flightdetails F1;
F1.f_accept();
passengerdetails P1;
P1.p_accept();
F1.f_display();
P1.p_display();
}
=========================================================================
********************** swap value *************************************
#include<iostream.h>
#include<conio.h>
class interchange
{
private:
int var1;
int var2;
int temp;
public:
void swap()
{
var1=5;
var2=10;
temp=var1;
var1=var2;
var2=temp;
}
void display()
{
cout<<"The new value of variable1 is:"<<var1<<endl;
cout<<"The new value of variable2 is:"<<var2<<endl;
}
};
void main()
{
interchange I1;
I1.swap();
I1.display();
}
=======================================================================

#include <iostream.h>
#include<conio.h>
class MyInt
{
int num1;
public:
MyInt()
{
num1=0;
}
MyInt(MyInt *ptr)
{
num1=ptr->num1;
}
void disp()
{
cout<< Value of Num1 is -><<num1;
}
void accept()
{
cout<< \nEnter any numeric value\t;
cin>>num1;
}
};
void main()
{
MyInt int1,int2;
cout<< \nThe objects initialization values are\n;
cout<< Int1 -><<int1.disp();
cout<< Int2 -><<int2.disp();
int1.accept();
//Initializing int2 with int1
int2=int1; //Possible because of the copy constructor
cout<< \nValues after assigning are\n;
cout<< Int1 -><<int1.disp();
cout<< Int2 -><<int2.disp();
}
===========================================================================
#include <iostream.h>
class Employee
{
int salary[10];
public:
void accept_details()
{
int counter=0;
//Accept value in array
for(;counter<9;counter++)
{
cout<< Enter the Salary\n;
cin>>salary[counter];
}
}
void sort()
{
/* Traverse the array */
while(counter < 9)
{
int temp;
// Compare The Value Of Current Element With The Next
if(salary[counter] < salary[counter + 1])
{

/* Swap The Values */


temp = salary[counter];
salary [counter] = salary [counter + 1];
salary [counter + 1] = temp;
counter = 0;
continue;
}
counter++;
}
}
void display_asc()
{
/* Display All The Array Elements */
for(int counter = 0;counter < 10; ++counter)
{
if(salary[counter] != 0)
{
cout << "Element " << salary << ": ";
cout << salary [counter] << endl;
}
}
}
void display_desc()
{
/* Display All The Array Elements */
for(int counter = 9;counter >= 0; ++counter)
{
if(salary [counter] != 0)
{
cout << "Element " << counter << ": ";
cout << salary [counter] << endl;
}
}
}
void display_greater()
{
for(int ctr=0;salary[ctr]!=\0;ctr++)
if(salary[ctr])>1000)
cout<<salary[ctr];
}
void display_max()
{
int max=0;
for(int ctr=0;salary[ctr]!=\0;ctr++)
if(max<salary[ctr])
max=salary[ctr];
cout<< Maximum Salary is \t<<max;
}
void display_min()
{
int min=0;
for(int ctr=0;salary[ctr]!=\0;ctr++)
if(min>salary[ctr])
min=salary[ctr];
cout<< Minimum Salary is \t<<min;
}
void avgAmount()
{
float sum;
for(sum = 0.0f, counter = 0; counter < 10; counter++)
{
sum = sum + salary[counter];
}
cout << endl << "The average amount is : " << sum/10 << endl;

};
int main()
{
Employee empObj;
empObj.accept_details();
int choice = 0;
empObj.sortData();
while(choice != 6)
{
cout << endl << "Menu ";
cout << endl << "1. The maximum salary";
cout << endl << "2. The minimum salary";
cout << endl << "3. The average salary";
cout << endl << "4. The number of employees whose salary is greater than 1000";
cout << endl << "5. The salary in ascending and descending orders";
cout << endl << "6. Exit" << endl << endl;
cout << "Enter choice ";
cin >> choice;
switch(choice)
{
case 1:
empObj.display_max();
break;
case 2:
empObj.display_min();
break;
case 3:
empObj.avgAmount();
break;
case 4:
empObj.display_greater();
break;
case 5:
cout << endl << "Descending Order " << endl;
empObj.display_asc();
cout << "Ascending Order " << endl;
empObj.display_desc();
break;
case 6:
continue;
default:
cout << endl << "Please enter 1-6 only !" << endl;
}
}
return 0;
}
======================================================================
#include<iostream.h>
#include<conio.h>
int x ,y;
class calculate
{
public:
int a ,b,r;
void assign()
{
cout<<" pl'z enter A : ";
cin>>a;
cout<<"pl'z enter B : ";
cin>>b;
}

void sum()
{
int s;
s=a+b;
cout<<" \n sum of A and B is : "<<s;
}
void minus()
{
r=a-b;
cout<<"\n minus of two number is : "<<r;
}
void multiply()
{
r=a*b;
cout<<" \n Multiply of two number is : "<<r;
}
void divide()
{
r=a/b;
cout<<"\n Division of two number is : "<<r;
}
};
void main()
{
clrscr();
calculate o1;
cout<<"\n Enter Two Number : "<<endl;
o1.assign();
o1.a=50;
o1.b=50;
cout<<"\n -----------------------Sum-----------------------------"<<endl;
o1.sum();
cout<<"\n -----------------------Minus-----------------------------"<<endl;
o1.a=42;
o1.b=32;
o1.assign();
o1.minus();
cout<<"\n -----------------------Multiply-----------------------------"<<endl;
cout<<"\n\n pl'z enter the value of A : ";
cin>>o1.a;
cout<<"\n\n pl'z enter the value of B : ";
cin>>o1.b;
o1.multiply();
cout<<"\n -----------------------Division-----------------------------"<<endl;
o1.assign();
o1.divide();
getch();
}
================================================================================
#include<iostream.h>
#include<conio.h>
class calculate
{
int a,b,r;
public :
calculate()
{
a=0;
b=0;
r=0;
}

void get()
{
cout<<" pl'z enter the value of A :
cin>>a;
cout<<" pl'z enter the value of B :
cin>>b;
}
void sum()
{
r=a+b;
cout<<" sum of two number is "<<r;
}

";
";

};
void main()
{
clrscr();
calculate obj;
obj.get();
obj.sum();
getch();
}
===================================================================================
#include<iostream.h>
#include<conio.h>
class calculate
{
int a,b,r;
public :
calculate(int x ,int y)
{
a=x;
b=y;
r=0;
}
void sum()
{
r=a+b;
cout<<"\n sum of two number is "<<r;
}
~calculate()
{
cout<<"\n destructor is invoked ";
}
};
void main()
{
clrscr();
int num1 ,num2;
cout<<"pl'z enter the value of num1 : ";
cin>>num1;
cout<<"pl'z enter the value of num2 : ";
cin>>num2;
calculate obj(num1,num2);
obj.sum();
getch();
}
===============================================================================
***************************** CONSTRUCTOR & DESTRUCTOR ************************
#include<iostream.h>
#include<conio.h>
class calculate
{

int a,b,r;
public :
calculate()
{
a=0;
b=0;
r=0;
}
void get()
{
cout<<" pl'z enter the value of A :
cin>>a;
cout<<" pl'z enter the value of B :
cin>>b;
}
void sum()
{
r=a+b;
cout<<" sum of two number is "<<r;
}
~calculate()
{
cout<<"\n destructor is invoked ";
}

";
";

};
void main()
{
clrscr();
calculate obj;
obj.get();
obj.sum();
getch();
}
=====================================================================================
// constructors & destructors;
#include<iostream.h>
#include<conio.h>
class calculator
{
private:
int a,b,r;
public:
void sum(int ,int);
};
void calculator :: sum(int x ,int y)
{
a=x;
b=y;
r=a+b;
cout<<" sum of two number is : "<<r;
}
void main()
{
clrscr();
int num1 , num2;
cout<<"pl'z enter the value of first number : ";
cin>>num1;
cout<<"pl'z enter the value of 2nd number : ";
cin>>num2;
calculator o1;
o1.sum(num1,num2);
getch();

}
==============================================================================
// constructors & destructors;
#include<iostream.h>
#include<conio.h>
class calculator
{
int a,b,r;
public:
calculator();
void get();
void sum();
void show();
};
calculator :: calculator()
{
a=0;
b=0;
r=0;
}
void calculator :: get()
{
a=45;
b=62;
}
void calculator :: sum()
{
r=a+b;
}
void calculator :: show()
{
cout<<"sum of a and b is :
"<<r;
}
void main()
{
clrscr();
calculator o1;
o1.get();
o1.sum();
o1.show();
getch();
}
============================================================================
#include<iostream.h>
#include<conio.h>
class values
{
private:
int var1;
public:
int var2;
int var3;
void assign()
{
var1=5;
var2=10;
var3=15;
}
void display()
{
cout<<"The value of variable1 is:"<<var1<<endl;
cout<<"The value of variable2 is:"<<var2<<endl;
cout<<"The value of variable3 is:"<<var3<<endl;
}

};
void main()
{
clrscr();
values V1;
V1.assign();
V1.var2=20;
V1.var3=50;
V1.display();
}
===========================================================================
#include<iostream.h>
#include<conio.h>
int globalvar;
class test
{
int var1;
int var2;
public:
void sum()
{
int sum;
globalvar=1;
cout<<"enter the value of var1 :";
cin>>var1;
cout<<" enter the value of var2 :";
cin>>var2;
sum=var1+var2;
cout<<"\n sum of var1 and var2 is : "<<sum;
cout<<"\n value of global varible in memeber function 1 is :
"<<globalvar<<endl;
}
void minus()
{
globalvar=2;
int minus ;
minus=var1-var2;
cout<<"\n minus of var1 and var 2 is : "<<minus;
cout<<"\n value of global varible in memeber function 2 is :
"<<globalvar<<endl;
}
};
void main()
{
clrscr();
cout<<"\n pl'z enter the value of globalvarible for main function : ";
cin>>globalvar;
cout<<"\n value of global variable in main function is : "<<globalvar;
test o2;
o2.sum();
o2.minus();
getch();
}
================================================================================
****************************** GLOBAL VARIBLE **********************************
# include <iostream.h>
# include <conio.h>
int

globalvar;

class
{

scope
int a , b ;
public:
void sum()
{
a=15;
b=10;
globalvar=100;
int sum=a+b;
cout<<"sum is "<<sum<<endl;
cout<<"value of globalvarible is "<<globalvar<<endl;
}
void minus()
{
a=45;
b=10;
globalvar=200;
int minus=a-b;
cout<<"minus is "<<minus<<endl;
cout<<"value of globalvarible is "<<globalvar;
}

};
void main ()
{
clrscr();
cout<<"enter value of globalvarible for main function() ";
cin>>globalvar;
cout<<" value is : "<<globalvar<<endl;
scope obj;
obj.sum();
obj.minus();
getch ();
}
=========================================================================
# include <iostream.h>
# include <conio.h>
int
class
{

globalvar;
scope
int a , b ;
public:
void sum()
{
a=15;
b=10;
globalvar=100;
int sum=a+b;
cout<<"sum is "<<sum<<endl;
cout<<"value of globalvarible is "<<globalvar<<endl;
}
void minus()
{
a=45;
b=10;
globalvar=200;
int minus=a-b;
cout<<"minus is "<<minus<<endl;
cout<<"value of globalvarible is "<<globalvar;
}

};

void main()
{
clrscr();
cout<<"enter value of globalvarible for main function() ";
cin>>globalvar;
cout<<" value is : "<<globalvar<<endl;
scope obj;
obj.sum();
obj.minus();
getch ();
}
================================================================================
********************* CHANGE VALUE OF CLASS VARIBLE IN MAIN() *****************
#include<iostream.h>
#include<conio.h>
class test
{
public:
int var1;
int var2;
void disp()
{
cout<<"\nvar 1= "<<var1<<endl;
cout<<"\nvar 2 = "<<var2<<endl;
}
};
void main()
{
clrscr();
test o2;
cout<<"enter the value of var1 : ";
cin>>o2.var1;
cout<<" enter the value of var 2 :";
cin>> o2.var2;
o2.disp();
getch();
}
=================================================================================
********************* CHANGE VALUE OF CLASS VARIBLE IN MAIN ()*******************
#include<iostream.h>
#include<conio.h>
class test
{
public:
int var1;
int var2;
void assign()
{
var1=10 ;
var2=20;
}
void disp()
{
cout<<"\nvar 1= "<<var1<<endl;
cout<<"\nvar 2 = "<<var2<<endl;
}
};
class sample
{
int var1 ,var2;
public :
void display()

{
var1=40;
var2=50;
cout<<"\nvar 1 = "<<var1;
cout<<"\nvar 2 = "<<var2;
}
};
void main()
{
clrscr();
sample s1;
s1.display();
test o2;
o2.assign();
o2.var1=100;
o2.var2=200;
o2.disp();
getch();
}
============================================================================
*************************** TWO CLASSES WITH TWO OBJECTS
*****************************
#include<iostream.h>
#include<conio.h>
class test
{
public:
int var1;
int var2;
void disp()
{
cout<<"var1="<<var1<<endl;
cout<<"var2="<<var2<<endl;
}
};
class sample
{
public:
int var1 ,var2;
void display()
{
var1=100;
var2=200;
cout<<"var1="<<var1<<endl;
cout<<"var2="<<var2;
}
};
void main()
{
clrscr();
test o1;
cout<<"enter var1 ";
cin>>o1.var1;
cout<<"enter var2";
cin>>o1.var2;
clrscr();
o1.disp();

sample S1;
S1.display();

}
=============================================================================
******************* ARRANGE RECORD IN DESICENDING ORDER**********************
#include <iostream.h>
#include<conio.h>
class Customers
{
float amounts[10];
public:
void sortData()
{
int ctr;
for ( ctr = 0; ctr < 10; ctr ++ )
{
cout << "Enter the amount : ";
cin >> amounts[ctr];
if(amounts[ctr]==0)
{
cout<<"pl'z re-enter the amount : ";
cin>>amounts[ctr];
}
}
int counter=0;
/* Traverse The Array */
while(counter < 9)
{
float temp;
/* Compare The Value Of Current Element With The Next */
if(amounts[counter] < amounts[counter + 1])
{
/* Swap The Values */
temp = amounts[counter];
amounts[counter] = amounts[counter + 1];
amounts[counter + 1] = temp;
counter = 0;
continue;
}
counter++;
}
}
void display()
{
/* Display All The Array Elements */
for(int counter = 0;counter < 10; ++counter)
{
cout << "amount of customer " << counter<< ":
<< endl;

" << amounts[counter]

}
}
};
void main()
{
clrscr();
Customers C1;
C1.sortData();
C1.display();
getch();
}
=================================================================================

*********************** TWO CLASSES WITH TWO OBJECTS ****************************


#include<iostream.h>
#include<conio.h>
class test
{
int var1;
int var2;
public:
void disp()
{
var1=20;
var2=10;
cout<<"var1="<<var1<<endl;
cout<<"var2="<<var2<<endl;
}
};
class sample
{
public:
int var1 , var2;
void display()
{
var1=50;
var2=40;
cout<<"var1="<<var1<<endl;
cout<<"var2="<<var2;
}
};
void main()
{
clrscr();
test o1;
o1.disp();
sample S1;
S1.display();
}
====================================================================================
*******************************Reverse a String **********************************
#include <iostream.h>
#include<conio.h>
class strings
{
char source[101], dest[101];
int pos ,j;
public:
void reverseString()
{
pos=j=0;
cout << "Enter string to be reversed"
<< " (please enter a maximum of 100 characters): " << endl ;
cin >> source;
while(source[pos]!= '\0')
{
pos = pos + 1;
}
for(--pos; pos >= 0 ;dest[j++] = source[pos--]);
dest[j] = 0;
cout << endl << "The reversed string is: " << endl << dest << endl;
}

};
int main()
{
clrscr();
strings S1;
S1.reverseString();
return 0;
}
===================================================================================
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int month;
cout<< "Tell me a month number.";
cout<< "I will tell you the number of days in that month.";
cin>>month;
if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||
(month==10)||(month==12))
{
cout<<"Month has 31 days";
}
else if((month==4)||(month==6)||(month==9)||(month==11))
{
cout<<"Month has 30 days";
}
else if (month==2)
{
cout<<"Month has either 28 or 29(if leap year) days."<<endl;
}
else
{
cout<<"There are only 12 months silly."<<endl;
}
getch();
}
=====================================================================================
***************************** STATIC VARIBLES ***************************************
#include<iostream.h>
#include<conio.h>
class CountsItself
{
static int objectCount;
int localCount;
public:
void setCount()
{
localCount=objectCount++;
}
void displayCount()
{
cout<<"Total number of objects :"<<localCount;
}
};
int CountsItself::objectCount;
void main()
{
clrscr();
CountsItself count1, count2, count3;
count1.setCount();
count2.setCount();
count3.setCount();
count3.displayCount();
getch();

}
=====================================================================================
#include<iostream.h>
#include<conio.h>
void showNumber(int number)
{
number=20;
cout<< "Number is "<<number<<endl;
}
void displayNumbers(int number[])
{
number[0]=30;
cout<<"\n Number inside displayNumber Method is "<<number[0]<<endl;
}
void main()
{
clrscr();
int numbers[]={4,5,6};
cout<<"The number in main function is : "<<numbers[0]<<endl;
showNumber(numbers[0]);
cout<<"The number in main()after calling showNumber is : "<<numbers[0]<<endl;
displayNumbers(numbers);
cout<<"The number in main() after calling displayNumbers is :
"<<numbers[1]<<endl;
getch();
}
===============================================================================
************************** CONSTRUCTOR & DESTRUCTOR ***************************
#include<iostream.h>
#include<conio.h>
class calculator
{
private:
int number1,number2,tot;
public:
calculator()
{
number1=10;
number2=20;
tot=number1+number2;
cout<<"sum of two number is "<<tot;
}
~ calculator()
{
cout<<" \n now constructor is out of scope ";
}
void show()
{
cout<<"\n constructor and destructor is automatically invoked ";
}
};
void main()
{
clrscr();
calculator c1;
c1.show();
getch;
}
=====================================================================================
***************************** CONSTRUCTOR WITH PARAMETER ***************************
#include<iostream.h>
#include<conio.h>
class calculator
{
private :

int num1 ,num2,total;


public:
calculator(int, int) ;
void sum();
};
calculator ::calculator (int x ,int y)
{
num1=x;
num2=y;
total=0;
}
void calculator :: sum()
{
total=num1+num2;
cout<<" the sum of "<<num1 <<" and "<<num2<< " is : "<<total;
}
void main()
{
clrscr();
calculator obj(42 ,65);
obj.sum();
getch();
}
==============================================================================
#include<iostream.h>
#include<conio.h>
class calculator
{
private :
int num1 ,num2,total;
public:
calculator(int, int) ;
void sum();
};
calculator ::calculator (int x ,int y)
{
num1=x;
num2=y;
total=0;
}
void calculator :: sum()
{
total=num1+num2;
cout<<" the sum of "<<num1 <<" and "<<num2<< " is : "<<total;
}
void main()
{
clrscr();
int var1 ,var2;
cout<<"\n pl'z enter the value of var1:";
cin>>var1;
cout<<"pl'z enter the value of var2 : ";
cin>>var2;
calculator obj(var1 ,var2);
obj.sum();
getch();
}
=============================================================================
#include<iostream.h>
#include<conio.h>
class calculate
{

int a,b,r;
public :
calculate()
{
a=0;
b=0;
r=0;
}
void get()
{
cout<<" pl'z enter the value of A :
cin>>a;
cout<<" pl'z enter the value of B :
cin>>b;
}
void sum()
{
r=a+b;
cout<<" sum of two number is "<<r;
}
~calculate()
{
cout<<"\n destructor is invoked ";
}

";
";

};
void main()
{
clrscr();
calculate obj;
obj.get();
obj.sum();
getch();
}
=================================================================================
************************** SCOPE RESOLATATION OPERATOR (::)**********************
#include<iostream.h>
#include<conio.h>
class atika
{
private :
int a;
public:
void loop();
};
void atika::loop()
{
for(a=0;a<=20;a++)
{
cout<<a<<endl;
}
}
void main()
{
clrscr();
atika obj;
obj.loop();
getch();
}
=====================================================================================

#include<iostream.h>
#include<conio.h>
class atika
{
private :
char name[25];
char age[15];
char address[30];
public:
atika();
void show();
};
atika ::atika()
{
cout<<" pl'z enter the name : ";
cin.getline(name,25);
cout<<"pl'z enter the age : ";
cin>>age;
cout<<"pl'z enter the address : ";
cin>>address;
}
void atika:: show()
{
cout<<"\n name of student is : "<<name<<endl;
cout<<"\n age of student is : "<<age<<endl;
cout<<"\n address of student is : "<<address<<endl;
}
void main()
{
clrscr();
atika obj;
obj.show();
getch();
}
===============================================================================
************************* MEMBER FUNCTION WITH PARAMETERS ********************
#include<iostream.h>
#include<conio.h>
class calculator
{
private:
int x,y,s;
public :
calculator();
void get(int ,int);
void sum();
void show();
};
calculator :: calculator()
{
cout<<"\n this is a default construtor and it is automatically invoked";
x=0;
y=0;
s=0;
}
void calculator :: get(int a ,int b)
{
x=a;
y=b;
}

void calculator :: sum()


{
s=x+y;
}
void calculator :: show()
{
cout<<" \n sum of x and y is : "<<s;
}
void main()
{
clrscr();
int var1 ,var2;
calculator o1;
cout<<"\n pl'z enter the value of var1 : ";
cin>>var1;
cout<<"pl'z enter the value of var2 : ";
cin>>var2;
o1.get(var1,var2);
o1.sum();
o1.show();
getch();
}
=================================================================================
***************************CONSTRUCTOR OVERLOADING ******************************
#include<iostream.h>
#include<conio.h>
class calculator
{
private :
int num1 ,num2,total;
public:
calculator(int, int) ;
void sum();
};
calculator ::calculator (int x ,int y)
{
num1=x;
num2=y;
total=0;
}
void calculator :: sum()
{
total=num1+num2;
cout<<" the sum of "<<num1 <<" and "<<num2<< " is : "<<total;
}
void main()
{
clrscr();
calculator obj(42 ,65);
obj.sum();
getch();
}
===================================================================================
************************** CONSTRUCTOR OVERLOADING***********************************
#include<iostream.h>
#include<conio.h>
class calculator
{
private:
int x,y,s;
public :

calculator();
~calculator()
{
cout<<"\n this is destructor ";
}
calculator(int , int);
void sum();
void show();
};
calculator :: calculator()
{
cout<<"\n this is a default construtor and it is automatically invoked";
}
calculator :: calculator(int a ,int b)
{
x=a;
y=b;
}
void calculator :: sum()
{
s=x+y;
}
void calculator :: show()
{
cout<<" \n sum of x and y is : "<<s;
}
void main()
{
clrscr();
calculator obj;
int var1 ,var2;
cout<<"\n pl'z enter the value of var1 : ";
cin>>var1;
cout<<"pl'z enter the value of var2 : ";
cin>>var2;
calculator o1(var1,var2);
o1.sum();
o1.show();
getch();
}
====================================================================================
#include<iostream.h>
#include<conio.h>
class atika
{
private :
char name[25];
char age[15];
char address[30];
public:
void accept()
{
cout<<" pl'z enter the name : ";
cin.getline(name,25);
cout<<"pl'z enter the age : ";
cin>>age;
cout<<"pl'z enter the address : ";
cin>>address;
}

void show()
{
cout<<"\n name of student is : "<<name<<endl;
cout<<"\n age of student is : "<<age<<endl;
cout<<"\n address of student is : "<<address<<endl;
}
};
void main()
{
clrscr();
atika obj;
obj.accept();
obj.show();
getch();
}
=====================================================================================
#include<iostream.h>
#include<conio.h>
class atika
{
private :
char fname[15];
char lname[12];
char age[15];
char address[30];
public:
void accept()
{
cout<<" pl'z enter the name : ";
cin>>fname;
cin>>lname;
cout<<"pl'z enter the age : ";
cin>>age;
cout<<"pl'z enter the address : ";
cin>>address;
}
void show()
{
cout<<"\n name of student is : "<<fname<<" "<<lname<<endl;
cout<<"\n age of student is : "<<age<<endl;
cout<<"\n address of student is : "<<address<<endl;
}
};
void main()
{
clrscr();
atika obj;
obj.accept();
obj.show();
getch();
}
=================================================================================
#include<iostream.h>
#include<conio.h>
class atika
{
private :
char name[25];
char age[15];
char address[30];
public:
void accept();
void show();
};

void atika :: accept()


{
cout<<" pl'z enter the name : ";
cin.getline(name,25);
cout<<"pl'z enter the age : ";
cin>>age;
cout<<"pl'z enter the address : ";
cin>>address;
}
void atika:: show()
{
cout<<"\n name of student is : "<<name<<endl;
cout<<"\n age of student is : "<<age<<endl;
cout<<"\n address of student is : "<<address<<endl;
}
void main()
{
clrscr();
atika obj;
obj.accept();
obj.show();
getch();
}
=================================================================================
************************** SWAP VALUE & CALL BY VALUE ***************************
#include<iostream.h>
#include<conio.h>
void swap(int ,int);
class functioncall
{
int number1 ,number2;
public:
void accepts();
};
void functioncall :: accepts()
{
cout<<"pl'z enter first number ";
cin>>number1;
cout<<"pl'z enter second number ";
cin>>number2;
swap(number1,number2);
cout<<number1<<"
"<<number2<<endl;
}
void swap(int num1 ,int num2)
{
int temp;
temp=num1;
num1=num2;
num2=temp;
cout<< num1<<"
"<<num2<<endl;
}
void main()
{
clrscr();
functioncall f1;
f1.accepts();
getch();
}
====================================================================================

******************CALLING MEMBER FUCTION USING CALL BY VALUE ***********************


#include<iostream.h>
#include<conio.h>
void square(int);
class functioncal
{
int number;
public :
functioncal();
};
functioncal :: functioncal()
{
cout<<"pl'z enter a number ";
cin>>number;
square(number);
}
void square(int num)
{
cout<<"number is : "<<num<<endl;
num=num*num;
cout<<"square is : "<<num<<endl;
}
int main()
{
clrscr();
functioncal f1;
getch();
return 0;
}
==============================================================================
******************************* CALL BY REFERENCES ***************************
#include<iostream.h>
#include<conio.h>
void swap(int & , int &);
class functioncall
{
int number1 ,number2;
public :
void accept();
} ;
void functioncall :: accept()
{
cout<<" enter first number : ";
cin>>number1;
cout<<" enter second number : ";
cin>>number2;
swap(number1, number2);
cout<<"number 1 is :"<<number1<<endl;
cout<<"number2 is : "<<number2;
}
void swap(int &num1 , int &num2)
{
int temp;
temp=num1;
num1=num2;
num2=temp;
}
void main()
{
clrscr();
functioncall o1;
o1.accept();
getch();

}
===============================================================================
****************** CALL BY REFERENCES USING POINTER ***************************
#include<iostream.h>
#include<conio.h>
void swap(int *, int*);
void main()
{
clrscr();
int number1 ,number2;
cout<<"enter two numbers "<<endl;
cin>>number1;
cin>>number2;
swap(&number1 ,&number2);
cout<<number1<<"
"<<number2<<endl;
getch();
}
void swap(int *ptr1 , int *ptr2)
{
int temp;
temp=*ptr1;
*ptr1=*ptr2;
*ptr2=temp;
cout<<*ptr1<<"
"<<*ptr2<<endl;
}
==============================================================================
******************************* OPERATOR OVERLOADING *************************
#include<iostream.h>
#include<conio.h>
class Number
{
private:
int number;
public:
Number(int = 0); //Constructor
/* Operations */
Number plus(int = 0);
Number plus(Number);
void display(); //Function
};
Number :: Number(int num)
{
number = num;
}
Number Number :: plus(int num)
{
Number temp;
temp.number = number + num;
return temp;
}
Number Number :: plus(Number objnum)
{
Number temp;
temp.number = number + objnum.number;
return temp;
}
void Number :: display()
{
cout << number << endl;
}
int main()
{
clrscr();
Number num1(100);
Number num2(200);

Number num3 = num1;


Number tot;
tot = num1.plus(50);
tot.display();
//Displays 150
tot = num1.plus(num2);
tot.display();
//Displays 300
num3.display(); //Displays 100
getch();
return 0;
}
==================================================================================
#include<iostream.h>
class Number
{
private:
int number;
public:
Number(int = 0); //Constructor
/* Operations */
Number plus(int = 0);
Number plus(Number);
void display(); //Function
};
Number :: Number(int num)
{
number = num;
}
Number Number :: plus(int num)
{
Number temp;
temp.number = number + num;
return temp;
}
Number Number :: plus(Number objnum)
{
Number temp;
temp.number = number + objnum.number;
return temp;
}
void Number :: display()
{
cout << number << endl;
}
int main()
{
Number num1(100);
Number num2(200);
Number num3 = num1;
Number tot;
tot = num1.plus(50);
tot.display();
//Displays 150
tot = num1.plus(num2);
tot.display();
//Displays 300
num3.display(); //Displays 100
return 0;
}
===================================================================================
#include<iostream.h>
class distance
{
int length;
public:
distance(int);

void operator =(distance);


};
distance::distance(int a)
{
length=a;
}
void distance::operator =(distance d)
{
if (length=d.length)
{
cout<<length<<" is equal to "<<d.length;
}
else
{
cout<<length<<" is not equal to "<<d.length;
}
}
int main()
{
distance d1(20);
distance d2(20);
d1=d2;
return 0;
}
===================================================================================
#include<stdio.h>
#include<iostream>
class Time
{
//Declare hour, minute, and second
int hour;
int minute;
int second;
public:
//Default constructor
Time()
{
hour=0;
minute=0;
second=0;
}
//Constructor to set hour, minute, and second
Time(int hr, int min=0, int sec=0)
{
hour=hr;
minute=min;
second=sec;
}
void setTime(int hr,int min,int sec);
void setTime(int min);
//second
void setTime(int min,int sec);
void display()
{
cout<<hour<<":"<<minute<<":"<<second<<endl;
}
};

void Time::setTime(int hr, int min, int sec)


{
hour=hr;
minute=min;
second=sec;
}
void Time::setTime(int min)
{
minute=min;
}
void Time::setTime(int min, int sec)
{
minute=min;
second=sec;
}
int main()
{
//Time object
Time time;
//Setting hour, minute, and second
time.setTime(12,30,50);
//Displaying time in the hh:mm:ss format
time.display();
//Setting the minute to 35 minutes past 12:00
time.setTime(35);
time.display();
//Setting the minute and second
time.setTime(42, 31);
time.display();
}//End of main()
===================================================================================
#include <iostream>
class DayCount
{
int month;
int year;
int days;
public:
//constructor to initialize month and year to 0
DayCount()
{
month=0;
year=0;
}
//returns 1 if year is a leap year, else returns 0
int leap()
{
if (year%4 ==0 || year%400!=0)
return 1;
return 0;
}
//sets the month and year
void setDate(int mth, int yr)
{
year=yr;
month=mth;
}
// sets the month, overloaded function

void setDate(int mth)


{
month=mth;
}
//returns the name of the month
char *monthName()
{
switch(month)
{
case 1: return "January"; case 2: return "February";
case 3: return "March"; case 4: return "April";
case 5: return "May"; case 6: return "June";
case 7: return "July"; case 8: return "August";
case 9: return "September"; case 10: return "October";
case 11: return "November"; case 12: return "December;
}
}
//sets the number of days in a month
void setDays()
{
switch(month)
{
case 1:case 3: case 5:case 7:case 8:case 10:case 12:
days=31;
break;
case 2: days=28;
if (leap())
days=29;
break;//assign 29 days if leap year
case 4:case 6:case 9:case 11:
days=30;
break;
}
}
void display()
{
setDays();
cout<< "The number of days for the month of "<<monthName();
cout << " is "<<days<<endl;
}
};
int main()
{
int mm,yy;
DayCount dayCount;
cout<<Enter month<<endl;
cin>>mm;
cout<<Enter year<<endl;
cin>>yy;
dayCount.setDate(mm,yy);
dayCount.display();
}
===================================================================================
***************************** INHERITANCES ****************************************
#include <iostream.h>
#include<conio.h>
class furniture
{
protected:
char color[12];
int width;
int height;
};

class bookshelf:public furniture


{
private:
int no_shelves;
public:
void accept()
{
cout<<"\nEnter Color of bookself
cin>>color;
cout<<"Enter Width of bookself
cin>>width;
cout<<"Enter Height of bookself
cin>>height;
cout<<"Enter No. of shelves
:
cin>>no_shelves;

";

";

";
";

}
void display()
{
cout<<"\nColor of bookself is : "<<color<<endl;
cout<<"Width of bookself is
:
"<<width<<endl;
cout<<"Height of bookself is : "<<height<<endl;
cout<<"Number of shelves is :
"<<no_shelves<<endl;
}
};
class chair:public furniture
{
private:
int no_legs;
public:
void accept()
{
cout<<"\nEnter Color of chair : ";
cin>>color;
cout<<"Enter Width of chair
: ";
cin>>width;
cout<<"Enter Height of chair
: ";
cin>>height;
cout<<"Enter number of legs of chair : ";
cin>>no_legs;
}
void display()
{
cout<<"\nColor of chair is
: "<<color<<endl;
cout<<"Width of chair is
:
"<<width<<endl;
cout<<"Height of chair is
:
"<<height<<endl;
cout<<"Number of legs of chair is
:
"<<no_legs<<endl;
}
};
void main()
{
clrscr();
bookshelf b1;
chair c1;
b1.accept();
b1.display();
c1.accept();
c1.display();
getch();
}
=================================================================================

//Class will be used for inheritance purpose only


class
{

Shape
//Class variables
protected:
int length;
int breadth;
int area;
public:
//The constructor
Shape()
{
length=0;
breadth=0;
}
//Function to set parameters
void setParameters()=0;
//Function to display parameters
void displayParameters()=0;
//Function to draw shape, will print a message
void draw()=0;
void calculateArea()=0;

};
class Rectangle: public Shape
{
void setParameters()
{
cout<<Enter length and breadth:;
cin>>length;
cin>>breadth;
}
void displayParameters()
{
cout<<Length and breadth
are:<<length<<:<<breatdh;
}
//Function to draw shape, will print a message
void draw()
{
cout<<Draw a rectangle;
}
void calculateArea()
{
cout<<Area:<<length*breadth;
}
};
class Circle:public Shape
{
int radius;
void setParameters()
{
cout<<Enter radius;
cin>>radius;
}
void displayParameters()
{
cout <<Radius is :<<radius;
}
void draw()
{
cout<<Draw Circle;
}

void calculateArea()
{
cout<<Area is:<<3.14*radius/2;
}
};
int main()
{
//use to test the implementation
//Ask user what he wants to draw and draw accordingly
Shape *shape;
cout <<Specify what you want to draw:
cout <<R for rectangle<<endl;
cout <<C for circle<<endl;
char choice;
cin>>choice;
switch(choice)
{
case R:
case r:
shape= new Rectangle();
break;
case C:
case c:
shape=new Circle();
}
shape.setParameters();
shape.displayParameters();
shape.calculateArea();
shape.draw();
}
=================================================================================
The following program demonstrates the concept of late binding:
#include <iostream>
class base
{
public:
virtual void func()
{
cout << "BASE" << endl;
}
};
class derived : public base
{
public:
void func()
{
cout << "DERIVED" << endl;
}
};
int main()
{
base *ptr;
int var;
cout << "Enter 1 or 2 : ";
cin >> var;
if (var == 1)
{
ptr = new base;
}
else
{
ptr = new derived;

}
ptr -> func(); // At compile time, the outcome of this statement
// is undeterminable - an example of late binding
return 0;
}
=================================================================================
#include <iostream>
class Animalia
{
public:
void breath()
// ordinary member function
{
cout << "Oxygen" << endl;
}
virtual void move() = 0;
// pure virtual function
};
class Fish : public Animalia
{
public:
void move()
{
cout << "Swim" << endl;
}
};
int main()
{
Animalia * ptr; // permitted
Animalia obj;
// ERROR: Abstract class cannot be instantiated
Fish gold;
gold.breath(); // displays Oxygen
gold.move();
// displays Swim
return 0;
}
=================================================================================
#include<iostream.h>
#include<conio.h>
class Person
{
protected:
char name[20];
char dateOfBirth[12];
char city[20];
char phoneNo[15];
public:
void accept()
{
cout<< endl << "ENTER First Name: ";
cin>>name;
cout << endl << "ENTER Date of Birth: ";
cin >> dateOfBirth;
cout << endl << "ENTER City: ";
cin>>city;
cout << endl << "ENTER Residence phone number: ";
cin >> phoneNo;
}
void display()
{
cout << endl << "First Name Is
: " << name;
cout << endl << "Date of birth Is
: " << dateOfBirth;
cout << endl << "City Is
: " << city;
cout << endl << "Residence number Is : " << phoneNo;
}

};
class Customer : public Person
{
private:
char billingAddress[30];
public:
void accept()
{
cout << endl << endl << "ENTER CUSTOMER'S DETAILS";
Person::accept();
cout << endl << "Customer's billing address: ";
cin.getline(billingAddress, 30);
}
void display()
{
cout << endl << endl << "CUSTOMER'S DETAILS ";
Person::display();
cout << endl << "Billing address
: " << billingAddress;
}
};
class Dealer : public Person
{
private:
char shopAddress[30];
int numSold;
public:
void accept()
{
cout << endl << endl << "ENTER DEALER'S DETAILS";
Person::accept();
cout << endl << "Shop address
: ";
cin.getline(shopAddress, 30);
cout << endl << "Number Sold
: ";
cin >> numSold;
}
void display()
{
cout << endl << endl << "DEALER'S DETAILS ";
Person::display();
cout << endl << "Shop address
: "
<< shopAddress;
cout << endl << "Number sold
: "
<< numSold << endl;
}
};
int main()
{
clrscr();
Person *ptr;
ptr = new Customer;
ptr->accept();
ptr->display();
ptr = new Dealer;
ptr->accept();
ptr->display();
return 0;
}
=================================================================================

#include<iostream.h>
class Furniture
{
protected:
int numberOfLegs;
int height;
int width;
int length;
public:
void display();
};
class Chair:public Furniture
{
public:
void display()
{
cout<< Chair;
}
};
class Table:public Furniture
{
public :
void display()
{
cout<< Table;
}
};
void display()
{
cout<< C for chair;
cout << T for table;
cout<< Q to quit;
}
int main()
{
Furniture *furniture;
char choice;
display();
cin>>choice;
while(choice!=Q)
{
switch(choice)
{
case T: furniture=new Table;
break;
case C: furniture=new Chair;
break;
default:
cout<< Invalid option. Enter
C, T, or Q<<endl;
}
furniture.display();
display();
cin>>choice;
}
}//end of main
===============================================================================

#include<iostream.h>
class RandomNumbers
{
int seed;
float count;
public:
//intialize the seed variable, by default to zero
RandomNumbers(int seed=0)
{
this.seed=seed;
//this will avoid calculating again and again
count=180.0/3.14;
}
//calculate a single random number
float random ()
{
return seed/count;
}
//calculate and display many random numbers
float displayRandom(int counter)
{
for(int i=1; i<counter; i++){
float random=seed/(count*I);
cout<<Random number is: <<random<<endl;
}
}
};
void displayMenu()
{
cout<<Want random numbers?(Y/N);
}
int main()
{
int choice;
int number;
displayMenu();
RandomNumbers randomNumber;//Moved out of loop
//To stop repeated instantiation
while(choice!=n||choice!=N)
{
cout << How many random numbers do you want?;
cin>>number;
if(number==1)
{
int random=randomNumber.random();
Cout<< Random number is :<<random;
}
else
{
randomNumber.displayRandom();
}
displayMenu();
cin>>choice;
}
}
=================================================================================

#include<iostream.h>
#include<conio.h>
.
class Book
{
protected:
char *bookName;
char *bookAuthor;
char *publisher;
char *isdnNumber;
int
numberOfPages;
float price;
public :
Book(char *name,char *author,char *publisher, char *number,
int pages, float
rate)
{
bookName=name;
bookAuthor=author;
this.publisher=publisher;
isdnNumber=number;
numberOfPages=pages;
price=rate;
}
void displayDetails()
{
cout<<\tTitle\tAuthor\tpublisher\tISDN
Number\tPages\tPrice\n;
cout<<bookName<<\t<<bookAuthor<<\t<<publisher
<<\t<<isdnNumber<<\t<<numberOfPages
<<\t<<price<<endl;
}
void setPrice(int price)
{
this.price=price;);
}
};
class TextBook
{
char

*subject;

public:
TextBook(char *name, char *author,char *publisher, char *number, int
pages,float rate, char *subject):Book(name,author,publisher, number,pages,rate){
this.subject=subject;
}
void displayDetails()
{
cout<<\tTitle\tAuthor\tsubject\tpublisher\tISDN
Number\tPages\tPrice\n;
cout<<bookName<<\t<<bookAuthor<<\t<<subject<<\tpublisher
<<\t<<isdnNumber<<\t<<numberOfPages
<<\t<<price<<endl;
}
};
class ReferenceBook
{

public:
ReferenceBook(char *name, char *author,char *publisher, char *number, int
pages,float rate):Book(name,author,publisher, number,pages,rate)
{
id setPrice(int price)
{
this.price=price;);
}
};
class StoryBook
{
char *type;
public:
StoryBook(char *name, char *author, char *publisher, char *number, int pages,float
rate, char * type):Book(name,author,publisher, number,pages,rate){
this.type=type;
}
void displayDetails()
{
cout<<\tTitle\tAuthor\tpublisher\tISDN Number\t
Pages\tPrice\tType\n;
cout<<bookName<<\t<<bookAuthor<<\t<<publisher
<<\t<<isdnNumber<<\t<<numberOfPages
<<\t<<price<<\t<<type<<endl;
}
};
=================================================================================
************************** late binding *****************************************
#include <iostream>
class device
{
protected:
int dev_no;
char dev_name[15];
public:
void getdata()
{
cout<<"Enter device number :: ";
cin>>dev_no;
cout<<"Enter device name
:: ";
cin>>dev_name;
}
void showdata()
{
cout<<dev_no;
cout<<dev_name;
}
};
class input: virtual public device
{
protected:
int speed_reading;
public:
void showdata()
{
device :: showdata();
cout<<speed_reading;
}
void getdata()
{
device ::getdata();
cout<< "Enter speed_reading :: ";

cin>>speed_reading;
}
};
class output: virtual public device
{
protected:
int speed_writing;
public:
void getdata()
{
device :: getdata();
cout<<"Enter speed of writing :: ";
cin>>speed_writing;
}
void showdata()
{
device :: showdata();
cout<<speed_writing;
}
};
class input_output_device: public input, public output
{
private:
int type;
public:
void showdata()
{
cout<<"\n\nInput Device";
input :: showdata();
cout<<"\n\nOutput Device";
output :: showdata();
cout<< type;
}
void getdata()
{
cout<<"\nEnter the data regarding Input Device\n";
input :: getdata();
cout<<"\nEnter the data regarding Output Device\n";
output :: getdata();
cout<<"Enter type ::
";
cin>>type;
}
};
int main()
{
char ch;
int ret =0;
input_output_device iod;
do
{
cout<<"\n1. Enter Device";
cout<<"\n2. Show Device";
cout<<"\n3. Exit";
cout<<"\n\nEnter the choice :: ";
cin>>ch;
switch(ch)
{
case '1':
iod.getdata();
ret=1;
break;

case '2':
iod.showdata();
ret=1;
break;
case '3':
ret=0;
break;
default:
ret=1;
break;
}
}while(ret);
return 0;
}
=================================================================================
#include <iostream.h>
class application
{
protected:
char appcode[4];
int storagespace;
public:
void getapp()
{
cout<<"enter application code:";
cin>>appcode;
cout<<"enter the storage requirement";
cin>>storagespace;
}
void showapp()
{
cout<<endl<<"Application code :"<<appcode<<endl;
cout<<"Storage space"<<storagespace<<endl;
}
};
class spellchecker:virtual public application
{
protected:
char lang[5];
public:
void getspell()
{
cout<<"enter the language:";
cin>>lang;
}
void showspell()
{
cout<<"Language:"<<lang<<endl;
}
};
class calculator:virtual public application
{
protected:
int noofoperations;
public:
void getcal()
{
cout<<"enter no of operations";
cin>>noofoperations;
}
void showcal()
{
cout<<"no of operations"<<noofoperations<<endl;

}
};
class spreadsheet : public spellchecker,public calculator
{
private:
int noofsheets;
public:
void getsheet()
{
getapp();
getspell();
getcal();
cout<<"enter no of sheets";
cin>>noofsheets;
}
void showsheet()
{
showapp();
showspell();
showcal();
cout<<"No of Sheets :"<<noofsheets<<endl;
}
};
int main()
{
spreadsheet s;
s.getsheet();
s.showsheet();
return 0;
}
=================================================================================
************************** ARRAY IN CLASSES *************************************
#include<iostream.h>
#include<conio.h>
class Customer
{
private:
char mobileNo[12];
char name[25];
char dateOfBirth[10];
char billingAdd[50];
char city[25];
char phoneNo[13];
float amountOutstanding;
public:
void print()
{
cout << endl << "\nMobile phone number: "<<mobileNo<< endl;
cout << "Name: "<< name << endl;
cout << "Date of Birth: "<< dateOfBirth << endl;
cout << "Billing Address: "<< billingAdd << endl;
cout << "City: "<< city << endl;
cout << "Residence phone number: "<< phoneNo << endl;
cout << "Amount due: "<< amountOutstanding << endl;
}
void get()
{
cout << "Mobile phone number: ";
cin >> mobileNo;
cout << endl << "Name: ";
cin >> name;
cout << endl << "Date of Birth: ";
cin >> dateOfBirth;

cout << endl << "Billing Address: ";


cin>>billingAdd;
cout << endl << "City: ";
cin >> city;
cout << endl << "Residence phone number: ";
cin >> phoneNo;
cout << endl << "Amount due: ";
cin >> amountOutstanding;
}
};
void main()
{
clrscr();
Customer object;
object.get();
clrscr();
object.print();
getch();
}
===============================================================================
********************** ARRANGE RECORD IN ASCENDING ORDER **********************
#include<iostream.h>
#include<conio.h>
class Customers
{
float amounts[10];
public:
void sortData()
{
int ctr;
for ( ctr = 0; ctr < 10; ctr ++ )
{
cout << "Enter the amount : ";
cin >> amounts[ctr];
if(amounts[ctr]==0)
{
cout<<"pl'z re-enter the amount : ";
cin>>amounts[ctr];
}
}
int counter=0;
/* Traverse The Array */
while(counter < 9)
{
float temp;
/* Compare The Value Of Current Element With The Next */
if(amounts[counter] < amounts[counter + 1])
{
/* Swap The Values */
temp = amounts[counter];
amounts[counter] = amounts[counter + 1];
amounts[counter + 1] = temp;
counter = 0;
continue;
}
counter++;
}
}

void display()
{
/* Display All The Array Elements */
for(int counter = 0;counter < 10; ++counter)
{
cout << "Element " << counter << ": " << amounts[counter]
<< endl;
}
}
};
int main()
{
clrscr();
Customers C1;
C1.sortData();
C1.display();
return 0;
getch();
}
=====================================================================================
=
=====================================================================================
=
************************************* FILE HANDLING
**********************************
#include <iostream.h>
#include<conio.h>
int main()
{
clrscr();
char str[10];
cout << "Input: ";
cin.get(str, 10, 'N'||'n');
cout << "Output:" << str << endl;
return 0;
}
==================================================================================
#include <iostream.h>
#include <fstream.h>
#include<conio.h>
class Customer
{
private:
char mobileNo[11];
char name[25];
char dateOfBirth[9];
char billingAddress[51];
char city[25];
char phoneNo[11];
float amountOutstanding;
public:
void print()
{
cout << endl << "Mobile phone number: ";
cout << mobileNo << endl;
cout << "\nName: ";
cout << name << endl;
cout << "\nDate of Birth: ";
cout << dateOfBirth<<endl;
cout << "\n\nCustomer's billing address: ";
cout << billingAddress<<endl;
cout << "\nCity: ";
cout << city << endl;

cout
cout
cout
cout

<<
<<
<<
<<

"\nResidence phone number: ";


phoneNo << endl;
"\nAmount due: ";
amountOutstanding << endl;

}
void get()
{
cout << "Mobile phone number: ";
cin >> mobileNo;
cin.ignore();
cout << endl << "Name: ";
cin.getline(name,25);
cout << endl << "Date of Birth: ";
cin >> dateOfBirth;
cin.ignore();
cout << endl << "Customer's billing address: ";
cin.getline(billingAddress,51);
cout << endl << "City: ";
cin.getline(city,25);
cout << endl << "Residence phone number: ";
cin >> phoneNo;
cout << endl << "Amount due: ";
cin >> amountOutstanding;
}
};
int main()
{
clrscr();
int ch;
Customer object;
while(1)
{
cout<< "\n \n Diaz Customer Tracking System\n";
cout<< "\n 1. Enter Customer Details\n";
cout << "\n 2. Display all records \n";
cout << "\n Enter your choice (0-2)\t";
cin>>ch;
if(ch==1)
{
ofstream ofile("customer.dat");
char reply = 'Y';
while(reply == 'Y' || reply == 'y')
{
cout << "Enter customer details " << endl;
object.get();
ofile.write((char *)&object,sizeof(object));
cout << "Do you wish to continue ?[Y/N]";
cin >> reply;
}
ofile.close();
}
if(ch==2)
{
ifstream ifile("customer.dat");
ifile.read((char *)&object, sizeof(object));
while(ifile) //Read Till The End Of The File
{
object.print();
ifile.read((char *)&object,sizeof(object));
}
ifile.close();
}

if(ch==0)
break;
}
return 0;
}
=============================================================================
#include <iostream>
#include <fstream>
#include <string>
class NRailways
{
private:
string pnr;
string pname;
string date_departure;
string to;
string from;
char status;
int No_of_Seats;
public:
void print()
{
cout<<"\n\n PNR Number
:\t"<<pnr;
cout<<"\n Passenger Name
:\t"<<pname;
cout<<"\n Date of Departure :\t"<<date_departure;
cout<<"\n Destination To
:\t"<<to;
cout<<"\n
From
:\t"<<from;
cout<<"\n Status of Booking :\t"<<status;
cout<<"\n # of Seats Reserved
:\t"<<No_of_Seats;
}
void get()
{
cout << "Enter the PNR Number:\t";
cin >> pnr;
cout << endl << "Enter Passenger Name:\t";
cin>>pname;
cout << endl << "Enter Date of Departure: \t";
cin >> date_departure;
cout << endl << "From:\t";
cin>>from;
cout << endl << "To:\t ";
cin>>to;
cout << endl << "Enter Status of Booking\t";
cin >> status;
cout << endl << "Enter # of Seats Reserved:\t";
cin >> No_of_Seats;
}
char getstatus()
{
return status;
}
};
int main()
{
int ch;
NRailways object;
while(1)
{
cout<< "\n \n Northern Railway System\n";
cout<< "\n 1. Enter Passenger Details \n";
cout << "\n 2. Print Confirmed Booking List \n";
cout << "\n Enter your choice (0-2)\t";
cin>>ch;

if(ch==1)
{
ofstream ofile("booking.dat");
char reply = 'Y';
while(reply == 'Y' || reply == 'y')
{
cout << "Enter Passenger Details " << endl;
object.get();
ofile.write((char *)&object,sizeof(object));
cout << "Do you wish to continue ?[Y/N]";
cin >> reply;
}
ofile.close();
}
if(ch==2)
{
ifstream ifile("booking.dat");
ifile.read((char *)&object, sizeof(object));
while(ifile) //Read Till The End Of The File
{
if(object.getstatus()=='C')
object.print();
ifile.read((char *)&object, sizeof(object));
}
ifile.close();
}
if(ch==0)
break;
}
return 0;
}
==================================================================================
#include <iostream>
#include <fstream>
#include <string>
class NRailways
{
private:
char pnr[6];
char pname[30];
char date_departure[9];
char to[40];
char from[40];
char status;
int No_of_Seats;
public:
NRailways()
{
pnr[0]='\0';
pname[0]='\0';
date_departure[0]='\0';
to[0]='\0';
from[0]='\0';
status=' ';
No_of_Seats=0;
}
void print()
{
cout<<"\n\n PNR Number
:\t"<<pnr;
cout<<"\n Passenger Name
:\t"<<pname;
cout<<"\n Date of Departure :\t"<<date_departure;

cout<<"\n Destination To
:\t"<<to;
cout<<"\n
From
:\t"<<from;
cout<<"\n Status of Booking :\t"<<status;
cout<<"\n # of Seats Reserved
:\t"<<No_of_Seats;
}
void get()
{
cout << "Enter the PNR Number:\t";
cin >> pnr;
cout << endl << "Enter Passenger Name:\t";
cin>>pname;
cout << endl << "Enter Date of Departure: \t";
cin >> date_departure;
cout << endl << "From:\t";
cin>>from;
cout << endl << "To:\t ";
cin>>to;
cout << endl << "Enter Status of Booking\t";
cin >> status;
cout << endl << "Enter # of Seats Reserved:\t";
cin >> No_of_Seats;
}
char getstatus()
{
return status;
}
char *getpnr()
{
return pnr;
}
void setstatus()
{
char choice;
cout<<"\n\n Do you want to cancel the Booking?\t";
cin>>choice;
if(choice=='y' || choice=='Y')
status='R';
}
};
int main()
{
int ch;
while(1)
{
cout<< "\n \n Northern Railway System\n";
cout<< "\n 1. Enter Passenger Details\n";
cout<< "\n 2. Query Passenger Details \n";
cout<< "\n 3. Cancel the Booking \n";
cout<< "\n 4. Print Confirmed Booking List\n";
cout << "\n Enter your choice (0-4)\t";
cin>>ch;
if(ch==1)
{
NRailways object;
fstream ofile("booking1.dat",ios::app);
cout << "Enter Passenger Details " << endl;
object.get();
ofile.write((char *)&object,sizeof(object));
ofile.close();
}
if(ch==2)
{
NRailways object;

ifstream ifile("booking1.dat");
char pnr[6];
cout<<"\n\n Enter the PNR Number:\t";
cin>>pnr;
ifile.seekg(0,ios::beg);
ifile.read((char *)&object, sizeof(object));
while(ifile) //Read Till The End Of The File
{
char temp[6];
strcpy(temp,object.getpnr());
if(strcmp(temp,pnr)==0)
{
object.print();
break;
}
ifile.read((char *)&object, sizeof(object));
}
ifile.close();
}
if(ch==3)
{
NRailways o;
fstream ie("booking1.dat",ios::in|ios::out);
char pnr[6];
int pos;
cout<<"\n\n Enter the PNR Number:\t";
cin>>pnr;
ie.read((char *)&o, sizeof(o));
while(ie) //Read Till The End Of The File
{
char temp[6];
pos=ie.tellg();
strcpy(temp,o.getpnr());
if(strcmp(temp,pnr)==0)
{
o.setstatus();
ie.seekp(pos-sizeof(o),ios::beg);
ie.write((char*)&o,sizeof(o));
ie.close();
break;
}
else
ie.read((char *)&o, sizeof(o));
}
ie.close();
}
if(ch==4)
{
NRailways object;
ifstream ifile("booking1.dat");
ifile.read((char *)&object, sizeof(object));
while(ifile) //Read Till The End Of The File
{
if(object.getstatus()=='C'||object.getstatus()=='c')
object.print();
ifile.read((char *)&object, sizeof(object));
}
ifile.close();
}
if(ch==0)
break;
}
return 0;
}

==============================================================================
#include <string>
#include <iostream>
#include <fstream>
class Customer
{
private:
char mobileNo[11];
char name[25];
char dateOfBirth[9];
char billingAddress[51];
char city[25];
char phoneNo[11];
float amountOutstanding;
public:
Customer()
{
mobileNo[0]='\0';
name[0]='\0';
dateOfBirth[0]='\0';
billingAddress[0]='\0';
city[0]='\0';
phoneNo[0]='\0';
amountOutstanding=0;
}
void print()
{
cout << endl << "Mobile phone number: ";
cout << mobileNo << endl;
cout << "\nName: ";
cout << name << endl;
cout << "\nDate of Birth: ";
cout << dateOfBirth<<endl;
cout << "\n\nCustomer's billing address: ";
cout << billingAddress<<endl;
cout << "\nCity: ";
cout << city << endl;
cout << "\nResidence phone number: ";
cout << phoneNo << endl;
cout << "\nAmount due: ";
cout << amountOutstanding << endl;
}
void get()
{
cout << "Mobile phone number: ";
cin >> mobileNo;
cin.ignore();
cout << endl << "Name: ";
cin.getline(name,25);
cout << endl << "Date of Birth: ";
cin >> dateOfBirth;
cin.ignore();
cout << endl << "Customer's billing address: ";
cin.getline(billingAddress,51);
cout << endl << "City: ";
cin.getline(city,25);
cout << endl << "Residence phone number: ";
cin >> phoneNo;
cout << endl << "Amount due: ";
cin >> amountOutstanding;
}
char *getmbno()
{
return mobileNo;
}

};
int main()
{
int ch;
Customer object;
while(1)
{
cout<< "\n \n Diaz Customer Tracking System\n";
cout<< "\n 1. Enter Customer Details\n";
cout << "\n 2. Display all records \n";
cout <<" \n 3. Query \n";
cout << "\n Enter your choice (0-3)\t";
cin>>ch;
if(ch==1)
{
ofstream ofile("customer.dat");
cout << "Enter customer details " << endl;
object.get();
ofile.write((char *)&object,sizeof(object));
ofile.close();
}
if(ch==2)
{
ifstream ifile("customer.dat");
ifile.read((char *)&object, sizeof(object));
while(ifile) //Read Till The End Of The File
{
object.print();
ifile.read((char *)&object, sizeof(object));
}
ifile.close();
}
if(ch==3)
{
Customer c1;
ifstream ie("customer.dat");
char mbno[11];
int pos;
cout<<"\n\n Enter the Mobile Number:\t";
cin>>mbno;
ie.read((char *)&c1, sizeof(c1));
while(ie) //Read Till The End Of The File
{
char temp[11];
strcpy(temp,c1.getmbno());
if(strcmp(temp,mbno)==0)
{
c1.print();
break;
}
else
ie.read((char *)&c1, sizeof(c1));
}
ie.close();
}
if(ch==0)
break;
}
return 0;
}
==============================================================================

#include <iostream>
class device
{
protected:
int dev_no;
char dev_name[15];
public:
void getdata()
{
cout<<"Enter device number :: ";
cin>>dev_no;
cout<<"Enter device name
:: ";
cin>>dev_name;
}
void showdata()
{
cout<<dev_no;
cout<<dev_name;
}
};
class input: virtual public device
{
protected:
int speed_reading;
public:
void showdata()
{
device :: showdata();
cout<<speed_reading;
}
void getdata()
{
device ::getdata();
cout<< "Enter speed_reading :: ";
cin>>speed_reading;
}
};
class output: virtual public device
{
protected:
int speed_writing;
public:
void getdata()
{
device :: getdata();
cout<<"Enter speed of writing :: ";
cin>>speed_writing;
}
void showdata()
{
device :: showdata();
cout<<speed_writing;
}
};
class input_output_device: public input, public output
{
private:
int type;
public:
void showdata()
{
cout<<"\n\nInput Device";
input :: showdata();

cout<<"\n\nOutput Device";
output :: showdata();
cout<< type;
}
void getdata()
{
cout<<"\nEnter the data regarding Input Device\n";
input :: getdata();
cout<<"\nEnter the data regarding Output Device\n";
output :: getdata();
cout<<"Enter type ::
";
cin>>type;
}
};
int main()
{
char ch;
int ret =0;
input_output_device iod;
do
{
cout<<"\n1. Enter Device";
cout<<"\n2. Show Device";
cout<<"\n3. Exit";
cout<<"\n\nEnter the choice :: ";
cin>>ch;
switch(ch)
{
case '1':
iod.getdata();
ret=1;
break;
case '2':
iod.showdata();
ret=1;
break;
case '3':
ret=0;
break;
default:
ret=1;
break;
}
}while(ret);
return 0;
}
===================================================================================
#include<fstream>
int main()
{
int i=0;
char fname[15];
cout<<"Enter the file name :";
cin>>fname;
char ch;
ifstream ifile(fname);
while(ifile)
{
ifile.get(ch);
if(ch >='A' && ch <='Z') //convert all uppercase alphabets to lowercase
{
ch=ch+32;//so that you can check only lowercase vowels

}
switch(ch)
{
case 'a' :i=i+1;
break;
case 'e': i=i+1;
break;
case 'i': i=i+1;
break;
case 'o' :i=i+1;
break;
case 'u': i=i+1;
break;
}
}
cout<<"The total count of alphabets is: "<<i;
}
=================================================================================
#include<fstream>
int main()
{
char fname[15];
cout<<"Enter the file name :";
cin>>fname;
char ch;
ifstream ifile(fname);
while(ifile)
{
ifile.get(ch);
if(ch>='a' && ch<='z') // In case the file contains any lower case
//alphabets
{
ch=ch-32;
}
cout<<ch;
};
cout<<endl;
}
================================================================================
#include<fstream>
class fileoperation
{
char fname[15];
int i;
char ch;
public:
void fileopen();
void vowel();
void chgcase();
};
void fileoperation::fileopen()
{
cout<<"Enter the file name :";
cin>>fname;
ifstream ifile(fname);
}
void fileoperation::vowel()
{
i=0;
ifstream ifile(fname);
while(ifile)
{
ifile.get(ch);

if(ch >='A' && ch <='Z') //convert all uppercase alphabets to


//lowercase
{
ch=ch+32;//so that you can check only lowercase vowels
}
switch(ch)
{
case 'a' :i=i+1;
break;
case 'e': i=i+1;
break;
case 'i': i=i+1;
break;
case 'o' :i=i+1;
break;
case 'u': i=i+1;
break;
}
}
cout<<"The total count of alphabets is: "<<i;
void fileoperation::chgcase()
{
ifstream ifile(fname);
while(ifile)
{
ifile.get(ch);
if(ch>='a' && ch<='z') // In case the file contains any lower case
//alphabets
{
ch=ch-32;
}
cout<<ch;
};
cout<<endl;
}
int main()
fileoperation f1;
{
fileoperation f1;
f1.fileopen();
f1.vowel();
f1.chgcase();
}
==============================================================================

Das könnte Ihnen auch gefallen