Вы находитесь на странице: 1из 64

RAJHANS VIDYALAYA

COMPUTER PRACTICAL FILE (C++)

NAME: Soumalya Roy

CLASS: 12 ‘C’

SUBMITTED TO: GEETHA MA’AM


INDEX

1. Menu based program for matrix.

2. Complex Number structure program.

3. Structure Program of Country,Capital and Per Capita Income.

4. Telephone Directory Simulation Program.

5. TICKET BOOTH Program.

6. ADMISSION.

7. FLIGHT BOOKING.

8. CLOTHING.

9. Sales Customer Program using inheritance.

10. BOOK AND TAPE PUBLICATION.

11. MIN, MAX, SUM OF ARRAY AND SEARCH IN ARRAY.

12. Bubble, SELECTION, INSERTION SORT.

13. MERGING ARRAY.

14. POPING AND PUSHING .

15. STACK FOR PINCODE AND NAME OF CITY.

16. INSERTION AND DELETION OF ELEMENT IN QUEUE.

17. LINED LIST FOR NAME AND AGE.

18. CIRCULAR QUEUE.

19. BANK MANAGEMENT.

20. TELE INFORMATION.

21. MODIFY RECORD OF CUSTOMER.

22. SHOP MANAGEMENT.

23. SQL.
RAJHANS VIDYALAYA
ANDHERI-WEST
MUMBAI

CERTIFICATE

This is to certify that this computer practical file has been completed by SOUMALYA
ROY of class XII board roll no. ______________ , in partial fulfillment of the curriculum
of the CENTRAL BOARD OF SECONDARY EDUCATION leading to the award of All India
Senior School Certificate for the year 2019-2020.

____________________ ______________________
External Examiner Internal Examiner
Date: Date:

____________________ ______________________
SCHOOL SEAL PRINCIPAL
Date:
1. Menu based program for matrix.

#include<iostream>
using namespace std;
int main()
{int i,j,m,n,p,q ,a[5][5],b[5][5],c[5][5];
cout<<"Enter the number of rows and columns of 1st matrix" ;
cin>>m>>n;
cout<<" \n Enter the values of 1st matrix \n";
for( i=0;i<m;i++)
{for( j=0;j<n;j++)
cin>>a[i][j];
}
cout<<"\n Enter the no.of rows and columns for 2nd matrix";
cin>>p>>q;
cout<<"\n Enter the values for 2nd matrix \n";
for(i=0;i<p;i++)
{for(j=0;j<q;j++)
cin>>b[i][j];}
cout<<" \n Enter the Menu \n";
cout<<"1.Add them and display the result \n";
cout<<"2.Display upper and lower Triangle \n";
cout<<"3.Multiply and display the result \n";
cout<<"4.Ad the diagonal elements and display the result \n";
char ch,again;
do{
cout<<"Enter the option you want to perform";
cin>>ch;
switch(ch)
{
case '1': { cout<<"Adding the two matrices \n";
for(i=0;i<p;i++)
{for(j=0;j<q;j++)
c[i][j]=a[i][j]+b[i][j];
}
cout<<"On adding the final matrix is: \n";
for(i=0;i<p;i++)
{ cout<<"\n";
for(j=0;j<q;j++)
cout<<c[i][j]<<"\n";}
cout<<endl; }break;
case '2': { cout<<" \n Lower triangular matrix of a and b \n";
for (i=0;i<m;i++)
{ for (j=0;j<n;j++)
{ if(i < j)
{ cout << "0" << " "; }
else
cout <<a[i][j] << " "; }
cout<<endl<<"\n"; }
for (i=0;i<p;i++)
{ for (j=0;j<q;j++)
{ if(i < j)
{ cout << "0" << " "; }
else
cout <<b[i][j] << " "; }
cout<<endl<<"\n"; }
cout<<" \n Upper triangular matrix of a and b \n";
for (i=0;i<m;i++)
{ for (j=0;j<n;j++)
{ if(i>j)
{ cout << "0" << " "; }
else
cout <<a[i][j] << " "; }
cout<<endl<<"\n"; }
for (i=0;i<p;i++)
{ for (j=0;j<q;j++)
{ if(i>j)
{ cout << "0" << " "; }
else
cout <<b[i][j] << " "; }
cout<<endl; }
} break;
case '3': {cout<<"Multiplication of two matrices \n ";
int ip;
if(n==p)
{cout<<"The matrices can be multiplied \n";
{for(i=0;i<m;i++)
for(j=0;j<q;j++)
{c[i][j]=0;
for(ip=0;ip<n;++ip)
c[i][j]+= (a[i][ip]*b[ip][j]); }}
for(i=0;i<m;i++)
{ cout<<"\n";
for(j=0;j<q;j++)
cout<<c[i][j]<<"\n";
}cout<<endl;}
else
cout<<"\n The matrices cannot be multiplied \n";}break;
case '4': {cout<<"Diagonal addition";
int sum1=0,sum2=0;
for( i=0;i<m;i++)
{for (j=0;j<n;j++)
if((i+j)%2==0)
sum1+= a[i][j]; }
for(int i=0;i<p;i++)
{for (j=0;j<q;j++)
if((i+j)%2==0)
sum2+= b[i][j]; }
cout<<"the diagonal sum are:"<<sum1<<"\t"<<sum2<<endl;
}break; }
cout<<"\n Do you want to continue \n";
cin>>again;
}while(again=='Y'|| again=='y');
cout<<"\n";
return 0;}
2. Complex Number structure program.

#include<iostream>
using namespace std;
typedef struct complex{ float real;
float imaginary;
void display()
{cout<<"The real part is \n"<<real;
cout<<"THe imaginary part is \n "<<imaginary;
} } compnum;
compnum add(complex ,complex ) ;
compnum sub(complex, complex) ;
compnum multi(complex ,complex) ;
compnum div(complex ,complex) ;

int main()
{compnum n1,n2,aresult,sresult,mresult,dresult ;
char choice,ans;
cout<<"Enter the value of first complex number\n";
cin>>n1.real>>n1.imaginary;
cout<<"Enter the values of second complex number \n";
cin>>n2.real>>n2.imaginary;
cout<<"Enter the the Complex number Menu \n";
do{cout<<"1.Addition \n"<<"2.Subtraction \n"<<"3.Multiplication \n"<<"4. Division \n";
cout<<"Enter your choice \n ";
cin>>choice;
switch(choice)
{case '1' : { aresult=add(n1,n2) ;
cout<<"The addition is \n";aresult.display();
}break;
case '2' : {sresult=sub(n1,n2) ;
cout<<"The Subtraction is \n";sresult.display();
} break;
case '3' : { mresult= multi(n1,n2) ;
cout<<"The Multiplication is \n";mresult.display();
} break;
case '4' : { dresult=div(n1,n2) ;
cout<<"The Division is \n";dresult.display();
} break;
}
cout<<"\n Do you want to continue \n";
cin>>ans;
}while(ans=='Y' || ans=='y');
return 0;
}

compnum add(complex n1,complex n2)


{ compnum temp;
temp.real= n1.real+n2.real;
temp.imaginary=n1.imaginary+n2.imaginary;
return(temp);
}
compnum sub(complex n1,complex n2)
{ compnum temp;
temp.real= n1.real - n2.real;
temp.imaginary=n1.imaginary - n2.imaginary;
return(temp);
}
compnum multi(complex n1,complex n2)
{ compnum temp;
temp.real= n1.real * n2.real;
temp.imaginary=n1.imaginary * n2.imaginary;
return(temp);
}
compnum div(complex n1,complex n2)
{ compnum temp;
temp.real= n1.real / n2.real;
temp.imaginary=n1.imaginary / n2.imaginary;
return(temp);
}
3. Structure Program of Country,Capital and Per Capita Income.

#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<string.h>
using namespace std;
struct country{
char country_name[20];
char capital_name[20];
float incm; };
typedef country C;
int main()
{ C c[50];
for(int i = 0; i<4; i++)
{cout<<"\n Enter Country's name :";
cin>>c[i].country_name;
cout<<"\n Enter the name of Capital :";
cin>>c[i].capital_name;
cout<<"\n Enter per capita incme:";
cin>>c[i].incm;
}
char cname[20];
char capital[20];
char choice;
int n;
do
{ cout<<"\n ***********MENU***********\n\n";
cout<<" 1. Know Capital for a country :";
cout<<"\n 2. Know County for a capital :";

cout<<"\n\n Enter your choice :";


cin>>n;
switch(n)
{ case '1':{cout<<"\n Enter a country name :";
cin>>cname;
for(int i=0; i<4; i++)
{if(strcmp(c[i].country_name, cname)==0)
cout<<"The capital of "<< c[i].country_name <<" is " << c[i].capital_name ;
cout<<"\n Per caita income = Rs. "<< c[i].incm;
break;
}}break;
case '2': {cout<< "\n Enter a capital name :";
cin>>capital;
for(int i=0; i<4; i++)
if(strcmp(c[i].capital_name, capital)==0)
{ cout<<"\nThe capital of "<< c[i].capital_name <<" is " << c[i].country_name ;
cout<<"\n Per capita income = Rs. "<< c[i].incm;
break;}
} break;
default: cout<<"\n Wrong Input! "; }
cout<<"\n\n Do you want to continue (Y/N) :";
cin>>choice;
}while(choice == 'Y' || choice == 'y');
return 0;
4. Telephone Directory Simulation Program.
#include<iostream>
#include<cstring>
using namespace std;
const int s = 5;
struct PERSON
{
char fname[25];
char lname[25];
long int tel;
}td[s],t;
void swa(PERSON &s1,PERSON &s2)
{
strcpy(t.fname,s1.fname);
strcpy(t.lname,s1.lname);
t.tel = s1.tel;
strcpy(s1.fname,s2.fname);
strcpy(s1.lname,s2.lname);
s1.tel = s2.tel;
strcpy(s2.fname,t.fname);
strcpy(s2.lname,t.lname);
s2.tel = t.tel;
}
int main()
{
int i,j;
for(i=0;i<s;++i)
{
cout<<"PERSON "<<i+1<<endl;
cin>>td[i].fname>>td[i].lname>>td[i].tel;
}
for(i=0;i<s;++i)
{
for(j=0;j<s-1;++j)
{
if(strcmp(td[j].lname,td[j+1].lname)>0)
swa(td[j],td[j+1]);
else if(strcmp(td[j].lname,td[j+1].lname)==0)
if(strcmp(td[j].fname,td[j+1].fname)>0)
swa(td[j],td[j+1]);
}}
cout<<"\n After swapping\n";
for(i=0;i<s;++i)
{
cout<<"PERSON "<<i+1<<endl;
cout<<td[i].lname<<" "<<td[i].fname<<" , "<<td[i].tel<<endl;
}
return 0;
}
5. Ticket Booth Class Program.
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<conio.h>
using namespace std;
class ticbooth
{
int nop;
float amount;
public:
ticbooth()
{
nop=0;
amount=0;
}
void fair();
void display();
void displaynop();
};
void ticbooth::fair()
{
nop++;
amount+=2.50;
cout<<"\nThe no. of people and the total have beem incremented"<<nop++<<amount;
}
void ticbooth::display()
{
cout<<"\nThe number of people who have entered the fair are:"<<nop<<endl;
cout<<"The total amount collected till now is:"<<amount<<endl;
}
void ticbooth::displaynop()
{
cout<<"The no. of people who have visited so far are:"<<nop<<endl;
}
int main()
{
char ch='y';
int choice;
ticbooth T1;
l1:cout<<"\n\n\n\n1.Increment person and total"<<endl;
cout<<"2.Display no. of people and the amount collected till now"<<endl;
cout<<"3.Display no. of people who entered"<<endl;
cout<<"4.Exit"<<endl;
cout<<"Enter your choice:";
cin>>choice;
switch(choice)
{
case 1:T1.fair();
goto l1;
break;
case 2:T1.display();
goto l1;
break;
case 3:T1.displaynop();
goto l1;
break;
case 4:
exit(0);
break;
}
return 0;
}
6. Admission Program.

#include<iostream>
#include<conio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
using namespace std;
class ADMISSION
{
int ad_no;
char name[21];
char cls;
float fees;
public:
void Read_data();
void display();
void draw_nos();
};
void ADMISSION::Read_data()
{

cout<<"Enter admission number(10-2000): ";


cin>>ad_no;
cin>>name;
cin>>cls;
cin>>fees;

}
void ADMISSION::display()
{
cout<<"ADMISSION number is: "<<ad_no;
cout<<"Name of the student is: "<<name;
cout<<"Class of the student is: "<<cls;
cout<<"Fees of the student is: "<<fees;
}
void ADMISSION::draw_nos()
{
int adno;
adno=random(ad_no);
if(ad_no==adno)
display(); }
int main()
{
ADMISSION a1;
a1.Read_data();
a1.display();
return 0;
}
7. Flight Program using Class.
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
using namespace std;
class Flight
{ int FlightNumber;
char Destination[25];
float Distance;
float Fuel;
CalFuel()
{ if(Distance <= 1000)
Fuel = 500;
else if(Distance > 1000 && Distance <= 2000)
Fuel = 1100;
else
Fuel = 2200;}
public:
void Feed_Info()
{ cout<<"\nENTER DESTINATION:\n";
gets(Destination);
cout<<"\nENTER FLIGHT NUMBER:\n";
cin>>FlightNumber;
cout<<"\nENTER DISTANCE TRAVELLED:\n";
cin>>Distance;
CalFuel(); }
void Show_Fuel()
{ cout<<"\nFLIGHT NUMBER: "<<FlightNumber;
cout<<"\nDESTINATION: "<<Destination;
cout<<"\nDISTANCE: "<<Distance;
cout<<"\nFUEL: "<<Fuel;
}};
int main()
{ Flight F1;
F1.Feed_Info();
F1.Show_Fuel();
return 0; }
8. Clothhing Program using Class.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
class CLOTHING
{
char Code[5];
char Type[15];
int Size;
char Material[15];
float price;
void Calc_Price()
{
if(strcmp(Material,"COTTON")==0)
{
if(strcmp(Type,"TROUSER")==0)
price = 1500;
else if(strcmp(Type,"SHIRT")==0)
price = 1200;
}
else
{
if(strcmp(Type,"TROUSER")==0)
price = 1500*0.75;
else if(strcmp(Type,"SHIRT")==0)
price = 1200*0.75 ;
}}
public:
CLOTHING()
{
strcpy(Code,"N/A");
strcpy(Type,"NOT ASSIGNED");
strcpy(Material,"NOT ASSIGNED");
Size = 0;
price = 0.0;
}
void ENTER()
{
cout<<"\nENTER CODE: ";
cin>>Code;
cout<<"\nENTER MATERIAL: ";
cin>>Material;
cout<<"\nENTER TYPE: ";
cin>>Type;
Calc_Price();
cout<<"\nENTER SIZE: ";
cin>>Size;
}
void SHOW()
{
cout<<"\nCODE: "<<Code;
cout<<"\nTYPE: "<<Type;
cout<<"\nSIZE: "<<Size;
cout<<"\nMATERIAL: "<<Material;
cout<<"\nPRICE: "<<price;
}};
int main()
{
CLOTHING C1;
C1.ENTER();
C1.SHOW();}
9. Sales Customer Program using inheritance.

#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
class PERSON
{ protected:
int ID;
char name[20];
char Address[30];
public:
void read()
{ cout<<"\nENTER ID NO.: \n";
cin>>ID;
cout<<"\nENTER NAME: \n";
cin>>name;
cout<<"\nENTER ADDRESS: \n";
cin>>Address;
}
void display()
{
cout<<"\nID NUMBER: "<<ID;
cout<<"\nNAME: "<<name;
cout<<"\nADDRESS: \n"<<Address;
}
};
class CUSTOMER:protected PERSON
{ int quan;
char dos[10],des[30];
float unitprice;
float discountpercentage;
float salestax;
float Price;
void Calculate()
{Price = (quan*unitprice) + ((salestax*quan*unitprice)/100) -
((discountpercentage*quan*unitprice)/100);
}
public:
void Read()
{ PERSON :: read();
cout<<"\nENTER QUANTITY: ";
cin>>quan;
cout<<"\nUNIT PRICE: ";
cin>>unitprice;
cout<<"\nENTER DATE OF SALE: ";
cin>>dos;
cout<<"\n Description of product:";
cin>>des;
cout<<"\nENTER DISCOUNT PERCENTAGE: ";
cin>>discountpercentage;
cout<<"\nENTER SALES TAX LEVIED: ";
cin>>salestax;
Calculate();
}
void Display()
{ PERSON :: display();
cout<<"\nQUANTITY: \n"<<quan;
cout<<"\nUNIT PRICE: \n"<<unitprice;
cout<<"\nDATE OF SALE: \n"<<dos;
cout<<"\n Description: \n"<<des;
cout<<"\nDISCOUNT: \n"<<discountpercentage;
cout<<"\nTAX CHARGE: \n"<<salestax;
cout<<"\nPRICE: \n"<<Price;
}};
int main()
{CUSTOMER C;
C.Read();
C.Display();
return 0;
}
10. Inheritance Program of Publications,Tape and Book.

#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
using namespace std;
class Publication
{
public:
char title[15];
float price;
void getdata()
{
cout<<"\nENTER TITLE: \n";
cin>>title;
cout<<"\nENTER PRICE: \n";
cin>>price;
}
void putdata()
{
cout<<"\nTITLE: "<<title;
cout<<"\tPRICE: "<<price;
}};
class Book : public Publication
{
public:
int pgcnt;
void getdata()
{
Publication :: getdata();
cout<<"\nENTER PAGE COUNT OF BOOK: \n";
cin>>pgcnt;
}
void putdata()
{
Publication :: putdata();
cout<<"\tPAGE COUNT: "<<pgcnt;
}};
class Tape : public
Publication
{
public:
char ptime[30];
void getdata()
{
Publication :: getdata();
cout<<"\nENTER PLAY TIME OF TAPE: ";
cin>>ptime;
}
void putdata()
{
Publication :: putdata();
cout<<" \tPLAY TIME: "<<ptime;
}};
int main()
{ int ch;
char ch1;
do{ cout<<"\nENTER YOUR CHOICE: ";
cout<<"\n1. BOOK";
cout<<"\n2. TAPE\n";
cin>>ch;
switch(ch)
{ case 1:
Book B1;
B1.getdata();
B1.putdata();
break;
case 2:
Tape T1;
T1.getdata();
T1.putdata();
break;
default:
cout<<"\nWRONG CHOICE !!";
break; }
cout<<"\nWANT TO ENTER MORE(y/n)?\n";
cin>>ch1;
}while(ch1 == 'y' || ch1 == 'Y');
return 0;}
11. Menu Driven Program for Integers in an Array.
#include<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;
int BSearch(int [],int,int);
int LARGE(int [],int);
int SMALL(int [],int);
int SUM(int [], int);
int main()
{
int AR[50],ITEM,N,index,i;
int big;
int small;
int SOA; char choice;
do{cout<<"\nENTER DESIRED ARRAY SIZE: ";
cin>>N;
cout<<"\nENTER ARRAY ELEMENTS:\n";
for(i = 0;i < N;++i)
cin>>AR[i];
cout<<"\nENTER ELEMENT TO BE SEARCHED: ";
cin>>ITEM;
index = BSearch(AR,N,ITEM);
{
if(index==-1)
cout<<"\nSORRY!GIVEN ELEMENT COULD NOT BE FOUND\n";
else
cout<<"\nELEMENT FOUND AT INDEX: "<<index<<", \t POSITION: "<<index+1;
}
big = LARGE(AR,i);
cout<<"\nLARGEST ELEMENT OF ARRAY: "<<big;
small = SMALL(AR,i);
cout<<"\nSMALLEST ELEMENT IN ARRAY: "<<small;
SOA = SUM(AR,i);
cout<<"\nSUM OF ELEMENTS IN ARRAY: "<<SOA;
cout<<"\n Do you want to continue \n";
cin>>choice;}while(choice=='Y'||choice=='y');
return 0;
}
int BSearch(int AR[],int s,int item)
{
int beg,last,mid;
beg = 0;
last = s - 1;
while(beg <=last)
{
mid = (beg+last)/2;
if(item == AR[mid])
return mid;
else if(item > AR[mid])
beg = mid + 1;
else
last = mid - 1;
}
return -1;
}
int LARGE(int AR[],int s)
{
int m = AR[0];
for(int j = 1;j < s;++j)
{
if(AR[j] > m)
m = AR[j];
}
return m;}
int SMALL(int AR[],int s)
{ int M = AR[0];
for(int j = 1;j < s;++j)
{ if(AR[j] < M)
M = AR[j];}
return M;}
int SUM(int AR[],int s)
{ int sum = 0;
for(int i = 0;i < s;++i)
{ sum += AR[i];}
return sum;}
12. Sorting Program Of One dimensional Array using Bubble Sort, Insertion
Sort and Select Sort.

#include<iostream>
#include<cstdlib>
#include<process.h>
using namespace std;
void BSort(int AR[],int s)
{
int tmp,ctr = 0;
for(int i = 0;i < s;i++)
{
for(int j = 0;j < (s-1)-i;j++)
{
if(AR[j]>AR[j+1])
{
tmp = AR[j];
AR[j] = AR[j+1];
AR[j+1] = tmp;
}
}
cout<<"\nARRAY AFTER ITERATION: "<<ctr++<<"- is: ";
for(int k = 0;k < s;k++)
cout<<AR[k]<< " ";
cout<<endl;
}
}
void SSort(int AR[],int s)
{
int small,pos,tmp;
for(int i = 0;i < s;++i)
{
small = AR[i];
pos = i;
for(int j = i+1;j < s;j++)
{
if(AR[j]<small)
{
small = AR[j];
pos = j;
}
}
tmp = AR[i];
AR[i] = AR[pos];
AR[pos]=tmp;
cout<<"\nARRAY AFTER PASS - "<<i+1<<"- is: ";
for(int j = 0;j < s;j++)
cout<<AR[j]<<" ";
}
}
void ISort(int AR[],int s)
{
int tmp,j;
AR[0] = INT_MIN;
for(int i = 1;i <= s;++i)
{
tmp = AR[i];
j = i - 1;
while(tmp < AR[j])
{
AR[j+1] = AR[j];
j--;
}
AR[j+1] = tmp;
cout<<"\nARRAY AFTER PASS- "<<i<<"- is: ";
for(int k = 1;k <= s;k++)
cout<<AR[k]<<" ";
cout<<endl;
} }
int main()
{ int AR[50],N,ch;char ans;
do{cout<<"\nENTER NO. OF ELEMENTS: ";
cin>>N;
cout<<"\nENTER ARRAY ELEMENTS: \n";
for(int i = 0;i < N;++i)
cin>>AR[i];
cout<<"\nENTER SORTING TECHNIQUE TO USE: ";
cout<<"\n1. BUBBLE SORT: ";
cout<<"\n2. SELECTION SORT: ";
cout<<"\n3. INSERTION SORT: ";
cin>>ch;
switch(ch)
{case 1:
BSort( AR,N);
break;
case 2:
SSort( AR,N);
break;
case 3:
ISort(AR,N);
break;
default:
cout<<"\nWRONG CHOICE: ";
break;
}cout<<"\n Do you want to continue \n";
cin>>ans;}while(ans=='Y'||ans=='y');
return 0; }
13. Merge of One dimensional Array.
#include<iostream>
using namespace std;
void Merge(int A[], int B[], int C[], int N, int M, int &K);
int main()
{
int A[100], B[100], C[200],i,n,m,k;

cout<<"\nEnter number of elements you want to insert in first array ";


cin>>n;

cout<<"Enter element in ascending order\n";


for(i=0;i<n;i++)
{
cout<<"Enter element "<<i+1<<":";
cin>>A[i];
}

cout<<"\nEnter number of elements you want to insert in second array ";


cin>>m;
cout<<"Enter element in descending order\n";
for(i=0;i<m;i++)
{
cout<<"Enter element "<<i+1<<":";
cin>>B[i];
}
Merge(A,B,C,n,m,k);
cout<<"\nThe Merged Array in Ascending Order"<<endl;
for(i=0;i<k;i++)
{
cout<<C[i]<<" ";
}
return 0;
}
void Merge(int A[], int B[], int C[], int N, int M, int &K)
{
int I=0, J=M-1;
K=0;
while (I<N && J>=0)
{
if (A[I]<B[J])
C[K++]=A[I++];
else if (A[I]>B[J])
C[K++]=B[J--];
else
{
C[K++]=A[I++];
J--;
}
}

for (int T=I;T<N;T++)


C[K++]=A[T];
for (int T=J;T>=0;T--)
C[K++]=B[T];
}
14. Menu Driven Program for push and pop of an element in a stack.

#include<iostream>
#include<cstdlib>
#include<process.h>
using namespace std;
const int s = 50;
void Display(int Stack[],int top)
{
if(top == -1)
return;
cout<<Stack[top]<<"<---";
for(int i=top - 1;i >= 0;i--)
cout<<Stack[i];
}
int Push(int Stack[],int &top,int ele)
{
if(top == s-1)
return -1;
else{
top++;
Stack[top] = ele;
}
return 0;
}
int Pop(int Stack[],int &top)
{
int ret;
if(top==-1)
return -1;
else
{ ret = Stack[top];
top--; }
return ret; }
int main()
{ int C;
int Stack[s],Item,top = -1,res;
char ch = 'y';
cout<<"\n1.PUSH ";
cout<<"\n2.POP ";
cout<<"\nENTER CHOICE: ";
cin>>C;
switch(C)
{ case 1:
while(ch=='y'||ch=='Y')
{ cout<<"\nENTER ITEM FOR INSERTION: ";
cin>>Item;
res = Push(Stack,top,Item);
if(res == -1)
{ cout<<"\nOVERERFLOW!!!!\n";
exit(1); }
else
{ cout<<"\nTHE STACK NOW IS:\n";
Display(Stack,top);
cout<<"\nWANT TO ENTER MORE? \n";
cin>>ch; } }
break;
case 2:
while(ch=='y'||ch=='Y')
{ cout<<"\nENTER ITEM FOR INSERTION: ";
cin>>Item;
res = Pop(Stack,top);
if(res == -1)
{ cout<<"\nUNDERFLOW!!!!\n";
exit(1); }
else
{ cout<<"\nDELETED ELEMENT: \n"<<res<<endl;
cout<<"\nSTACK NOW IS:\n";
Display(Stack,top);
cout<<"\nWANT TO ENTER MORE? \n";
cin>>ch;
}}
break;
default:
exit(0);}
return 0;}
15. Menu Driven Program for push and pop of stack containing City
pincode and name.
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<process.h>
using namespace std;
struct City
{
long Cpin ;
string CName;
City *Next ;
}*top,*newptr,*save,*ptr;
City *create_new_node(int,string);
void push(City *);
void pop();
void display(City *);
int main()
{
top=NULL;
int pin;
string name;
char ch='y';
while(ch=='y'||ch=='Y')
{ cout<<"\n**Enter Pin Code**\n";
cin>>pin;
cout<<"\n**Enter Name**\n";
cin>>name;
newptr=create_new_node(pin,name);
if (newptr==NULL)
{ cout<<"\nCANNOT CREATE NEW NODE";
exit(1); }
push(newptr);
cout<<"\n**Want to enter new node(y/n)**\n";
cin>>ch; }
do
{ cout<<"\nSTACK IS NOW\n";
display(top);
cout<<"\n**Want to pop an element(y/n)**\n";
cin>>ch;
if(ch=='y'||ch=='Y')
pop();
}while(ch=='y'||ch=='Y');
return 0; }
City *create_new_node(int pincode,string gname)
{ ptr=new City;
ptr->Cpin=pincode;
ptr->CName=gname;
ptr->Next=NULL;
return ptr; }
void push(City *np)
{ if(top==NULL)
top=np;
else
{ save=top;
top=np;
np->Next=save;
} }
void pop()
{ if(top==NULL)
cout<<"\nUNDERFLOW";
else
{ ptr=top;
top=top->Next;
delete ptr; } }
void display(City *np)
{ while(np!=NULL)
{ cout<<"\nPIN CODE: "<<np->Cpin;
cout<<"\nNAME: "<<np->CName;
np=np->Next; }
cout<<"\n!!!!\n";}
16. Program to delete and insert an elemnet in a queue.
#include<iostream>
#include<cstdlib>
#include<process.h>
using namespace std;
int Remove(int[]);
int Insert(int[],int);
void Display(int[],int,int);
const int s = 50;
int Queue[s],f=-1,r=-1;
int main()
{
int Item,res;
char ch = 'y';
while(ch=='y'||ch=='Y')
{
cout<<"\nENTER ITEM FOR INSERTION: ";
cin>>Item;
res = Insert(Queue,Item);
if(res==-1)
{cout<<"\nOVERFLOW!!!ABORTING!!\n";
exit(1);
}
cout<<"\nNOW THE QUEUE(FRONT...TO...REAR) IS: \n";
Display(Queue,f,r);
cout<<"\nWANT TO INSERT MORE(y/n)..";
cin>>ch; }
cout<<"\nNOW DELETION BEGINS: \n";
ch = 'y';
while(ch=='y'||ch=='Y')
{ res = Remove(Queue);
if(res==-1)
{ cout<<"\nUNDEFLOW!!!!ABORTING\n";
exit(1);
}
else
{ cout<<"\nELEMENT DELETED: "<<res<<endl;
cout<<"\nNOW QUEUE (FRONT...TO...REAR) IS: \n";
Display(Queue,f,r); }
cout<<"\nWANT TO DELETE MORE ELEMENTS(y/n) ";
cin>>ch; }
return 0;
}
int Insert(int Queue[],int ele)
{ if(r==s-1)
return -1;
else if(r==-1)
{ f=r=0;
Queue[r]=ele;
}else
{
r++;
Queue[r]=ele;
}
return 0;
}
int Remove(int Queue[])
{
int ret;
if(f==-1)
return -1;
else
{ ret = Queue[f];
if(f==r)
f=r=-1;
else
f++; }
return ret; }
void Display(int Queue[],int f,int r)
{ if(f==-1)
return;
for(int i = f;i < r;++i)
cout<<Queue[i]<<" <-\t";
cout<<Queue[r]<<endl;
}
17. Program to insert and delete from a linked queue.
#include <iostream>
#include <string.h>
using namespace std;
struct Node{
int stu_no;
char stu_name[50];
float p;
Node *next;
};
Node *top;
class stack{
public:
void push(int n,char name[],int perc);
void pop();
void display();
};
void stack::push(int n,char name[],int perc)
{
struct Node *newNode=new Node;
newNode->stu_no=n;
newNode->p=perc;
strcpy(newNode->stu_name,name);
newNode->next=top;
top=newNode;
}
void stack::pop()
{
if(top==NULL)
{cout<<"List is empty!"<<endl;
return;}
cout<<top->stu_name<<" is removed."<<endl;
top=top->next;
}
void stack::display()
{ if(top==NULL)
{cout<<"List is empty!"<<endl;
return;}
struct Node *temp=top;
while(temp!=NULL)
{ cout<<temp->stu_no<<" ";
cout<<temp->stu_name<<" ";
cout<<temp->p<<" ";
cout<<endl;
temp=temp->next; }}
int main()
{ stack s;
char ch;
do{ int n;
cout<<"\n**MENU**";
cout<<"\n1.Push";
cout<<"\t2.Pop";
cout<<"\t3.Display";
cout<<"\nEnter your Choice: ";
cin>>n;
switch(n)
{ case 1: Node n;
cout<<"\n**Enter the Roll Number : ";
cin>>n.stu_no;
cout<<"**Enter the Name: ";
std::cin.ignore(1);
cin.getline(n.stu_name,50);
cout<<"**Enter Percentage: ";
cin>>n.p;
s.push(n.stu_no,n.stu_name,n.p);
break;
case 2: s.pop();
break;
case 3: s.display();
break;
default: cout<<"WRONG CHOICE!!!\n"; }
cout<<"\nDo you want to continue(y/n)? ";
cin>>ch;} while(ch=='Y'||ch=='y');
return 0; }
18. Program to Insert and Delete an element in a circular queue.
#include<iostream>
#include<cstdlib>
#include<process.h>
using namespace std;
int Insert_in_CQ(int[],int);
int Display(int [],int,int);
int Del_in_CQ(int CQueue[]);
const int size1 = 7;
int CQueue[size1],front1 = -1,rear = -1;
int main()
{ int Item,res,ch;
do { cout<<"\t\tCIRCULAR QUEUE MENU:\n ";
cout<<"\n1. INSERT ";
cout<<"\n2. DELETE ";
cout<<"\n3. EXIT ";
cout<<"\nENTER YOUR CHOICE: \n";
cin>>ch;
switch(ch)
{ case 1:
cout<<"\nENTER ITEM FOR INSERTION: ";
cin>>Item;
res = Insert_in_CQ(CQueue,Item);
if(res == -1)
cout<<"\nOVERFLOW !!!\n";
else{ cout<<"\nNOW THE CIRCULAR QUEUE IS\n";
Display(CQueue,front1,rear); }
break;
case 2:
Item = Del_in_CQ(CQueue);
cout<<"\nELEMENT DELETED IS: "<<Item;
Display(CQueue,front1,rear);
break;
case 3:
break;
default:
cout<<"\nWRONG CHOICE!!! ";
break; } }
while(ch != 4);
return 0; }
int Insert_in_CQ(int CQueue[],int ele)
{ if((front1 == 0 && rear == size1 - 1)||(front1 == rear - 1))
return -1;
else if(rear == -1)
front1 = rear = 0;
else if(rear == size1 -1)
rear = 0;
else rear++;
CQueue[rear] = ele;
return 0; }
int Display(int CQueue[],int front1,int rear)
{ int i = 0;
cout<<"\nCIR_QUEUE: \n"<<"(FRONT SHOWN AS >>>>,REAR AS <<<<AND FREE SPACE AS - )\n";
if(front1 == -1)
return 1;
if(rear >= front1)
{ for(i = 0;i < front1 ;++i)
cout<<"-";
cout<<">>>>";
for(i = front1;i < rear; ++i)
cout<<CQueue[i]<<"<-";
cout<<CQueue[rear]<<"<<<<"; }else
{ for(i = 0; i < rear ; ++i)
cout<<CQueue[i]<<"<-";
cout<<CQueue[rear]<<"<<<<";
for(i = 0; i < front1 ;++i)
cout<<"-";
cout<<">>>>";
for(i = front1; i < size1 ;++i)
cout<<CQueue[i]<<"<-";
cout<<"\t...WRAP AROUND..."; }
return 0; }
int Del_in_CQ(int CQueue[])
{ int ret;
if(front1 == -1)
return-1;
else{ ret = CQueue[front1];
if(front1 == rear)
front1 = rear = -1;
else if(front1 == rear)
front1 = 0;
else front1 ++; }
return ret; }
19. Bank linked list Program to dislpay no.of people above one
lakh.
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<process.h>
using namespace std;
struct bank
{
long bbal ;
string bName;
bank *Next ;
}*top,*newptr,*save,*ptr;
bank *create_new_node(int,string);
void push(bank *);
void pop();
void display(bank *);
void rich(bank *);
int main()
{
top=NULL;
int bb;
string name;
char ch='y';
while(ch=='y'||ch=='Y')
{
cout<<"\n**Enter Bank Balance: ";
cin>>bb;
cout<<"\n**Enter the Name: ";
cin>>name;
newptr=create_new_node(bb,name);
if (newptr==NULL)
{
cout<<"\nCannot create new node ";
exit(1);
}
push(newptr);
cout<<"\nDo you want to continue(y/n): ";
cin>>ch;
}
do
{
cout<<"\n Stack now is: ";
display(top);
cout<<"\nWant to pop an element(y/n)?";
cin>>ch;
if(ch=='y'||ch=='Y')
pop();
}while(ch=='y'||ch=='Y');
rich(top);
return 0;
}
bank *create_new_node(int bankbal,string gname)
{
ptr=new bank;
ptr->bbal=bankbal;
ptr->bName=gname;
ptr->Next=NULL;
return ptr;
}
void push(bank *np)
{
if(top==NULL)
top=np;
else
{
save=top;
top=np;
np->Next=save;
}
}
void pop()
{
if(top==NULL)
cout<<"\n Underflow";
else
{
ptr=top;
top=top->Next;
delete ptr;
}
}
void display(bank *np)
{
while(np!=NULL)
{
cout<<"\n Bank Balance :"<<np->bbal;
cout<<"\n Name :"<<np->bName;
np=np->Next;
}
cout<<"\n!!!!\n";
}
void rich(bank *ri)
{
int c=0;
while(ri!=NULL)
{
if(ri->bbal>100000)
{c++;}
ri=ri->Next;
}
cout<<"\n\nPeople having Bank Balance more than One Lakh are "<<c;
}
20. File handling Program of Tele.txt to search for record.
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
class info
{ int tno;
char name[15];
char address[25];
int acode;
long pno;
public:
void getdata()
{ cout<<"\n**Enter T.no**\n";
cin>>tno;
cout<<"\n**Enter Name**\n";
cin>>name;
cout<<"\n**Enter Phone no**\n";
cin>>pno;
cout<<"\n**Enter Address**\n";
cin>>address;
cout<<"\n**Enter Area code**\n";
cin>>acode; }
void display()
{ cout<<"\nT.no: "<<tno;
cout<<"\nName: "<<name;
cout<<"\nAddress: "<<address;
cout<<"\nArea code: "<<acode;
cout<<"\nPhone no: "<<pno; }
int check()
{return tno;}
void addrec()
{ fstream fout;
fout.open("tele.txt",ios::in|ios::out|ios::app);
getdata();
fout.write((char*)this,sizeof(info));
fout.close(); }
void searc(int r)
{ fstream fout;
fout.open("tele.txt",ios::in|ios::out);
while(fout.read((char*)this,sizeof(info)))
{ if(tno==r)
{display();} }
fout.close();
} };
int main()
{
info i1;
int x,y;
char ch;
do{ cout<<"\n1.Add Record";
cout<<"\n2.View Record";
cout<<"\nEnter your Choice ";
cin>>y;
switch(y)
{ case 1: i1.addrec();
break;
case 2: cout<<"\n**Enter T.no**\n";
cin>>x;
i1.searc(x);
break;
default: cout<<"\nWRONG CHOICE!!!!"; }
cout<<"\nDo you want to continue(y/n) ";
cin>>ch;
}while(ch=='y'||ch=='Y');
return 0;}
21. MODIFY RECORD OF CUSTOMER

#include<fstream>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
using namespace std;
class file
{
private:
int ccode;
float age;
int dd,mm,yy;
char name[100];
char ad[100];
public:
void input();
void show();
char *getn()
{
return name;
}
};file fileobj;
void file::input()
{
cout<<"Enter the Customer Code: ";
cin>>ccode;cout<<endl;
cout<<"Enter the Age: ";
cin>>age;cout<<endl;
cout<<"Enter the Name (First Name is enough): ";
cin>>name;cout<<endl;
cout<<"Enter the Address: ";
cin>>ad;cout<<endl;
cout<<endl<<"ENTER DATE OF PURCHASE:"<<endl;
cout<<"DATE : "; cin>>dd;
cout<<"MONTH: "; cin>>mm;
cout<<"YEAR : "; cin>>yy;cout<<endl;
}
void file::show()
{
cout<<"Customer Code==> "<<ccode<<endl;
cout<<"Age ==> "<<age<<endl;
cout<<"Name==> "<<name<<endl;
cout<<"Address==> "<<ad<<endl;
cout<<"DATE OF PURCHASE: "<<dd<<"/"<<mm<<"/"<<yy<<endl;
}
void Create();
void Add();
void Display();
void DisplayP();
void Modify();
void Delete();
fstream fil;
int main()
{ int opt;
while(1)
{ cout<<"\n1.Create Data File"<<endl;
cout<<"2.Add New Record "<<endl;
cout<<"3.Display Record "<<endl;
cout<<"4.Modify A Particular Record "<<endl;
cout<<"5.Delete A Particular Record "<<endl;
cout<<"6.Exit From the Program"<<endl;
cout<<"Enter your Option : "<<endl;
cin>>opt;cout<<endl;
switch(opt)
{ case 1: { Create();
cout<<"\nDisplay Main Menu------"<<endl;
getch();
break;}
case 2:
{ Add();
cout<<"\nDisplay Main Menu------"<<endl;
getch();
break;}
case 3:
{ Display();
cout<<"\nDisplay Main Menu------"<<endl;
getch();
break;
}
case 4:
{ Modify();
cout<<"\nDisplay Main Menu------"<<endl;
getch();
break; }
case 5:
{ Delete();
cout<<"\nDisplay Main Menu------"<<endl;
getch();
break;
}
case 6:{exit(0);}
default:
{
cout<<"Wrong Choice....Press Key For View the Main Menu.";
getch();

} } } }
void Create()
{ char ch='y';
fil.open("binary.txt",ios::out);
while(ch=='y' || ch =='Y')
{ fileobj.input();
fil.write((char*)&fileobj, sizeof(fileobj));
cout<<"\nWant to Continue.....(y- for yes): ";
cin>>ch; }
fil.close();
}
void Add()
{ char ch='y';
fil.open("binary.txt",ios::app);
while(ch=='y' || ch =='Y')
{ fileobj.input();
fil.write((char*)&fileobj, sizeof(fileobj));
cout<<"\nWant to Continue?.....";
cin>>ch;
} fil.close();
}

void Display()
{ fil.open("binary.txt",ios::in);
if(!fil)
{ cout<<"\nFile not Found.";
exit(0);
}
else
{ fil.read((char*)&fileobj, sizeof(fileobj));
while(!fil.eof())
{ fileobj.show();
cout<<"\nPress Any Key....For Next Record."<<endl;
getch();
fil.read((char*)&fileobj, sizeof(fileobj)); }
} fil.close();
}
void Modify()
{ char n[100];
cout<<"\nEnter Name that should be searched: ";
cin>>n;
fil.open("binary.txt",ios::in| ios::out);
if(!fil)
{ cout<<"\nFile not Found.";
exit(0); }
else
{ fil.read((char*)&fileobj, sizeof(fileobj));
while(!fil.eof())
{ if(strcmp(n,fileobj.getn())==0)
{ fil.seekg(0,ios::cur);
cout<<"\nEnter New Record...."<<endl;
fileobj.input();
fil.seekp(fil.tellg() - sizeof(fileobj));
fil.write((char*)&fileobj, sizeof(fileobj)); }
else
{ cout<<"\nPress Any Key....For Search."<<endl;
getch();}
fil.read((char*)&fileobj, sizeof(fileobj));
} } fil.close(); }
void Delete()
{ char n[100];
cout<<"\nEnter Name that should be Deleted: ";
cin>>n;
ofstream o;
o.open("new.txt",ios::out);
fil.open("binary.txt",ios::in);
if(!fil)
{
cout<<"\nFile not Found.";
exit(0);
}
else
{
fil.read((char*)&fileobj, sizeof(fileobj));
while(!fil.eof())
{
if(strcmp(n,fileobj.getn())!=0)
{
o.write((char*)&fileobj, sizeof(fileobj));
}
else
{
cout<<"\nPress Any Key....For Search."<<endl;
getch();
}
fil.read((char*)&fileobj, sizeof(fileobj));
}
}
o.close();
fil.close();
remove("binary.txt");
rename("new.txt", "binary.txt");
}
22. Price Program.
#include <iostream>
#include <fstream>
#define FILE_NAME "price.txt"
using namespace std;
class Item {
int icd[3];
int ict[3];
int qty[3];
int ttl[3];
int total=0;
public:
void Itp()
{
cout<<"**Item Details ";
for(int i=0;i<3;i++)
{
cout<<"\n**Enter Item Code**\n";
cin>>icd[i];
cout<<"**Enter Item Cost**\n";
cin>>ict[i];
cout<<"**Enter Item Quantity**\n";
cin>>qty[i];
ttl[i]=ict[i]*qty[i];
total=total+(ict[i]*qty[i]);
}
}
void displayI()
{
cout<<"ITEM CODE\t PRICE/UNIT\t QUANTITY\t TOTAL COST \n";
for(int i=0;i<3;i++)
{
cout<<icd[i]<<"\t\t"<<ict[i]<<"\t\t"<<qty[i]<<"\t\t"<<ttl[i]<<endl;
}
cout<<"Total:- "<<total;
}
};
int main()
{
Item I;
I.Itp();
fstream file;
file.open(FILE_NAME,ios::out);
if(!file){
cout<<"Error in creating file...\n";
return -1;
}
file.write((char*)&I,sizeof(I));
file.close();
cout<<"Date saved into file the file.\n";
file.open(FILE_NAME,ios::in);
if(!file){
cout<<"Error in opening file...\n";
return -1;
}
if(file.read((char*)&I,sizeof(I))){
cout<<endl<<endl;
cout<<"Data extracted from file..\n";
I.displayI();
}
else{
cout<<"Error in reading data from file...\n";
return -1;
}
file.close();
return 0;
}
23. SQL Program.
(i)

(ii)

(iii)
(iv)

(v)

(vi)

(vii)

(viii)

Вам также может понравиться