C++ Coding Tutorial



Introduction to C++ : How to code C++



Turbo C++ Importance



C++ Tutorial Advance Method



New Features in the Next C++ Standard



C++ Templates For Generic Programming



Write a C++ Program for Vector

/*write a class to represent a vector (a series of float values).
Include member functions to perform the following tasks:
1)To Create the Vector
2)To modify the value of a given element
3)To multiply by a scalar value.
4)To display the vector in the form (10,20,30....)
Write a program to test your class*/

#include
#include

int const size=50;

class vector
{
float d[size];
int s;
public:
void create(void);
void modify(void);
void multiply(void);
void display(void);
};

void vector :: create(void)
{
cout<<"\n\nEnter of Array you want to create:-";
cin>>s;
cout<<"Enter "<for(int i=0;i cin>>d[i];
}

void vector :: modify(void)
{
int mfy_value;
float with;
cout<<"\nEnter Value is to be modified:-";
cin>>mfy_value;
cout<<"Enter Value with which you want to Replace:-";
cin>>with;
int search=0;
for(int i=0;search{
if(mfy_value==d[i])
{
d[i]=with;
}
search=i+1;
}
}

void vector :: multiply(void)
{
int mul;
cout<<"\nEnter value with which you want to multiply:-";
cin>>mul;
for(int i=0;i d[i]=d[i]*mul;
}

void vector :: display(void)
{
cout<<"\n\nDisplay of Array\n";
cout<<"(";
for(int i=0;i{
cout< if(i!=s-1)
cout<<",";
}
cout<<")";
}

void main()
{
clrscr();
vector o1;
int choice;
do
{
cout<<"\n\nChoice List\n";
cout<<"1) To Create Vector Array\n";
cout<<"2) To Modify Array\n";
cout<<"3) To Multiply with Scalar value\n";
cout<<"4) To Display\n";
cout<<"5) EXIT\n";
cout<<"Enter your choice:-";
cin>>choice;
switch(choice)
{
case 1: o1.create();
break;
case 2: o1.modify();
break;
case 3: o1.multiply();
break;
case 4: o1.display();
break;
case 5:goto end;
}
}while(1);
end:
}



C++ Program for Unary Operator minus

//Unary Operator minus
#include
#include

class minus
{
int d1,d2,d3;
public:
minus()
{d1=d2=d3=0;}
minus(int a,int b,int c)
{
d1=a;
d2=b;
d3=c;
}
void display(void)
{
cout< }
void operator - ()
{
d1=-d1;
d2=-d2;
d3=-d3;
}
};

void main()
{
clrscr();
minus o1,o2(2,4,6);

-o1;
cout<<"\nData of Object 1 : ";
o1.display();

-o2;
cout<<"\n\nData of Object 2 : ";
o2.display();

getch();
}



C++ Program to generate Triangle

#include
#include
#include
void main()
{
int i,j,num,c;
clrscr();
cout<<"Enter number:-";
cin>>num;
cout<for(c=2,i=num;i>0;i--)
{
cout<
for(j=1;j<=1;j++)
{
cout< }
c=c+2;
cout<<"\n";
}
getch();
}



C++ Program for DYNAMIC MEMORY ALLOCATION

//DYNAMIC MEMORY ALLOCATION
#include
#include

class matrix
{
int ***p,d1,d2,d3;
public:
matrix(){}
matrix(int a,int b,int c);
void getdata();
void display();
};

matrix :: matrix(int a,int b,int c)
{
d1=a;
d2=b;
d3=c;
p=new int **[d1];
for(int i=0;i {
p[i]=new int *[d2];
for(int j=0;j p[i][j]=new int [d3];
}
}

void matrix :: getdata(void)
{
cout<<"\n\nEnter data "< for(int i=0;i {
for(int j=0;j {
for(int k=0;k cin>>p[i][j][k];
}
}
}

void matrix :: display(void)
{
cout<<"\n\n\nDisplay function\n";
for(int i=0;i {
for(int j=0;j {
for(int k=0;k cout< }
cout< }
}

void main()
{
clrscr();
matrix o1;
o1.getdata();
o1.display();
getch();
}



C++ Class Template for vector operations.

//Class Template for vector operations.


#include
#include

template
class vector
{
T *arr;
int size;

public:

vector() {
arr=NULL;
size=0;
}

vector(int m);
vector(T *a,int n);
void modify(T value,int index);
void multiply(int scalarvalue);
void display();
};

template
vector :: vector(int m)
{
size=m;
arr = new T[size];
for(int i=0;i arr[i]=0;
}

template
vector :: vector(T *a,int n)
{
size=n;
arr = new T[size];
for(int i=0;i arr[i]=a[i];
}


template
void vector :: modify(T value,int index)
{
arr[index]=value;
}


template
void vector :: multiply(int scalarvalue)
{
for(int i=0;i arr[i] = arr[i] * scalarvalue;
}

template
void vector :: display()
{
cout<<"(";
for(int i=0;i {
cout< if(i!=size-1)
cout<<", ";
}
cout<<")";
}


void main()
{
clrscr();


//Creating Integer Vector.
int iarr[]={1,2,3,4,5};
vector v1(iarr,5); //Integer array with 5 elements.
cout<<"\nInteger Vector : ";
v1.display();
cout<<"\n\nModify index 3 with value 15\n";
v1.modify(15,3); //modifying index 3 with value 15.
cout<<"After Modification : ";
v1.display();
cout<<"\n\nMultiply with scalar value : 10\n";
v1.multiply(10); //Multiply with scalar value 10.
cout<<"After Multiplying : ";
v1.display();
cout<<"\n\n";


//Creating double Vector.
double darr[]={1.1,2.2,3.3,4.4,5.5};
vector v2(darr,5); //Double array with 5 elements.
cout<<"\nDouble Vector : ";
v2.display();
cout<<"\n\nModify index 0 with value 9.9 \n";
v2.modify(9.9,0); //modifying index 0 with value 9.9.
cout<<"After Modification : ";
v2.display();
cout<<"\n\nMultiply with scalar value : 10\n";
v2.multiply(10); //Multiply with scalar value 10.
cout<<"After Multiplying : ";
v2.display();
cout<<"\n\n";

getch();



}



C++ Template for finding Minimum value in an array

//Template for finding Minimum value in an array

#include
#include

template
T findMin(T arr[],int n)
{
int i;
T min;
min=arr[0];
for(i=0;i {
if(min > arr[i])
min=arr[i];
}
return(min);
}


void main()
{
clrscr();
int iarr[]={5,4,3,2,1};
char carr[]={'z','y','c','b','a'};
double darr[]={3.3,5.5,2.2,1.1,4.4};

//calling Generic function...to find minimum value.
cout<<"Generic Function to find Minimum from Array\n\n";
cout<<"Integer Minimum is : "< cout<<"Character Minimum is : "< cout<<"Double Minimum is : "<
getch();
}



sum of 10 integers

//sum of 10 integers

#include
#include

class addition
{
int data;
public:
addition() //constructor
{data=0;}

void getdata(addition o1)
{cout<<"\nEnter Your Data :-";
int sum;
cin>>sum;
data=data+sum;
}

void display(void)
{ cout<<"\nSum of Data is :-"<};


void main()
{
clrscr();
addition o1;
for(int i=0;i<10;i++)
{
o1.getdata(o1);
}
o1.display();
getch();
}



Write a C++ Program for String concatenation using + operator and String Comparision using <= operator

//String concatenation using + operator
//String Comparision using <= operator #include
#include
#include

class string
{
char *p;
int len;
public:
string()
{}

string(char *a)
{
len=strlen(a);
p=new char[len+1];
strcpy(p,a);
}

string operator + (string o2)
{
string temp;
temp.len=len+o2.len;
temp.p = new char[temp.len + 1];
strcpy(temp.p,p);
strcat(temp.p,o2.p);
return temp;
}

int operator <= (string o2)
{
if(len <= o2.len)
return(1);
else
return(0);
}

void display(void)
{
cout<
}
};


void main()
{
clrscr();
string o1("Vivek"),o2("Patel"),o3;

o1.display();
cout<
o2.display();
cout<<

o3=o1+o2;

cout<<"After String Concatenation : ";
o3.display();
cout<<<

string s1("New Delhi"),s2("New York");
if(s1<=s2)
{
s1.display();
cout<<" is smaller than ";
s2.display();
}
else
{
s2.display();
cout<<" is smaller than ";
s1.display();
}

getch();
}



C++ Coding Tutorial



Write a C++ Program demonstrating Operator Overloading demo2

#include
#include

const size = 3;

class vector
{
int v[size];
public:
vector();
vector (int *x);
friend vector operator * (int a,vector b);
friend vector operator * (vector b,int a);
friend istream & operator >> (istream &amp;,vector &);
friend ostream & operator << (ostream &amp;,vector &); }; vector :: vector() { for(int i=0;i> (istream & din,vector & b)
{
for(int i=0;i>b.v[i];
return(din);
}

ostream & operator << (ostream &amp; dout,vector & b) { dout<<"(";//<<<", "<<<")"; return(dout); } int x[size] = {2,4,6}; void main() { clrscr(); vector m; vector n=x; cout<<"Enter elements of vector m \n"; cin>>m;
cout<
cout<<"m="<<

vector p,q;
p=2*m;
q=n*2;

cout<
cout<<"p="<

<
cout<<"q="<<
getch();
}



Write a C++ Program demonstrating Operator Overloading

#include
#include

class distance
{
int feet;
float inches;
public:

distance() //constructor1
{feet=0;inches=0;}
distance(int ft,float inch) //constructor2
{feet=ft;inches=inch;}

void getdata()
{ cout<<"Enter Feet and inches respectively: "; cin>>feet>>inches;
}

void display()
{ cout<<"Feet : "<<<<"Inches :"<< (distance &ob1, distance &ob2); friend int operator > (distance &ob1, distance &ob2);
friend istream & operator >> (istream &din, distance &ob3);
friend ostream & operator << (ostream &dout, distance &ob3); }; distance operator +(distance &ob1, distance &ob2) { distance temp; temp.feet = ob1.feet + ob2.feet; temp.inches = ob1.inches + ob2.inches; if(temp.inches > 12)
{
temp.inches -= 12;
temp.feet++;
}
return(temp);
}

distance operator -(distance &ob1, distance &ob2)
{
distance temp;
float ob1inch,ob2inch;
ob1inch = (ob1.feet * 12) + ob1.inches;
ob2inch = (ob2.feet * 12) + ob2.inches;
temp.inches = ob1inch - ob2inch;
temp.feet = temp.inches/12;
temp.inches = temp.inches - (temp.feet * 12);
return(temp);
}

distance operator *(int d, distance &ob)
{
distance temp;
float i;
temp.feet = d * ob.feet;
temp.inches = d * ob.inches;
i = temp.inches/12;
temp.feet = temp.feet + i;
temp.inches = temp.inches-(i*12.0);
return(temp);
}

int operator ==(distance &ob1, distance &ob2)
{
if(ob1.feet == ob2.feet && ob1.inches == ob2.inches)
return(1);
else
return(0);
}

int operator < (distance &ob1, distance &ob2) { if(ob1.feet <> (distance &ob1, distance &ob2)
{
if(ob1.feet > ob2.feet && ob1.inches > ob2.inches)
return(1);
else
return(0);
}

istream & operator >> (istream &din, distance &ob3)
{
cout<<"\nEnter Data for Object3\n"; cout<<"Enter Feet : "; din>>ob3.feet;
cout<<"Enter Inches : "; din>>ob3.inches;
return(din);
}

ostream & operator << (ostream &dout, distance &ob3) { dout<<"\nData of OBJECT3\n"; dout<<"\nFeet :"<<<"\nInches :"<<<"\n=====Enter Data for OBJECT1=====\n"; ob1.getdata(); cout<<"\n\n=====Enter Data for OBJECT2=====\n"; ob2.getdata(); int choice,data; while(1) { up: clrscr(); cout<<"=====Display for OBJECT1=====\n"; ob1.display(); cout<<"\n=====Display for OBJECT2=====\n"; ob2.display(); cout<<<"\nChose your choice\n"; cout<<"1) Addition ( + )\n"; cout<<"2) Subtraction ( - )\n"; cout<<"3) Multiplication ( * )\n"; cout<<"4) Comparision ( == )\n"; cout<<"5) Comparision ( < )\n"; cout<<"6) Comparision ( > )\n";
cout<<"7) Input ( >> )\n";
cout<<"8) Output ( << )\n"; cout<<"Enter your choice:-"; cin>>choice;
cout<<<<"\nEnter integer to be multiplied:-"; cin>>data;
ob3 = data * ob1;
break;
case 4 : if(ob1 == ob2)
{ cout<<"\nBoth Objects are equal or same value\n";} else { cout<<"\nThey are Unequal\n";} getch(); goto up; case 5 : if(ob1 <> ob2)
{ cout<<"\nObject1 is Greater than Object2\n";} else { cout<<"\nObject2 is Greater than Object1\n";} getch(); goto up; case 7 : cout<<"\nInputing Data in\n"; cin>>ob3;
break;
case 8 : cout<<"\nOutputing Data out\n";
cout<
break;
default : cout<<"\n\nHave a nice day....\n";
getch();
goto out;
}
cout<<"\n\nResult in OBJECT3 as under\n";
ob3.display();
getch();
}
out:
}





Write a C++ Program demonstrating nested structure

//To Enter Few Records and to sort according to the choice of
//the data member. (USING NESTED STRUCTURE)

#include
#include
#include

//GLOBAL DECLARATION OF STRUCTURE
struct date
{
int year,month,day;
};

struct person
{
int recno;
char name[20];
date dob; //using date structure as datatype
int salary;
};

void line(void); //Global Declaration of function as it is called in another function other than main.


void main()
{
void starting(void);
void sorting(struct person[],int);
void display(struct person[]);
void end(void);
person rec[5]; //Declaration of person datatype

starting();

textcolor(111);
textbackground(196);
clrscr();
cout<<"\n\n"<<<"RECORD INFORMATION"; //for inserting records cout<<"\n\n\n\n\tEnter 5 Records\n\n\n\n"; for(int i=0,c=1;i<5;i++)><<<"\n\nEnter Record Number:-"; cin>>rec[i].recno;
cout<<"Enter Name :-"; cin>>rec[i].name;
cout<<"\nFOR Birth_Date\n"; cout<<"--------------\n"; cout<<"Enter Year:-"; cin>>rec[i].dob.year;
cout<<"Enter Month:-"; cin>>rec[i].dob.month;
cout<<"Enter Day:-"; cin>>rec[i].dob.day;
cout<<"\nEnter salary:-"; cin>>rec[i].salary;
line();
cout<<<<<<<<"\n\nWhat Operation Would you Like to Perform\n"; cout<<"1) sort by Record Number\n"; cout<<"2) sort by Name\n"; cout<<"3) sort by Date\n"; cout<<"4) sort by Salary\n"; cout<<"5) DISPLAYING\n"; cout<<"6) QUIT\n"; cout<<"Enter Your Choice:-"; cin>>choice;
switch(choice)
{
case 1:
case 2:
case 3:
case 4:sorting(rec,choice);
break;
case 5:display(rec);
break;
case 6:goto out;
default:cout<<"Entered Choice is Invalid, Try Again"; } getch(); clrscr(); }while(1); out: } //sorting function void sorting(struct person rec[],int choice) { struct person tempq; //record Number wise Sorting if(choice==1) { for(int i=0;i<5;i++) j="i+1;j<5;j++)"> rec[j].recno)
{
tempq = rec[i];
rec[i] = rec[j];
rec[j] = tempq;
}
}
}
}


//namewise sorting

if(choice==2)
{
for(int i=0;i<5;i++) j="i+1;j<5;j++)">0)
{
tempq = rec[i];
rec[i] = rec[j];
rec[j] = tempq;
}
}
}
}

//datewise
if(choice==3)
{
for(int i=0;i<5;i++) j="i+1;j<5;j++)"> rec[j].dob.year)
{
tempq = rec[i];
rec[i] = rec[j];
rec[j] = tempq;

if(rec[i].dob.month > rec[j].dob.month)
{
tempq = rec[i];
rec[i] = rec[j];
rec[j] = tempq;

if(rec[i].dob.day > rec[j].dob.day)
{
tempq = rec[i];
rec[i] = rec[j];
rec[j] = tempq;
}

}
}
}
}
}


//for salary wise

if(choice==4)
{
for(int i=0;i<5;i++) j="i+1;j<5;j++)"> rec[j].salary)
{
tempq = rec[i];
rec[i] = rec[j];
rec[j] = tempq;
}
}
}
}

}



//display function
void display(struct person rec[])
{
textcolor(106);
textbackground(104);
clrscr();
cout<<<
line();
cout<<<"Record No."<<<"NAME OF PERON"<<<"DATE OF BIRTH"<<<"SALARY AT PRESENT"<
line();
for(int i=0;i<5;i++)
{
cout<
cout<<
cout<<
cout<<<<"\\"<<<"\\"<
cout<<
cout<
}
getch();
}


//Line function
void line(void)
{
for(int i=0;i<40;i++)
{
cout<<"--";
}
cout<
}


//Starting function
void starting(void)
{
//START OF programer details\\
textcolor(105);
textbackground(104);
clrscr();
cout<
cout<<"|";
for(int i=0;i<39;i++)
{
cout<<"--";
}
cout<<"|";

cout<<" ";
for(int i=0;i<34;i++)
cout<<"=";

cout<<"VIVEK PATEL";

for(int i=0;i<33;i++)
cout<<"=";

cout<

cout<<"|";
for(int i=0;i<39;i++)
{
cout<<"--";
}
cout<<"|";
cout<<<
line();
cout<<<"WELLCOME VIEWERS\n";
line();
cout<<<"SAMPLE DATABASE APPLICATION\n\n";
line();
line();
cout<<<"Created By VIVEK PATEL\n\n";
line();
line();
cout<<<"EMAIL US AT VIVEK_P9@HOTMAIL.COM";
getch();

//END OF PROGRAMMER DETAILS\\
}



Write a C++ Program for MAKING FILE PROGRAM WITH USING ALL MODES

//MAKING FILE PROGRAM WITH USING ALL MODES

#include
#include
#include

static int totrec=0; //totrec variable keep track for total variable entered
//Initially Record scanned are Zero

void main()
{
int choice;
while(1)
{
clrscr();
cout<<"Choose your choice\nNOTE : one choice for one record(except viewing data)\n"; cout<<"1) Scanning intial records\n"; cout<<"2) Appending records\n"; cout<<"3) Modifying or append records\n"; cout<<"4) Viewing records\n"; cout<<"5) Exit\n"; cout<<"Enter your choice : "; cin>>choice;
switch (choice)
{
case 1 : {
ofstream outfile;
outfile.open("emp",ios::out);
cout<<"\n\nPlease enter the details as per demanded\n"; cout<<"\nEnter the name : "; char name[20]; cin>>name;
outfile<<<<"Enter Age : "; int age; cin>>age;
outfile<<<<"Enter programming language known by him\her : "; char lang[25]; cin>>lang;
outfile<<<<"\n\nPlease enter the details as per demanded\n"; cout<<"\nEnter the name : "; char name[20]; cin>>name;
outfile<<<<"Enter Age : "; int age; cin>>age;
outfile<<<<"Enter programming language known by him : "; char lang[25]; cin>>lang;
outfile<<<<"Are you interested in adding record\nenter y or n\n"; char ans; cin>>ans;
if(ans=='y' || ans=='Y')
{
cout<<"\n\nPlease enter the details as per demanded\n"; cout<<"\nEnter the name : "; char name[20]; cin>>name;
outfile<<<<"Enter Age : "; int age; cin>>age;
outfile<<<<"Enter programming language known by him : "; char lang[25]; cin>>lang;
outfile<< 0)
{
infile.getline(line,size);
cout<<"\n\nNAME : "<<
infile.getline(line,size);
cout<<"AGE : "<<
infile.getline(line,size);
cout<<"LANGUAGE : "<<
counter--;
}
infile.close();
}
getch();
break;
case 5 : goto out;
default : cout<<"\nInvalid Choice\nTRY AGAIN\n";
}
}
out:
}



Write a C++ Program for MATRIX ADDITION, through Pointers implementation

//MATRIX ADDITION
//Pointers implementation through pointers
#include
#include
#include

class matrix
{
int **p,row,col;
public:
void getdata(void);
friend void matrixadd(matrix &,matrix &amp;amp;amp;amp;amp;);
void display(void);
};

void matrix :: getdata(void)
{
clrscr();
cout<<"Enter Size of Row:-"; cin>>row;
p=new int *[row];
cout<<"Enter size of Coulumn:-"; cin>>col;
cout<<"\nEnter Data for Matrix of size "<<<"*"<< i = "0;i < row;i++)" scaning="" value="" a="0;a < row;a++)" int="" b="0;b < col;b++)" cin="">> p[a][b];
}
}
}


void matrix :: display(void)
{
cout<<"\n\n\n\n"; cout<<"Display Function\n\n"; for(int i=0;i
{
for(int j=0;j
{
cout<<
}
cout<
}
}

void matrixadd(matrix &a,matrix &b)
{
int result[10][10];
if(a.row==b.row &&amp;amp;amp;amp;amp; a.col==b.col)
{
for(int i=0;i
{
for(int j=0;j
{
result[i][j]=a.p[i][j]+b.p[i][j];
}
}
//displaying
for(int x=0;x
{
for(int y=0;y
{
cout<<
}
cout<
}
}
else
cout<<"Invalid Matrix Addition Occurs as size differs\n"; } void main() { matrix o1,o2; o1.getdata(); o2.getdata(); clrscr(); o1.display(); o2.display(); getch(); clrscr(); cout<<"\n\nAfter Adition Has been Performed\n\n"; matrixadd(o1,o2); getch(); }



Write a C++ Program for Matrix Addition by Overloading + operator

//Matrix Addition by Overloading + operator

#include
#include

class matadd
{
int **a;
int row,col;
public:
matadd(){}
matadd(int r,int c);
void getdata(void);
void display(void);
matadd operator + (matadd o2);
};

matadd :: matadd(int r,int c)
{
row=r;
col=c;
a=new int *[row];
for(int i=0;i<<"\n\nEnter Data for "<<<" rows and "<<<" cols\n\n"; for(int i=0;i>a[i][j];
}
}

void matadd :: display(void)
{
cout<<"\n\n\nMatrix Display\n\n";
for(int i=0;i
{
for(int j=0;j
cout<<<" ";
cout<
}
}

matadd matadd :: operator + (matadd o2)
{
matadd temp(row,col);
for(int i=0;i
{
for(int j=0;j
{
temp.a[i][j]=a[i][j] + o2.a[i][j];
}
}
return temp;
}

void main()
{
clrscr();
matadd o1(3,2),o2(3,2),o3;

o1.getdata();
o2.getdata();

o3=o1+o2;

o3.display();

getch();
}



Write a C++ Program for displaying logical output

#include
#include
void main()
{
int i,j,num,space,k;
clrscr();
printf("Enter the number:-");
scanf("%d",&num);
k=num;
for(i=num;i>=0;i--)
{

for(space=k;space>0;space--)
{
printf(" ");
}

for(j=num -(i-1);j>=1;j--)
{



printf("%d ",i);
}
printf("\n");
k--;
}

getch();
}



Write a C++ Program for displaying logical output

#include
#include
void main()
{
int i,j,num,space,k;
clrscr();
printf("Enter the number:-");
scanf("%d",&num);
k=num;
for(i=num;i>=0;i--)
{

for(space=k;space>0;space--)
{
printf(" ");
}

for(j=num -(i-1);j>=1;j--)
{



printf("%d ",i);
}
printf("\n");
k--;
}

getch();
}



Write a C++ Program for Library database : Linked List with New Operator

//Library Database
#include
#include
#include
#include

class books
{
char **author,**title,**publisher;
int *price;
static int count;
public:

books(void); //constructor
void getdata(void);
void display_stock(void);
void search(void);
};

int books :: count=0;

books :: books(void)
{
author=new char*[15];
title=new char*[15];
publisher=new char*[15];
price=new int[15];
for(int i=0;i<15;i++)>>title[count];
cout<<"Enter Author name:-"; cin>>author[count];
cout<<"Enter Publisher of book:-"; cin>>publisher[count];
cout<<"Enter Price of book:-"; cin>>price[count];
count++;
}

void books :: display_stock(void)
{
clrscr();
cout<<"\n\n\n"; cout<<<"Book Name"<<<"Author Name"<<<"Publisher"<<<"Price"<<<<<<<<<<<<<"\n\nTotal Number of Books are "<<<"\n\n\nEnter Book name:-"; cin>>name;
cout<<"Enter Author of Book:-"; cin>>writer;
for(int i=0;i<<"\n\nEntered Information Book Available\n"; cout<<"Price of that book is "<<<"\n\nBook is not Available in stock\n"; skip: } void main() { clrscr(); books o1; int choice; while(1) { cout<<"\n\nChoose your choice\n"; cout<<"1) Entering Information for book\n"; cout<<"2) To See Actual stock\n"; cout<<"3) To Search for a Particular book\n"; cout<<"4) Exit\n"; cout<<"Enter your choice:-"; cin>>choice;
switch(choice)
{
case 1 : o1.getdata();
break;
case 2 : o1.display_stock();
break;
case 3 : o1.search();
break;
case 4 : goto out;
default: cout<<"\n\nEnter choice is invalid\nTry again\n";
}
}
out:
}



Write a C++ Program for Library database : Linked List

//Library Database

#include
#include
#include

struct library
{
char author[20],title[20],pub[20];
int price;
library *next;
};


int sum=0;

void main()
{
clrscr();
library *head=NULL;
library *initial(void);
library *purchase(library *);
//library *sale(library *);
void display(library *);
void stock(library *);
void search(library *);

int choice;
while(1)
{
cout<<"Choose your Choice\n"; cout<<"1) Initial Data Entry\n"; cout<<"2) Purchase of Book\n"; cout<<"3) Sales of Book\n"; cout<<"4) Stock of Book\n"; cout<<"5) Search of Book\n"; cout<<"6) Display Books\n"; cout<<"7) Exit\n"; cout<<"Enter Your Choice:-"; cin>>choice;
switch(choice)
{
case 1 : head=initial();
getch();
break;
case 2 : head=purchase(head);
getch();
break;
// case 3 : head=sale(head);
// break;
case 4 : stock(head);
getch();
break;
case 5 : search(head);
getch();
break;
case 6 : display(head);
getch();
break;
case 7 : goto out;
default: cout<<"\nInvalid Choice\nTRY AGAIN\n"; } clrscr(); } out: } library *initial(void) { clrscr(); library *newl=NULL,*start=NULL,*end=newl; char ch; while(1) { cout<<"\n\nType y or Y for yes\n"; cout<<"Are you Interested in Entering Entry:-"; cin>>ch;
if(ch=='y' || ch=='Y')
{
newl=new library;
cout<<"\n\nEnter Author of Book:-"; cin>>newl->author;
cout<<"Enter Title of Book:-"; cin>>newl->title;
cout<<"Enter Publication of Book:-"; cin>>newl->pub;
cout<<"Enter Price of Book:-"; cin>>newl->price;
sum=sum+newl->price;
if(start==NULL)
start=newl;
else
end->next=newl;
end=newl;
end->next=NULL;
}
else
break;
}
return(start);
}

library *purchase(library *start)
{
clrscr();
int pos,count=1,choice;
library *newl,*cnt=start,*head=start;
if(start==NULL)
cout<<"\n\nLIST IS EMPTY\n"; cout<<"\n\nChoose your Choice\n"; cout<<"1) Inserting At FIRST POSITION\n"; cout<<"2) Inserting In BETWEEN\n"; cout<<"3) Inserting At LAST POSITION \n"; cout<<"4) Exit\n"; cout<<"Enter your choice:-"; cin>>choice;

if(choice >=1 &&amp; choice <=3) { newl=new library; cout<<"Enter Author Name :-"; cin>>newl->author;
cout<<"Enter Book Title :-"; cin>>newl->title;
cout<<"Enter Publication :-"; cin>>newl->pub;
cout<<"Enter Price of Book:-"; cin>>newl->price;
sum=sum+newl->price;
}

switch(choice)
{
case 1 : //for First position
newl->next=head;
head=newl;
break;

case 2 : //for Middle position
read:
cout<<"\n\nAt which position you want to insert Record:-"; cin>>pos;
while(cnt!=NULL)
{
count++; //cnt for counting variable of type node
cnt=cnt->next;
}
if(pos<1>count+1)
{
cout<<"\n\nEntered position is Invalid\nTRY AGAIN\n"; goto read; } { //Extra Braces are used as case bypasses intialization of a local variable int c=1; while(cnext;
}
}
newl->next=start->next;
start->next=newl;
break;

case 3 : //for Last position
while(start->next!=NULL)
start=start->next;

start->next=newl;
newl->next=NULL;
break;

case 4 : goto out;

default: cout<<"\nEntered Choice is Invalid Try again\n"; break; } out: return(head); } void stock(library *start) { clrscr(); int count=0; while(start!=NULL) { count++; start=start->next;
}
cout<<"\n\n\n\tTotal Number of Books in Stock is "<<<<"\tPurchase Price of Total Stock is "<<<"Enter Book title and its Author name respectively to Search in stock\n"; cin>>title>>author;
while(start!=NULL)
{
if(title==start->title)
{
if(author==start->author)
{
cout<<"\n\nBook is In Stock\n"; cout<<"It Cost Rs"<price;
return;
}
}
}
cout<<"\n\nSEARCH IS NOT IN STOCK\n"; } void display(library *start) { clrscr(); cout<<<"Book Title"<<<"Author of Book"<<<"Publication"<<<"Price"<<<<"=*"; cout<<<title<<author<<pub<<price<next;
}
}



Write a C++ Program for Library database

//Library Program
/*A Library shop maintains the inventory of books that are being sold at the shop
The list includes details such as author,title,price,publisher and stock position
Whenever a customer wants a book, the sales person inputs the title and author
and the system searches the list and displays whether it is available, the total cost
of the requested copies is displayed; otherwise the message "Required copies not in stock"
is displayed.
Design a system using a class called books with suitable member functions and constructors
Use New operator in constructors to allocate memory space required.

Write a program which suites above requirements.
*/

#include
#include
#include

class library
{
char author[15][20],title[15][20];
int price[15];
char pub[15][20];
int s;
public:
void getdata(void);
void display(void);
};

void library :: getdata(void)
{
cout<<"How many Entry you want to make :-"; cin>>s;
for(int i=0;i<<"\n\nEnter Author Name :- "; cin>>author[i];
cout<<"Enter Book Title :- "; cin>>title[i];
cout<<"Enter Price of Book :- "; cin>>price[i];
cout<<"Enter Publisher of Book :- "; cin>>pub[i];
}
}

void library :: display(void)
{
clrscr();
cout<<<"LIBRARY DATABASE";
cout<<
for(int a=0;a<40;a++)
cout<<"*-";
cout<
cout<<<"AUTHOR NAME"<<<"BOOK TITLE"<<<"PRICE"<<<"PUBLISHER"<
for(int b=0;b<40;b++)
cout<<"*-";
cout<

for(int i=0;i
{
cout<<<<<<<<<
}
}

void main()
{
clrscr();
library o1;
o1.getdata();
o1.display();
getch();
}



Write a C++ Program for Unary Operator ++

//Unary Operator ++
#include
#include

class counter
{
int count;
public:
counter(){count=0;}
counter(int a)
{count=a;}
void operator ++() //for prefix
{count++;}
counter operator ++(int) //for eg:- c1 = c2++
{ //and postfix expression
count++;
counter temp;
temp.count=count;
return temp;
}
void getdata(void)
{
cout<<"\n\nEnter Value for Count :-"; cin>>count;
}
void display(void)
{
cout<<"\nValue of count is "<<
}
};

void main()
{
clrscr();
counter o1(9),o2,o3;
o1++;
o1.display();

o2.getdata();
o2++;
++o2;
o2.display();

o3=o2++;
o3.display();
getch();
}



Write a C++ Program to find measure of different shape

#include
#include

class shape
{
protected:
double x,y;
public:
virtual void get_data()=0;
virtual void display_area()=0;
};

class triangle : public shape
{
public:
void get_data(void)
{
cout<<"\n\n=====Data Entry for Triangle=====\n\n"; cout<<"Enter base and height respectively : "; cin>>x>>y;
}
void display_area(void)
{
cout<<"\n\n=====Area of Triangle=====\n\n"; double aot; aot = 0.5 * x * y; cout<<"Area of Triangle is "<<<"\n\n=====Data Entry for Rectangle=====\n\n"; cout<<"Enter length of two sides : "; cin>>x>>y;
}
void display_area(void)
{
cout<<"\n\n=====Area of rectangle=====\n\n"; double aor; aor = x * y; cout<<"Area of Rectangle is "<<<"\n=====MEASURES OF DIFFERENT SHAPE=====\n"; cout<<"\nChoose your choice\n"; cout<<"1) Area of Triangle\n"; cout<<"2) Area of Rectangle\n"; cout<<"3) Exit\n"; cout<<"Enter your choice:-"; cin>>choice;
switch(choice)
{
case 1 : list[0]->get_data();
list[0]->display_area();
getch();
break;
case 2 : list[1]->get_data();
list[1]->display_area();
getch();
break;
case 3 : goto end;
default: cout<<"\n\nInvalid choice\nTry again\n";
getch();
}
}
end:
}



Write a C++ Program for maintaining employee database

#include
#include

class person
{
protected:
char name[20];
int code;
public:
void getdetail(void)
{
cout<<"\n\nEnter name :-"; cin>>name;
cout<<"Enter code :-"; cin>>code;
}
void dispdetail(void)
{
cout<<"\n\nNAME :-"<<<"\nCODE :-"<<<"\nEnter Pay amount :-"; cin>>pay;
}
void dispay(void)
{
cout<<"\nPAY :-"<<<"\nEnter Experience in yrs :-"; cin>>experience;
}
void dispexpr(void)
{
cout<<"\nEXPERIENCE:-"<<<"\n\n=====GETDATA IN=====\n"; getdetail(); getpay(); getexpr(); } void display(void) { cout<<"\n\n=====DISPLAY DETAILS=====\n"; dispdetail(); dispay(); dispexpr(); } void update(void) { cout<<"\n\n=====UPDATE DETAILS=====\n"; cout<<"\nChoose detail you want to update\n"; cout<<"1) NAME\n"; cout<<"2) CODE\n"; cout<<"3) EXPERIENCE\n"; cout<<"4) PAY\n"; cout<<"Enter your choice:-"; int choice; cin>>choice;
switch(choice)
{
case 1 : cout<<"\n\nEnter name : -"; cin>>name;
break;
case 2 : cout<<"\n\nEnter code :-"; cin>>code;
break;
case 3 : cout<<"\n\nEnter pay :-"; cin>>pay;
break;
case 4 : cout<<"\n\nEnter Expereince :-"; cin>>experience;
break;
default: cout<<"\n\nInvalid choice\n\n"; } } }; void main() { clrscr(); master ob1; int choice; while(1) { clrscr(); cout<<"\n=====MASTER DATABASE=====\n\n"; cout<<"\nChoose Operation you want to perform\n"; cout<<"1) Create Record\n"; cout<<"2) Display Record\n"; cout<<"3) Update Record\n"; cout<<"4) Exit\n"; cout<<"Enter your choice:-"; cin>>choice;
switch(choice)
{
case 1 : ob1.create();
break;
case 2 : ob1.display();
getch();
break;
case 3 : ob1.update();
break;
case 4 : goto out;
default : cout<<"\n\nInvalid Choice\nTry Again\n\n";
}
}
out:
}



Write a C++ Program for Educational Institution database

#include
#include

class staff
{
protected:
int code;
char name[20];
public:
void getstaff(void)
{
cout<<"\n\nEnter code :-"; cin>>code;
cout<<"Enter name :-"; cin>>name;
}
void dispstaff(void)
{
cout<<"\nNAME :-"<<<"\nCODE :-"<<<"Enter Subject :-"; cin>>sub;
cout<<"Enter Publication :-"; cin>>pub;
}
void display(void)
{
dispstaff();
cout<<"\nSUBJECT :-"<<<"\nPUBLICATION:-"<<<"Enter Grade :-"; cin>>grade;
}
void display(void)
{
dispstaff();
cout<<"\nGRADE :-"<<<"Enter speed (wpm):-"; cin>>speed;
}
void disptypist(void)
{
dispstaff();
cout<<"\nSPEED :-"<<<"Enter Daily Wages :-"; cin>>dailywages;
}
void display(void)
{
disptypist();
cout<<"\nDAILY WAGES:-"<<<"\n=====EDUCATION INSTITUTION DATABASE=====\n\n\n"; cout<<"Choose Category of Information\n"; cout<<"1) Teachers\n"; cout<<"2) Officer\n"; cout<<"3) Typist\n"; cout<<"4) Exit\n"; cout<<"Enter your choice:-"; cin>>choice;
switch(choice)
{
case 1 : while(1)
{
clrscr();
cout<<"\n=====TEACHERS INFORMATION=====\n\n"; cout<<"\nChoose your choice\n"; cout<<"1) Create\n"; cout<<"2) Display\n"; cout<<"3) Jump to Main Menu\n"; cout<<"Enter your choice:-"; cin>>choice;
switch(choice)
{
case 1 : for(count=0,i=0;i<10;i++) cout=""><<<"\n\nAre you Interested in entering data\n"; cout<<"Enter y or n:-"; cin>>test;
if(test=='y' || test=='Y')
continue;
else
goto out1;
}
out1:
break;
case 2 : for(i=0;i<<<<"\nEnter choice is invalid\ntry again\n\n"; } } case 2 : while(1) { clrscr(); cout<<"\n=====OFFICERS INFORMATION=====\n\n"; cout<<"\nChoose your choice\n"; cout<<"1) Create\n"; cout<<"2) Display\n"; cout<<"3) Jump to Main Menu\n"; cout<<"Enter your choice:-"; cin>>choice;
switch(choice)
{
case 1 : for(count=0,i=0;i<10;i++) cout=""><<<"\n\nAre you Interested in entering data\n"; cout<<"Enter y or n:-"; cin>>test;
if(test=='y' || test=='Y')
continue;
else
goto out2;
}
out2:
break;
case 2 : for(i=0;i<<<<"\nInvalid choice\ntry again\n\n"; } } case 3 : while(1) { clrscr(); cout<<"\n=====TYPIST INFORMATION=====\n\n"; cout<<"\nChoose your choice\n"; cout<<"1) Create\n"; cout<<"2) Display\n"; cout<<"3) Jump to Main Menu\n"; cout<<"Enter your choice:-"; cin>>choice;
switch(choice)
{
case 1 : for(count=0,i=0;i<10;i++) cout=""><<<"\n\nAre you Interested in entering data\n"; cout<<"Enter y or n:-"; cin>>test;
if(test=='y' || test=='Y')
continue;
else
goto out3;
}
out3:
break;
case 2 : for(i=0;i
{
cout<
o1c[i].display();
cout<
}
getch();
break;
case 3 : goto start;
default: cout<<"\nInvalid choice\ntry again\n\n";
}
}
case 4 : goto end;
}
}
end:
}



Write a C++ Program for Bank

#include
#include

class account
{
char cust_name[20];
int acc_no;
char acc_type[20];
public:
void get_accinfo()
{
cout<<"\n\nEnter Customer Name :- "; cin>>cust_name;
cout<<"Enter Account Number :- "; cin>>acc_no;
cout<<"Enter Account Type :- "; cin>>acc_type;
}
void display_accinfo()
{
cout<<"\n\nCustomer Name :- "<<<"\nAccount Number :- "<<<"\nAccount Type :- "<<<"\nBalance :- "<<<"\nEnter amount to Deposit :- "; cin>>deposit;
balance = balance + deposit;
}
void withdraw_currbal()
{
float penalty,withdraw;
cout<<"\n\nBalance :- "<<<"\nEnter amount to be withdraw :-"; cin>>withdraw;
balance=balance-withdraw;
if(balance < penalty="(500-balance)/10;" balance="balance-penalty;" else="" withdraw=""> balance)
{
cout<<"\n\nYou have to take permission for Bank Overdraft Facility\n"; balance=balance+withdraw; } else cout<<"\nAfter Withdrawl your Balance revels : "<<<"\nBalance :- "<<<"\nEnter amount to Deposit :- "; cin>>deposit;
savbal = savbal + deposit;
interest=(savbal*2)/100;
savbal=savbal+interest;
}
void withdraw_savbal()
{
float withdraw;
cout<<"\nBalance :- "<<<"\nEnter amount to be withdraw :-"; cin>>withdraw;
savbal=savbal-withdraw;
if(withdraw > savbal)
{
cout<<"\n\nYou have to take permission for Bank Overdraft Facility\n"; savbal=savbal+withdraw; } else cout<<"\nAfter Withdrawl your Balance revels : "<<<"\nEnter S for saving customer and C for current a/c customer\n\n"; char type; cin>>type;

int choice;

if(type=='s' || type=='S')
{
s1.get_accinfo();
while(1)
{
clrscr();
cout<<"\nChoose Your Choice\n"; cout<<"1) Deposit\n"; cout<<"2) Withdraw\n"; cout<<"3) Display Balance\n"; cout<<"4) Display with full Details\n"; cout<<"5) Exit\n"; cout<<"6) Choose Your choice:-"; cin>>choice;
switch(choice)
{
case 1 : s1.deposit_savbal();
getch();
break;
case 2 : s1.withdraw_savbal();
getch();
break;
case 3 : s1.disp_savbal();
getch();
break;
case 4 : s1.display_accinfo();
s1.disp_savbal();
getch();
break;
case 5 : goto end;
default: cout<<"\n\nEntered choice is invalid,\"TRY AGAIN\""; } } } else { { c1.get_accinfo(); while(1) { cout<<"\nChoose Your Choice\n"; cout<<"1) Deposit\n"; cout<<"2) Withdraw\n"; cout<<"3) Display Balance\n"; cout<<"4) Display with full Details\n"; cout<<"5) Exit\n"; cout<<"6) Choose Your choice:-"; cin>>choice;
switch(choice)
{
case 1 : c1.deposit_currbal();
getch();
break;
case 2 : c1.withdraw_currbal();
getch();
break;
case 3 : c1.disp_currbal();
getch();
break;
case 4 : c1.display_accinfo();
c1.disp_currbal();
getch();
break;
case 5 : goto end;
default: cout<<"\n\nEntered choice is invalid,\"TRY AGAIN\"";
}
}
}
end:
}
}



Write a C++ Program for Conversion CLASS TO BASIC : String object to basic string

//Conversion CLASS TO BASIC
//String object to basic string

#include
#include
#include

class string
{
char *p;
int len;
public:
string()
{}
string(char *a)
{
len=strlen(a);
p=new char[len+1];
strcpy(p,a);
}
operator char*()
{
return(p);
}
void display()
{
cout<
}
};


void main()
{
clrscr();
string o1="vivek";
cout<<"String of Class type : ";
o1.display();
cout<


char *str=o1;
cout<<"String of Basic type : "<

getch();
}



Write a C++ Program for Conversion from CLASS TO BASIC : TIME CONVERSION

//Conversion CLASS TO BASIC
//TIME CONVERSION

#include
#include

class time
{
int hrs;
int mins;
public:
time()
{}
void getdata()
{
cout<<"Enter value for Hours : "; cin>>hrs;
cout<<"Enter value for Minutes: "; cin>>mins;
}
void display()
{
cout<<"\n\nHours : "<
cout<<"\nMinutes : "<
}
operator int()
{
int t;
t = hrs*60;
t = t + mins;
return t;
}
};


void main()
{
clrscr();
time o1;
o1.getdata();
o1.display();

int duration;
duration=o1;

cout<<"\nDuration : "<<<" minutes";
getch();
}



Write a C++ Program for Conversion from CLASS TO CLASS

//Conversion from CLASS TO CLASS

#include
#include

class invent1
{
int code;
int items;
float price;

public:

invent1()
{}

invent1(int a,int b,int c)
{
code=a;
items=b;
price=c;
}

void display()
{
cout<<"\nCode : "<
cout<<"\nItems : "<
cout<<"\nPrice : "<
}

int getcode()
{return code;}

int getitem()
{return items;}

int getprice()
{return price;}

};


class invent2
{
int code;
float value;

public:

invent2()
{
code=0;
value=0;
}

invent2(int x,float y)
{
code=x;
value=y;
}

void display()
{
cout<<"Code : "<<
cout<<"Value : "<<
}

invent2(invent1 p)
{
code=p.getcode();
value=p.getitem()*p.getprice();
}
};


void main()
{
clrscr();
invent1 s1(100,5,140);
invent2 d1;

d1=s1; //Invoke Constructor in Invent2 for conversion

cout<<"\nProduct details - Invent1 type";
s1.display();

cout<<"\n\n\nProduct details - Invent2 type\n";
d1.display();
getch();
}



Write a Menu driven Telephone Directory Program

//Telephone Directory

#include
#include
#include
#include
#include

class phoneBook{
char name[20],phno[6];
public:
void getdata();
void showdata();
char *getname(){ return name; }
char *getphno(){ return phno; }
void update(char *nm,char *telno){
strcpy(name,nm);
strcpy(phno,telno);
}
};

void phoneBook :: getdata(){
cout<<"\nEnter Name : "; cin>>name;
cout<<"Enter Phone No. : "; cin>>phno;
}

void phoneBook :: showdata(){
cout<<"\n"; cout<<<<<<"\n*****Phone Book*****\n"; cout<<"1) Add New Record\n"; cout<<"2) Display All Records\n"; cout<<"3) Search Telephone No.\n"; cout<<"4) Search Person Name\n"; cout<<"5) Update Telephone No.\n"; cout<<"6) Exit\n"; cout<<"Choose your choice : "; cin>>choice;
switch(choice){
case 1 : //New Record
rec.getdata();
cin.get(ch);
file.write((char *) &rec, sizeof(rec));
break;

case 2 : //Display All Records
file.seekg(0,ios::beg);
cout<<"\n\nRecords in Phone Book\n"; while(file){ file.read((char *) &rec, sizeof(rec)); if(!file.eof()) rec.showdata(); } file.clear(); getch(); break; case 3 : //Search Tel. no. when person name is known. cout<<"\n\nEnter Name : "; cin>>nm;
file.seekg(0,ios::beg);
found=0;
while(file.read((char *) &rec, sizeof(rec)))
{
if(strcmp(nm,rec.getname())==0)
{
found=1;
rec.showdata();
}
}
file.clear();
if(found==0)
cout<<"\n\n---Record Not found---\n"; getch(); break; case 4 : //Search name on basis of tel. no cout<<"\n\nEnter Telephone No : "; cin>>telno;
file.seekg(0,ios::beg);
found=0;
while(file.read((char *) &rec, sizeof(rec)))
{
if(strcmp(telno,rec.getphno())==0)
{
found=1;
rec.showdata();
}
}
file.clear();
if(found==0)
cout<<"\n\n---Record Not found---\n"; getch(); break; case 5 : //Update Telephone No. cout<<"\n\nEnter Name : "; cin>>nm;
file.seekg(0,ios::beg);
found=0;
int cnt=0;
while(file.read((char *) &rec, sizeof(rec)))
{
cnt++;
if(strcmp(nm,rec.getname())==0)
{
found=1;
break;
}
}
file.clear();
if(found==0)
cout<<"\n\n---Record Not found---\n"; else { int location = (cnt-1) * sizeof(rec); cin.get(ch); if(file.eof()) file.clear(); cout<<"Enter New Telephone No : "; cin>>telno;
file.seekp(location);
rec.update(nm,telno);
file.write((char *) &rec, sizeof(rec));
file.flush();
}
break;
case 6 : goto out;
}
}
out:
file.close();
}



Write a C++ Program demonstrating files

#include
#include
#include
#include
#include

void main()
{
fstream fin,fout;
char ch;
int flag = 1;
clrscr();
fin.open("data.txt",ios :: out | ios :: in);
fout.open("data1.txt",ios :: out | ios :: in);
fin.seekg(0);
if(fin==NULL)
cout<<"Unable to open file";
while(fin)
{
fin.get(ch);
if(ch == ' ')
{
flag = 0;
}
else
{
if(flag == 0)
{
fout.put(' ');
cout<< ' ';
flag = 1;
}
fout.put(ch);
cout<
}
}
}



Write a C++ Program to count chars, line, word into it.

#include
#include
#include
#define MAX_ROW 5
#define MAX_COL 80


void main(){
char name[MAX_ROW][MAX_COL],c;
int lines=1; //bcoz. first line will be left to count.
int words=1; //bcoz. first word will be left to count.
int chars=1; //bcoz. first char will be left to count.
clrscr();
cout<<"===Input Status===\n";
cout<<"Enter string termanate by # : ";
cin.get(c);

//Finding no. of lines
while(c != '#'){
cin.get(c);
chars++;
if(c==' ' || c=='\n')
words++;
if(c=='\n')
lines++;
}

cout<<"\n"<<<"Particulars"<<<"Details\n";
cout<<"-------------------------------------\n";

cout.setf(ios::left,ios::adjustfield);
cout<<"\n"<<<"No. of lines ";
cout.setf(ios::right,ios::adjustfield);
cout<<

cout.setf(ios::left,ios::adjustfield);
cout<<"\n"<<<"No. of Words ";
cout.setf(ios::right,ios::adjustfield);
cout<<

cout.setf(ios::left,ios::adjustfield);
cout<<"\n"<<<"No. of Characters ";
cout.setf(ios::right,ios::adjustfield);
cout<<

getch();

}



Write a Menu driven Inventory Program

#include
#include
#include
#define MAX_REC 10

class Inventory{
char itemName[15];
int code;
double cost;
public:
void getdata();
void showdata();
};

void Inventory :: getdata(){
cout<<"\nEnter Item Name : "; cin>>itemName;
cout<<"Enter Code : "; cin>>code;
cout<<"Enter Cost : "; cin>>cost;
}

void Inventory :: showdata(){
cout<<<<<<"\n=====Inventory Management=====\n"; cout<<"\nHow many Records to be created : "; cin>>n;

cout<<"Enter "<<<" Records\n";
for(i=0;i
record[i].getdata();

cout<<"\n\n---Stock Information---\n";
cout<<"\n"<<<"Item Name"
<<<"Code"
<<<"Cost"<
cout<<"-------------------------------------------";

for(i=0;i
record[i].showdata();

getch();
}



Write a C++ Program to generate desired output

////OUTPUT PROGRAM OF C++ PROGRAMMING////
//C
//C+
//C++
//....
//.....
//C++ PROGRAMMING

#include
#include
void main()
{
int i,j;
char ch[]="C++ Programming";
clrscr();
for(i=0;i<15;i++)
{

for(j=0;j<=i;j++)
cout<

cout<<"\n";
}
getch();
}



Wrtie a C++ Program for Binary Operator + to add two object

//Binary Operator + to add two object
#include
#include

class distance
{
int feet;
float inches;
public:
distance()
{ feet=0;inches=0.0;}
distance(int ft,float in)
{ feet=ft; inches=in;}
void getdist()
{
cout<<"\nEnter feet : "; cin>>feet;
cout<<"\nEnter Inches : "; cin>>inches;
}
void showdist()
{
cout<<<"\'-"<<<'\"'; } distance operator + (distance); }; distance distance :: operator + (distance d2) { int f = feet + d2.feet; float i = inches + d2.inches; if(i >= 12.0)
{
i = i - 12.0;
f++;
}
return distance(f,i);
}


void main()
{
clrscr();
distance dist1,dist2(11,6.25),dist3,dist4;
dist1.getdist();

dist3=dist1 + dist2;

dist4=dist1 + dist2 + dist3;

cout<<"\ndist1 = ";
dist1.showdist();
cout<<"\ndist2 = ";
dist2.showdist();
cout<<"\ndist3 = ";
dist3.showdist();
cout<<"\ndist4 = ";
dist4.showdist();

getch();
}



Wrtie a C++ Program for Conversion BASIC TO CLASS TYPE : TIME CONVERSION

//Conversion BASIC TO CLASS
//TIME CONVERSION

#include
#include

class time
{
int hrs;
int mins;
public:
time()
{}
time(int t)
{
hrs=t/60;
mins=t%60;
}
void display()
{
cout<<"\nHours = "<<<"\nMinutes = "<<<"Enter Duration : "; cin>>duration;

o1=duration; //Invoke the constructor

o1.display();
getch();
}



Wrtie a C++ Program for Conversion BASIC TO CLASS TYPE

//Conversion BASIC TO CLASS TYPE
//string to class object

#include
#include
#include

class string
{
char *p;
int len;
public:
string::string()
{}
string::string(char *a)
{
len=strlen(a);
p=new char[len+1];
strcpy(p,a);
}
void display()
{
cout<
}
};

void main()
{
clrscr();
string s1,s2;
char *name1="vivek";
char *name2="patel";
s1=string(name1); //Invoke constructor
s2=name2; //Invoke constructor

s1.display();
cout<
s2.display();
getch();
}



Wrtie a C++ Program for finding values of distance

//create two classes DM and DB which stores the value of distances. DM stores distances in metres
//and centimetres and DB in feet and inches. Write a program that can read values for the class objects
//and add one object DM with another object of DB.
//use friend function.

#include
#include

class db;

class dm
{
float mt;
int cm;
public:
void getdata(void);
void display(void);
friend dm add(dm,db);
};

class db
{
int feet;
float inches;
public:
void getdata(void);
void display(void);
friend dm add(dm,db);
};

void dm :: getdata(void)
{
clrscr();
cout<<"\t\tDM GETDATA FUNCTION\n\n"; cout<<"\n\nEnter Values for metres :-"; cin>>mt;
cout<<"Enter Values for centimetres:-"; cin>>cm;
}
void dm :: display(void)
{
cout<<"\n\nThe value of distance in metres is "<<<"\nThe value of distance in Centimetres is "<<<"\t\tDB GETDATA FUNCTION\n\n"; cout<<"\n\nEnter Values for feet :-"; cin>>feet;
cout<<"Enter Values for inches :-"; cin>>inches;
}
void db :: display(void)
{
cout<<"\n\nThe value of distance in feet is "<
cout<<"\nThe value of distance in inches is "<
}

dm add(dm a,db b)
{
dm temp;
temp.cm=a.cm+(b.feet*30)+((b.inches*30)/12.0);
temp.mt=a.mt+(temp.cm % 100);
temp.cm=temp.cm-((temp.cm % 100)*100);
return(temp);
}

void main()
{
dm a;
a.getdata();
db b;
b.getdata();

clrscr();
cout<<"\n\t\tAFTER CONVERSION AND THEIR ADDITION IS PERFORMED\n";

//extra variable of type dm to display result of adding two different types of distance
dm extra;
extra=add(a,b);
extra.display();

getch();
}



Write a C++ Program for Vector Class

/*write a class to represent a vector (a series of float values).
Include member functions to perform the following tasks:
1)To Create the Vector
2)To modify the value of a given element
3)To multiply by a scalar value.
4)To display the vector in the form (10,20,30....)
Write a program to test your class*/

#include
#include

int const size=50;

class vector
{
float d[size];
int s;
public:
void create(void);
void modify(void);
void multiply(void);
void display(void);
};

void vector :: create(void)
{
cout<<"\n\nEnter of Array you want to create:-"; cin>>s;
cout<<"Enter " << s << " Real Numbers\n";
for(int i=0; i < s;i++) cin="" >> d[i];
}

void vector :: modify(void)
{
int mfy_value;
float with;
cout<<"\nEnter Location of array at which value is to be modified:-"; cin>>mfy_value;
cout<<"Enter Value with which you want to Replace:-"; cin>>with;
d[mfy_value]=with;
}

void vector :: multiply(void)
{
int mul;
cout<<"\nEnter value with which you want to multiply:-"; cin>>mul;
for(int i=0;i<<"\n\nDisplay of Array\n"; cout<<"("; for(int i=0;i<<<","; } cout<<")"; } void main() { clrscr(); vector o1; int choice; do { cout<<"\n\nChoice List\n"; cout<<"1) To Create Vector Array\n"; cout<<"2) To Modify Array\n"; cout<<"3) To Multiply with Scalar value\n"; cout<<"4) To Display\n"; cout<<"5) EXIT\n"; cout<<"Enter your choice:-"; cin>>choice;
switch(choice)
{
case 1: o1.create();
break;
case 2: o1.modify();
break;
case 3: o1.multiply();
break;
case 4: o1.display();
break;
case 5:goto end;
}
}while(1);
end:
}



Write a C++ Program for Bank Account Class

/*Define a class to represent a bank account. Include the following
members:

Data Members
1 Name of the depositor
2 Account Number
3 Type of account
4 Balance amount in the account

Member function
1 To assign initial values
2 To deposit an amount
3 To withdraw an amount after checking the balance
4 To display name and Balance

write a main program to test the program. */

#include
#include
#include

class bank
{
char name[20];
int acno;
char actype[20];
int bal;
public :
void opbal(void);
void deposit(void);
void withdraw(void);
void display(void);
};

void bank :: opbal(void)
{
cout<<<<"Enter Name :-"; cin>>name;
cout<<"Enter A/c no. :-"; cin>>acno;
cout<<"Enter A/c Type :-"; cin>>actype;
cout<<"Enter Opening Balance:-"; cin>>bal;
}

void bank :: deposit(void)
{
cout<<"Enter Deposit amount :-"; int deposit=0; cin>>deposit;
deposit=deposit+bal;
cout<<"\nDeposit Balance = "<<<"\nBalance Amount = "<<<"\nEnter Withdraw Amount :-"; cin>>withdraw;
bal=bal-withdraw;
cout<<"After Withdraw Balance is "<<<<<<<"DETAILS"<<<<"name "<<<<<"A/c. No. "<<<<<"A/c Type "<<<<<"Balance "<<<<"\n\nChoice List\n\n"; cout<<"1) To assign Initial Value\n"; cout<<"2) To Deposit\n"; cout<<"3) To Withdraw\n"; cout<<"4) To Display All Details\n"; cout<<"5) EXIT\n"; cout<<"Enter your choice :-"; cin>>choice;
switch(choice)
{
case 1: o1.opbal();
break;
case 2: o1.deposit();
break;
case 3: o1.withdraw();
break;
case 4: o1.display();
break;
case 5: goto end;
}
}while(1);
end:
}



Write a C++ Program for Finding Power of Number.

/*Write a function power() to raise a number m to a power n. The
function takes a double value for m and int value for n and returns
the result correctly. Use a default value of 2 for n to make the
function to calculate squares when this argument is omitted.
Write a main that gets the values of m and n from the user to test
the function.*/

#include
#include
void main()
{
double power(double m,int n=2);
clrscr();
cout<<<<<"\n\n\nCHOICES\n\n"; cout<<"1) Only Value of M\n"; cout<<"2) Value for both M and N\n"; cout<<"3) QUIT\n"; cout<<"ENTER YOUR CHOICE:-"; cin>>choice;
clrscr();
cout<<<<<"Enter Value for M:-"; cin>>m;
result=power(m);
cout<<"Power function when default argument is used ="<<<"Enter Value for M and N:-"; cin>>m>>n;
result=power(m,n);
cout<<"Power function when actual argument is use ="<
break;
case 3 : goto out;
default: cout<<"Entered Value is Invalid, Try again";
}
}while(choice!=3);
out:
}


double power(double m,int n)
{
double pow=1,k=0;
for(int i=0;i
{
pow=pow*m;
}
return(pow);
}



Write a macro that obtains the largest of three numbers.

//Write a macro that obtains the largest of three numbers.

#include
#include
void main()
{
clrscr();
int largest(int,int,int);
cout<<"Enter 3 Integer Numbers\n";
int a,b,c;
cin >> a >> b >> c;
int result;
result=largest(a,b,c);
cout<<"\n\nLargest Value of Inputed is "<getch();
}

inline largest(int a,int b,int c)
{
int z;
z=(a > b)?((a > c)?a:c):((b > c)? b:c);
return(z);
}



The Effect of a default argument can be alternatively achieved by overloading. Discuss with an example.

//The Effect of a default argument can be alternatively achieved
//by overloading. Discuss with an example.

#include
#include
void main()
{
int sum(int,int); //function with 2 argument
int sum(int,int,int); //function with 3 argument
int sum(int,int,int,int); //function with 4 argument
int sum(int[],int); //function with n argument
clrscr();
int a,b,c,d,result;

cout<<"\n\nfor 2 argument\n";
cout<<"Enter 2 Integers\n";
cin>>a>>b;
result=sum(a,b);
cout<<"Addition =" << result;


cout << "\n\nfor 3 argument\n";
cout<<"Enter 3 Integers\n";
cin>> a >> b >> c;
result=sum(a,b,c);
cout<<"Addition ="<< result;



cout<< "\n\nfor 4 argument\n";
cout<<"Enter 4 Integers\n";
cin>>a >> b >> c >> d;
result=sum(a,b,c,d);
cout<<"Addition =" << result;


cout<<"\n\nHow many Argument You want to enter:-";
int no;
cin>>no;
int num[50];
cout<<"Enter "<< no <<" Integers\n";
for(int i=0;i < no ;i++)
cin>>num[i];
result=sum(num,no);
cout<<"Addition =" << result;

getch();
}


//function with 2 argument
int sum(int a,int b)
{
return(a+b);
}


//function with 3 argument
int sum(int a,int b,int c)
{
return(a+b+c);
}

//function with 4 argument
int sum(int a,int b,int c,int d)
{
return(a+b+c+d);
}

//function with n argument
int sum(int a[],int n)
{
int sum=0;
for(int i=0;i < n;i++)
{
sum=sum+a[i];
}
return(sum);
}



rewrite the program of Exercise 4.14 to make the row parameter of the matrix as a default argument.

//rewrite the program of Exercise 4.14 to make the row parameter
//of the matrix as a default argument.

//DEFAULT VALUE\\
#define row 50
#define col 50
#include
#include
#include
void main()
{
void data_entry_matrix(int cols,int rows=3);
clrscr();
cout<<"\n\n\tusing rows as default value";


cout<<"\n\n\tEnter Number of Column You want to enter:-";
int cols;
cin>>cols;

data_entry_matrix(cols);

getch();
}



void data_entry_matrix(int c, int r)
{
clrscr();
int matrix[row][col];
cout<<"\n\n\t\tEnter Your Data for Matrix " << r <<"x" << c <<"\n\n\n\t";
//for input
for(int i=0;i < r;i++)
{
for(int j=0;j < c;j++)
{
cin>>matrix[i][j];
}
}

cout<< endl << endl << endl;
//for display
cout<<"\n";
for(int i=0;i < r;i++)
{
for(int j=0;j < c;j++)
{
cout << setw(5)<< matrix[i][j];
}
cout << endl;
}

}



Write a function to read a matrix of size m x n from the keyboard and display the same on the screen.

//Write a function to read a matrix of size m x n from the
//keyboard and display the same on the screen.


#define row 50
#define col 50
#include
#include
#include
void main()
{
void data_entry_matrix(int,int);
clrscr();
cout<<"\n\n\tEnter Number of rows you want to enter:-";
int rows;
cin>>rows;

cout<<"\n\n\tEnter Number of Column You want to enter:-";
int cols;
cin>>cols;

data_entry_matrix(rows,cols);

getch();
}



void data_entry_matrix(int r, int c)
{
clrscr();
int matrix[row][col];
cout << "\n\n\t\tEnter Your Data for Matrix "<< r <<"x" << c << "\n\n\n\t";
//for input
for(int i=0;i < r;i++)
{
for(int j=0;j < c;j++)
{
cin>>matrix[i][j];
}
}

cout << endl << endl << endl;
//for display
cout<<"\n";
for(int i=0;i < r;i++)
{
for(int j=0;j < c;j++)
{
cout << setw(5)<< matrix[i][j];
}
cout<< endl;
}




}



Write a function to read a matrix of size m x n from the keyboard.

//Write a function to read a matrix of size m x n from the
//keyboard.


#define row 50
#define col 50
#include
#include
void main()
{
void data_entry_matrix(int,int);
clrscr();
cout<<"\n\n\tEnter Number of rows you want to enter:-";
int rows;
cin>>rows;

cout<<"\n\n\tEnter Number of Column You want to enter:-";
int cols;
cin>>cols;

data_entry_matrix(rows,cols);

getch();
}



void data_entry_matrix(int r, int c)
{
clrscr();
int matrix[row][col];
for(int i=0;i < r;i++)
{
for(int j=0;j {
cin>>matrix[i][j];
}
}
}



Write a C++ Program for Electricity Board Charge

/*An electricity board charges the following rates to domestic
users to discourage large consumption of energy:
For the first 100 units - 40p per unit
For next 200 units - 50p per unit
Beyond 300 units - 60p per unit
All users are charged a minimum of Rs.500. If the total cost is
more than Rs.250.00 then an additional surcharge of 15% is added.
Write a program to read the names of users and number of units
consumed and print out the charges with names.*/

#include
#include
void main()
{
clrscr();
cout<<"\n\n\n\tElectricity Board Charges\n";
cout<<"\n\tTo Discourage Large Consumption of energy\n\n";



char name[20];
cout<<"\n\nEnter USER name :-";
cin>>name;

cout<<"\n\nEnter Number of Units Consumed:-";
float unit;
cin>>unit;

//MANIPULATION
float tc;
if(unit<=100)
tc=unit*0.40;
else if(unit<=300)
tc=unit*0.50;
else
tc=unit*0.60;


float surchase=0;
if(tc>250)
surchase=tc*0.15;

float total_cost;
total_cost = 500 + surchase + tc;

cout<<"\n\nYOUR BILL AMOUNT IS "<< total_cost;

getch();
}



write a program to print a table of values of the function. y=e raise to -x for x varying from 0 to 10 in steps of 0.1.

//write a program to print a table of values of the function.
//y=e raise to -x
//for x varying from 0 to 10 in steps of 0.1. the table should appear as follows.

#include
#include
#include
#include

class exponent
{
float i,j;
public:
exponent()
{i=0;j=0.0;}
void display(void);
};

void exponent :: display(void)
{
double sum;
cout<<"\n\n\t\t\tTABLE FOR Y = EXP[-X]\n";
for(int a=0;a<40;a++)
cout<<"--";
cout<<"\n";
for(int c=0,b=0.0;c<10;b++,c++)
{
if(b==0.0)
cout<< setw(c+5) <<"X";
else
cout<< setw(c+3)<< b;
}
cout << endl;
for(int d=0;d<40;d++)
cout << "==";
cout << endl;
c=0;
while(i<10)
{
while(c<10)
{
sum=1/pow(i,j);
if(c==0)
cout<< setw(5)<< i;
else
cout<< setw(3)<< sum;
if(c > 10)
break;
}
cout << endl;
}
}

void main()
{
clrscr();
exponent o1;
o1.display();
getch();
}



write programs to evaluate the following to 0.0001% accuracy.

/* write programs to evaluate the following to 0.0001%
accuracy.
(B) SUM = 1+[(1/2)raise to 2]+[(1/3)raise to 3]+.....*/

#include
#include
#include
void main()
{
clrscr();
int num;
cout<<"Enter the number:- ";
cin>>num;
float r,sum=0,p;
int k,i;
for(k=1,i=1;i<=num;i++,k++)
{
r=1.0/k;
p=pow(r,i);
sum=sum+p;
}
cout<<"\n\nSUM = " << sum;
getch();
}



Write a C++ Program for Cricket Match

/*A criket team has the following table of batting figures for a
series of test matches:
-----------------------------------------------------------------
Player's Name Runs Innings Times not out
-----------------------------------------------------------------
venkat 632 15 0
prasanna 514 14 3
Gavaskar 675 17 2
. . . .
. . . .
------------------------------------------------------------------
Write a program to read the figures set out in the above form, to calculate
the batting averages and to print out the complete table including the averages.*/

#include
#include
#include
void main()
{
void line();
void star();

int runs,innings;
float avg;
cout<<"\nEnter 5 records including following details\n";
cout<<"1) Player's Name\n";
cout<<"2) Runs\n";
cout<<"3) Innings\n";
cout<<"4) Times Not out\n\n";

struct cricketer
{
char name[15];
int runs;
int innings;
int tno;
float avg;
}rec[5];

for(int i=0;i<5;i++)
{
cout<<"\nEnter Player Name:-";
cin>>rec[i].name;
cout<<"Enter Runs:-";
cin>>rec[i].runs;
cout<<"Enter Innings:-";
cin>>rec[i].innings;
cout<<"Enter Time not out:-";
cin>>rec[i].tno;
rec[i].avg = float(rec[i].runs)/rec[i].innings;
}


clrscr();
cout<<"\n\n\n";
cout<line();
cout< <line();
for(int i=0;i<5;i++)
{
cout< <}
line();
cout<star();
cout<star();
getch();
}



//======================line=====================\\
void line()
{
for(int i=1;i<41;i++)
cout<<"--";

cout<<"\n";
}



//======================star======================\\
void star()
{
for(int i=1;i<41;i++)
cout<<"**";

cout<<"\n";
}



Write a C++ Program for Election Contest

/*An election is contested by five candidates. The candidates are
numbered 1 to 5 and the voting is done by marking the candidate number
on the ballot paper. Write a program to read the ballots and counts
the votes cast for each candidates using an array variable count.
In case, a number read is outside the range 1 to 5, the ballot should
be considered as a 'spoilt ballot' and the program should also count
the number of spoilt ballots.*/

#include
#include

int const size=50;

class ballot
{
int candidate; //candidate you want to create for voting
int vote[size];
int ballot[5];
static int spballot; //spoil ballot
public :
void getdisplay(void);
};

int ballot :: spballot;

void ballot :: getdisplay(void)
{
cout<<"\n\n\nEnter how many candidate you want to make:-";
cin>>candidate;

static int a,b,c,d,e;
a=0;
a=b=c=d=e;

cout<<"\nEnter 1-5 Integers\n";
for(int i=0;i< candidate;i++)
{
cin>>vote[i];
switch(vote[i])
{
case 1:ballot[a];
a++;
break;
case 2:ballot[b];
b++;
break;
case 3:ballot[c];
c++;
break;
case 4:ballot[d];
d++;
break;
case 5:ballot[e];
e++;
break;
default : ++spballot;
}
}

//for displaying
int choice;
do
{
cout<<"\n\n\n\nChoices Available\n";
cout<<"\n1) Scored By Ballot A\n";
cout<<"2) Scored By Ballot B\n";
cout<<"3) Scored By Ballot C\n";
cout<<"4) Scored By Ballot D\n";
cout<<"5) Scored By Ballot E\n";
cout<<"6) Spoilt Ballot\n";
cout<<"7) EXIT\n";
cout<<"Enter Your Choice :- ";
cin>>choice;
switch(choice)
{
case 1: cout<<"Scored By Ballot A is "< break;
case 2: cout<<"Scored By Ballot B is "< break;
case 3: cout<<"Scored By Ballot C is "< break;
case 4: cout<<"Scored By Ballot D is "< break;
case 5: cout<<"Scored By Ballot E is "< break;
case 6: cout<<"Spoil Ballot were "< break;
case 7: goto end;
}
}while(1);
end:
}



void main()
{
clrscr();
ballot o1;
o1.getdisplay();
}



Write a C++ Program to generate following output

//OUTPUT PROGRAM
//1
//22
//333
//......

#include
#include
void main()
{
int i,num,j;
clrscr();
cout<<"Enter number for corresponding output:- ";
cin>>num;
for(i=1;i<=num;i++)
{
for(j=1;j<=i;j++)
{
cout< }
cout<<"\n";
}
num--;
getch();
}



Write a function that creates a vector of user-given size M using new operator.

//Write a function that creates a vector of user-given size M
//using new operator.
#define null 0
#include
#include



void main()
{
void memory(int);
clrscr();
textcolor(16);
textbackground(1235);
clrscr();
cout<<"Enter Memory M you Want to create:-";
int size;
cin>>size;
memory(size);
getch();
}


//MEMORY function
void memory(int s)
{
int *m = new int[s];
if(m!=null)
{
cout<<"\nWe are Successfull";
cout<<"\n\n\n\n\tNow You Want to Delete This Created Memory";
cout<<"\n\n\tEnter Y or y for Deleting else anything:-";
char ch;
cin>>ch;
if(ch=='y' || ch=='Y')
{
delete[]m;
cout<<"\n\n\n\tCreated Memory is Delete";
}
else
cout<<"\n\n\tOK, your Memory is Safe";
}
else
cout<<"\nWe are UN-Successfull";
}



write a function using refrence variable as argument to swap the value of a pair of integers.

/* write a function using refrence variable as argument to swap
the value of a pair of integers. */


#include
#include

class swaping
{
int a;
public :
void getdata(void);
friend void swap(swaping &,swaping &);
void display(void);
};

void swaping :: getdata(void)
{
cout<<"\n\nEnter any Integer :-";
cin>>a;
}

void swap(swaping &o1,swaping &o2)
{
int temp;
temp = o1.a;
o1.a = o2.a;
o2.a = temp;
}

void swaping :: display(void)
{
cout<}

void main()
{
clrscr();
swaping o1,o2;

cout<<"Before Swaping\n";
o1.getdata();
o2.getdata();

swap(o1,o2);

cout<<"\n\nAfter Swaping\n";
o1.display();
o2.display();

getch();
}



Redo Exercise 2.11 using a CLASS called TEMP and member functions

/* Redo Exercise 2.11 using a CLASS called TEMP and
member functions.*/

#include
#include

class TEMP
{
float f,c;
public:
float getdata();
void display(void);
};

float TEMP :: getdata()
{
cout<<"Enter Value for farenheit degree to find for celsius:- ";
cin>>f;
c = (f-32)/1.8;
return(c);
}

void TEMP :: display(void)
{
float v;
v=getdata();
cout<<"CELSIUS DEGREE = "<}

void main()
{
TEMP c;
c.display();
}



Write a C++ program that will ask for a temperature in Fahrenheit and display it in Celsius.

/* Write a C++ program that will ask for a temperature in Fahrenheit
and display it in Celsius. */
// FORMULA C = F-32 / 1.8 //
//----------------------------//

#include
#include
void main()
{
float f,c;
clrscr();
cout<<"Enter Fahrenheit degree to find temperature in celsius: ";
cin>>f;
c = (f-32)/1.8;
cout<<"\n\n\tCELSIUS DEGREE = "<getch();
}



Write a program to read the value of a,b and c and display the value of x, where X=A/B-C

/*Write a program to read the value of a,b and c and display
the value of x, where
X=A/B-C */

#include
#include
void main()
{
float x,a,b,c,check;
clrscr();
cout<<"\nEnter value for a,b and c respectively\n";
cin>>a>>b>>c;
check=b-c;
if(check == 0)
cout<<"\n\nIMAGINARY NUMBERS\n";
else
{
x=a/(b-c);
cout<<"\n\nValue of X = "<}
getch();
}



write a program to input an integer value from keyboard and display on screen "WELL DONE" that many times

/* write a program to input an integer value from keyboard
and display on screen "WELL DONE" that many times*/

#include
#include
void main()
{
int n,i;
clrscr();
cout<<"Enter a Number:- ";
cin>>n;
cout<<"\n\n\n";
for(i=0;i{
cout<<"\t\tWELL DONE\n";
}
getch();
}



Write a program to read two numbers from the keyboard and display the larger value on the screen

/* Write a program to read two numbers from the keyboard
and display the larger value on the screen.*/

#include
#include

class largest
{
int d;
public :
void getdata(void);
void display_large(largest,largest);
};

void largest :: getdata(void)
{
cout<<"\n\nEnter Value :-";
cin>>d;
}

void largest :: display_large(largest o1,largest o2)
{
if(o1.d > o2.d)
cout<<"\nObject 1 contain Largest Value "< else if(o2.d > o1.d)
cout<<"\nObject 2 contain Largest Value "< else
cout<<"\nBOTH ARE EQUAL";
}


void main()
{
largest o1,o2,o3;
clrscr();

o1.getdata();
o2.getdata();

o3.display_large(o1,o2);
getch();
}



write a program demonstrating cout statement

/*write a program to display the following output using a
single cout statement.
Maths = 90
physics = 77
chemistry = 69 */

#include
#include
void main()
{
clrscr();
cout<<"OUTPUT PROGRAM\n\n\n";
cout<<"\tMaths = 90\n"<<"\tPhysics = 77\n"<<"\tChemistry = 69\n";
getch();
}