Sei sulla pagina 1di 119

LAB PRACTICAL FILE (C++ & SQL)

ROLL NO-

CHANDAN MISHRA Mrs. APEKSHA JOSHI


CLASS=XII-SCIENCE
INDEX

S PAGE DATE REMARK


NO Program NO.
Write a program to input day number of a week and display
the corresponding week day. 12/04/18
1
write a program to enter two numbers m and n and display m
multiples of n. 12/04/18
2
Write a program to read a string and print out the
Following :
3 [1].No. of capital alphabets.
12/04/18
[2].No. of small alphabets.
[3].No. of non-alphabets.

Write a program to read a string and print it after


replacing each of its capital alphabet by corresponding small 12/04/18
4 alphabet and each small alphabet by its corresponding capital
alphabet.

Write a program to store information of 10 employees and to


display of an employee 12/04/18
5 depending upon the employee number given by the user
using structure.

Write a menu driven program to calculate the TSA and


volume of a cube,cuboid,or 24/04/18
6 cylinder depending upon user’s choice. (using
Function overloading).

Define a class Outfit in C++ with the


following description
7 Private: OCode of type string
OType of Type string
OSize of type string
OFabric of type sTring
Price of type f loat
A function InitPrice() which calculates and
Assign the value of OPrice as follows:
For the v alue of OFabric as “ DENIM” 3/05/18
Type Price
TROUSER 1500
JACKET 2500
For the material other than “ DENIM” the above
mentioned Price gets reduced by 25%.
Public: A function Input( ) to input the value of the data
members OCode, OType, OSize and OFabric and invoke the
function InitPrice() .
A Display function That display the content of all the data
members for the Outfit.

.Define a class student with the following specifications:


Private members of the class:
8 Admission Number-An Integer
Name -string of 20 characters
Class -Integer Roll Number-Integer
3/05/18
Public members of the cl ass:
getdata( )-To input the data
showdata( )-To display the data
Write a program to define an array of 10 object of this class,
input the data in this array and then display this list .

Create a class PERSON with the following specifications :


Private : Data members : name-character string, ph long.
9 Public : A constructor that initialize the name as ‘NULL’
and phone number as 0.
 Getdata() – to get all values from the user. 10/05/18
 Putdata() – to display all the data.
A destructor to destruct all the constructor .

Write a program to input the name of a text file from t he


user and display :
10 a)The number of blanks present in the file.
b)The number of lines present in the file.
c)The number of capital alphabets present in the f ile. 5/07/18
d)The number of small alphabets present in the f ile.
e)The number of lines starting with a capital alphabet .
f ) The number of words present in the f ile.
g)The number of digits present in the file.
The number of words ending with a vowel.
Write a program to input a text file name, read the contents
11 of the file and create a new file named COPY.TXT, which 5/07/18
shall contain only those words from the original file which
don’t start with an upper case vowel.
. Declare a structure telerec in C++, containing name[20] and
12 telephone number. Wrtite a program to maintain a file
telephone record. the program should allow the following
functions on the file :
12/07/18
1) To append records in the file .
2) Display the name and the telephone number .if the
telephone number .If telephone number does not
exixst display error message “record not found”.
3) Display the telephone number9s0 for a given
name.If the name does not exixt then display
“record not found”.

A blood bank maintains a data file that contains the


13 following : Name, Date of Birth, Telephone number , Blood
group. Write a program in C++ to do the following:
1)Given a blood group,display name,date of birth and
12/07/18
phone number of all the persons of the given blood group.
2)Append records in the file.
3)Input a telephone number and modify the record.
Write a menu driven program in C++ to perform the
14 following functions on a binary file“ BOOK.DAT”
containing objects of the class book:
1.Append Record,
2. Modify a record for a given book no. 19/07/18
3. Delete a record with a given book no.
4. Search for a record with a given Book name
5. Display a sorted list of records ( sort on Book No. )
Display a sorted list of records ( Sor t on Book Name).
Write a program to perform Linear Search in an 16/08/18
15 array. ( Using functions).
Write a program to perform Binary Search in an 16/08/18
16 array ( Using funCTION)
Write a program to insert an element at a 16/08/18
17 ParTicular location in an array.
Write a pRogram to delete an element from an 16/08/18
18 Array.
Write a progam to perform Sel eTcion Sort to an 23/08/18
19 Array.
Write a progam to perform Sel eTcion Sort to an 23/08/18
20 Array.
Write a program to implement Insertion Sort to an array . 23/08/18
21
Write a program to merge two arrays which are
22 In ascending order, to give resultant in ascending/ 23/08/18
descending order.
Write a function in C++ which accepts an integer
23 Array and its size as arguments/ parameters and exchanges 30/08/18
the values of first half side elements with the second half
side elements of the array .
Write a function in C++ which accepts an integer array and
24 its size as arguments/ parameters and
Assigns the elements in to a two dimensional array of
Integers in the following format :
If the array is1, 2, 3, 4, 5, 6 If the array is 1,2,3
The resultant 2D array is: The resultant 2D array is:
1 2 3 4 5 6 1 2 3 30/08/18
1 2 3 4 5 0 1 2 0
1 2 3 4 0 0 1 0 0
1 2 3 0 0 0
1 2 0 0 0 0
1 0 0 0 0 0
Write a menu driven program which allows the user to
25 perform the following operations on a stack( Array 1/10/18
implementation ) :
1)Push 2)Pop 3) Display
Write a menu driven program which allows the user to
26 perform the following operations on a queue ( Array 1/10/18
implementation) :
1)Insert 2)Delete 3)Display

Write a menu driven program which allows the user to


27 perform the following operations on a stack( Linked 8/10/18
implementation) : 1)Push 2)Pop 3)Display

Write a menu driven program which allows the user to


28 perform the following operations on a queue ( linked 8/10/18
implementation) :
1)Insert 2)Delete 3)Display
Write a menu driven program which allows the user to
29 perform the following operations on a circular queue (Array 11/10/18
implementation) : 1)Push 2)Pop 3)Display.
Write a menu driven program which allows the user to
30 perform the following operations on a circular queue 11/10/18
( linked implementation) :
1)Insert 2)Delete

SQL
S PAGE DATE REMARK
PROGRAM NO.
no .
1
Create the table Employee. 29/10/18

2 Create the table Department. 29/10/18

3 Insert data in the table Employee. 29/10/18

4 Insert data in the table Department. 29/10/18

5 Display the details of all the employees 29/10/18

6 Display the Salary, Zone, and Grade of all the 29/10/18


employees.
Display the records of all the employees along
7 with their annual salaries. The Salary column 29/10/18
of the table contains monthly salaries of the
employees.
Display the records of all the employees along
8 with their annual salaries. The Salary column 29/10/18
of the table contains monthly salaries of the
employees. The new column should be given the
name “Annual Salary”.

9. Display the details of all the employees who are 29/10/18


below 30 years of age
Display the names of all the employees working
10. in North zone. 29/10/18
Display the salaries of all the employees of
11. department 10. 29/10/18
Display the details of all the employees whose
12. Grade is NULL. 12/11/18
Display the details of all the employees whose
13. Grade is not NULL. 12/11/18
Display the names of various zones from the
14. table Employee. A zone name should appear 12/11/18
only once.
Display the various department numbers from
15. the table Employee. A department number 12/11/18
should be displayed only once.
Display the details of all the employees of
16. department 10 who are above 30 years of age. 12/11/18

Display the details of all the employees who are


17. getting a salary of more than 35000 in the 12/11/18
department 30.
Display the names and salaries of all the
18. employees who are not working in department 12/11/18
20.
Display the names and salaries of all the
19. employees who are working neither in West 12/11/18
zone nor in Centre zone.
Display the names of all the employees who
20. are working in department 20 or 30. 12/11/18

Display the details of all the employees whose


21. salary is between 32000 and 38000. 12/11/18

Display the details of all the employees whose


22. grade is between ‘A’and‘C’. 12/11/18

Display the details of all the employees aged


23. above 30 in West zone. Using IN Operator 12/11/18

Display the names of all the employees who are


24. working in department 20 or 30. (Using IN 26/11/18
operator)
Display the names and salaries of all the
25. employees who are working neither in West 26/11/18
zone nor in Centre zone. (Using IN operator)
Using BETWEEN Operator
Display the details of all the employees whose
26. salary is between 32000 and 38000. (Using 26/11/18
BETWEEN operator)
Display the details of all the employees whose
27. grade is between ‘A’ and ‘C’. (Using 26/11/18
BETWEEN operator) .
Display the name, salary, and age of all the
28. employees whose names start with ‘M’. 26/11/18

Display the name, salary, and age of all the


29. employees whose names end with ‘a’. 26/11/18

Display the name, salary, and age of all the


30. employees whose names contain ‘a’. 26/11/18

Display the name, salary, and age of all the


31. employees whose names do not contain ‘a’ 26/11/18

Display the details of all the employees whose


32. names contain ‘a’ as the second character. 26/11/18
Using Aggregate functions
Display the sum and average of the salaries of
33. all the employees. 29/11/18

Display the highest and the lowest salaries


34. being paid in department 10. 29/11/18

Display the number of employees working in


35. department 10. 29/11/18

Display the details of all the employees in the


36. ascending order of their salaries. 29/11/18

Display the details of all the employees in the


37. descending order of their names. 29/11/18

Display the details of all the employees in the


38. ascending order of their grades and within 29/11/18
grades in the descending order of their salaries
Display the total number of employees in each
39. department 29/11/18

Display the highest salary, lowest salary, and


40. average salary of each zone 29/11/18

Display the average age of employees in each


41. department only for those departments in 29/11/18
which average age is more than 30.
Put the grade B for all those whose grade is
42. NULL 29/11/18

Increase the salary of all the employees above


43. 30 years of age by 10%. 29/11/18

Delete the records of all the employees whose


44. grade is C and salary is below 30000. 29/11/18

Delete the records of all the employees of


45. department 10 who are above 40 years of age. 29/11/18

Add another column HireDate of type Date in


46. the Employee table. 47 Display the details 29/11/18
of all the employees who work in Sales
department.
Display the details of all the employees who
47. work in Sales department. 29/11/18

Display the Name and Department Name of all


48. the employees. 29/11/18

Display the names of all the employees whose


49. salary is out of the specified range for the 29/11/18
corresponding department.

Display the name of the department and the


50. name of the corresponding HOD for all the 29/11/18
departments.
OUTPUT

[1].
[2].

[3].

[1]. Write a programme to input day number of a week and display the corresponding day name.
#include<iostream.h>
#include<conio.h>
void main(){ clrscr();
int n;
cout<<"Enter The Day Number In The Week\n";
cin>>n;
cout<<"\nThe Day Name Is- ";
switch(n){ case 1: { cout<<"Sonday”; }break;
case 2:{ cout<<"Monday"; }break;
case 3:{ cout<<"Tuesday"; }break;
case 4:{ cout<<"Wednesday"; }break;
case 5:{ cout<<"Thursday"; }break;
case 6:{ cout<<"Friday"; }break;
case 7:{ cout<<"Saturday"; }break; }
getch(); }

[2]. Write a program to input two numbers m and n and display first m multiples of n.
#include<iostream.h>
#include<conio.h>
void main(){ clrscr();
int m,n;
cout<<"Enter The Value Of n \n";
cin>>n;
cout<<"Enter tHE Value Of m \n";
cin>>m;
cout<<"The First m Multiple Of n Are :-\n";
for(int i=1;i<=m;i++)
{ cout<<n<<"*"<<i<<"="<<n*i<<"\n"; }
getch();
}

[3].Write a program to read a string and print out the followi ng:
1)No. Of capital alphabets, 2)No. Of small alphabet s, 3)No. Of non alphabet
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<stdio.h>
void main(){ clrscr();
char string[40];
int cap=0,sml=0,non=0;
cout<<"Enter The String\n";
cin.getline(string,40);
for(int i=0;string[i]!='\0';i++)
{ if(isupper(string[i])) { cap++; }
if(islower(string[i])) { sml++; }
if(!isalpha(string[i])) { non++; } }
cout<<"\n\nThe Number Of Capital Alphabet Is\n"<<cap;
cout<<"\n\nThe Number Of Small Alphabet Is\n"<<sml;
cout<<"\n\nThe Number Of Non-Alphabet Is\n"<<non;
getch();

[4].

[5].
[4].Write a program to read a string and print it after replacing each of its capital alphabets by the
corresponding small alphabet and each small alphabet by its corresponding capital alphabet.

#include<iostream.h>
#include<ctype.h>
#include<conio.h>
#include<stdio.h>
void main(){ clrscr();
char string[30];
cout<<"Enter The String\n";
cin.getline(string,30);
for(int i=0;string[i]!='\0';i++)
{ if(isupper(string[i]))
{ string[i]=tolower(string[i]); }
else if(islower(string[i]))
{ string[i]=toupper(string[i]); }}
cout<<"\n\nThe Updated String Is :-\n"<<string;
getch();
}

[5]. Write a program to store information of 10 employees and to display of an employee depending
upon the employee number given by the user using structure.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct addr{
int house_no;
char area[20];
char city[20]; };
struct emply{
int emp_no;
char emp_name[20];
char emp_desig[20];
addr adrs;
float salary; }e[10];
void enter(int s){
for(int i=0;i<s;i++)
{ clrscr();
cout<<"\nEnter The Employee Number "<<"\n";
cin>>e[i].emp_no;
cout<<"\nEnter The Employee Name "<<"\n";
gets(e[i].emp_name);
cout<<"\nEnter The Employee Designation "<<"\n";
gets(e[i].emp_desig);
cout<<"\nAddress of Employee "<<":-\n"<<"\n Enter The House Number \n";
cin>>e[i].adrs.house_no;
cout<<"\nEnter The Area \n";
gets(e[i].adrs.area);
cout<<"\nEnter The City \n";
gets(e[i].adrs.city);

[5].

[6].
cout<<"\nEnter The Salary Of The Employee "<<"\n";
cin>>e[i].salary; }}
void show(int a){
cout<<"\nEmployee Number is "<<e[a].emp_no;
cout<<"\nEmployee Name is "<<e[a].emp_name;
cout<<"\nEmployee Designation is "<<e[a].emp_desig;
cout<<"\nAddress of Employee "<<":-\n"<<"The House Number is "<<e[a].adrs.house_no;
cout<<"\nThe Area is "<<e[a].adrs.area;
cout<<"\nThe City is "<<e[a].adrs.city;
cout<<"\n The Salary Of The Employee is "<<e[a].salary;}
void main(){ clrscr();
int n,a;
cout<<"\nEnter The Number Of Employees Of Which You Want To Add Details (max 10)\n";
cin>>a;
enter(a); clrscr();
cout<<"\n\nEnter The Employee Number Of Which You Want To See Detail\n";
cin>>n;
for(int i=0;i<a;i++)
{ if(n==e[i].emp_no)
{ show(i); }}
getch();
}

[6]. Write a menu driven program to calculate the TSA and volume of a cube,cuboid,or
cylinder depending upon user’s choice. (using Function overloading).
#include<iostream.h>
#include<conio.h>
float tsa(float l,float b,float h)
{ float ar;
ar=2*(l*b+b*h+l*h);
return ar; }
float tsa(float a)
{ float ar;
ar=6*(a*a);
return ar; }
float tsa(float r,float h)
{ float ar;
ar=(2*3.14*r*(r+h));
return ar; }
float vol(float l,float b,float h)
{ float vl;
vl=l*b*h;
return vl; }
float vol(float a)
{ return(a*a*a); }
float vol(float r,float h)
{ float vl;
vl=3.14*(r*r*h);
return vl; }
void main(){ clrscr();
int n; char ans='y';

[6].
while(ans=='y'||ans=='Y'){
cout<<"\nEnter Your Choice:-\n"<<"\t1.Cube\n"<<"\t2.Cuboid\n"<<"\t3.Cylinder\n";
cin>>n;
switch(n)
{ case 1:{ clrscr(); float a;
cout<<"\n\n\t\t\t\tCUBE\nEnter The Side Of The Cube\n";
cin>>a;
cout<<"\nThe Total Surface Area Of Cube Is\n"<<tsa(a);
cout<<"\nThe Volume Of Cube Is\n"<<vol(a);
cout<<"\nWant To Enter Again(y/n)\n";
cin>>ans; }break;
case 2:{ clrscr(); float l,b,h;
cout<<"\n\n\t\t\t\tCUBOID\nEnter the Length \n";
cin>>l;
cout<<"\nEnter the Breadth \n";
cin>>b;
cout<<"\nEnter the Height \n";
cin>>h;
cout<<"\nThe Total Surface Is\n"<<tsa(l,b,h);
cout<<"\nThe Volume Is\n"<<vol(l,b,h);
cout<<"\nWant To Enter Again(y/n)\n";
cin>>ans; }break;
case 3:{ clrscr(); float r,h;
cout<<"\n\n\t\t\t\tCYLINDER\nEnter The Radius\n";
cin>>r;
cout<<"\nEnter The Height\n";
cin>>h;
cout<<"\nThe Total Surface Is\n"<<tsa(r,h);
cout<<"\nThe Volume Is\n"<<vol(r,h);
cout<<"\nWant To Enter Again(y/n)\n";
cin>>ans; }break;
default:{cout<<"\nYou Have Entered A Wrong Choice...\nWant To Enter Again(y/n)\n";
cin>>ans; }}}
getch();
}
[7].
[7]. Define a class Outfit in C++ with the following description
Private: OCode of type string, OType of Type string, OSize of type string,OFabric of type sTring
Price of type float
A function InitPrice() which calculates and
Assign the value of OPrice as follows:
For the v alue of OFabric as “ DENIM”
Type Price
TROUSER 1500
JACKET 2500
For the material other than “ DENIM” the above mentioned Price gets reduced by 25%.
Public: A function Input( ) to input the value of the data members OCode, OType, OSize and
OFabric and invoke the function InitPrice() .
A Display function That display the content of all the data members for the Outfit.

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class outfit{
private: char ocode[20],otype[20],osize[20],ofabric[20];
float price;
void initprice()
{ if(strcmpi(ofabric,"denim")==0)
{ if(strcmpi(otype,"trouser")==0)
price=1500;
else if(strcmpi(otype,"jacket")==0)
price=2500; }
else { if(strcmpi(otype,"trouser")==0)
price=1125;
else if(strcmpi(otype,"jacket")==0)
price=1875; }}
public: void input() { clrscr();
cout<<"\n\n\t\t\t\tINPUT\nEnter the Code \n";
gets(ocode);
cout<<"\nEnter the Type (Trouser/jacket)\n";
gets(otype);
cout<<"\nEnter the Size\n";
gets(osize);
cout<<"\nEnter the Fabric (Denim/Any Other)\n";
gets(ofabric);
initprice(); }
void output() { clrscr();
cout<<"\n\n\t\t\t\tOUTPUT\nThe Code Is\n"<<ocode;
cout<<"\n\nThe Type Is \n"<<otype;
cout<<"\n\nThe Size Is\n"<<osize;
cout<<"\n\nThe Fabric Is\n"<<ofabric;
cout<<"\n\nThe Price Is\n"<<price; }};
void main(){ outfit ot;
ot.input();
ot. output();
getch();
}

[8].
[8].Define a class student with the following specifications:
Private members of the class:
Admission Number-An Integer
Name -string of 20 characters
Class -Integer Roll Number-Integer
Public members of the cl ass:
getdata( )-To input the data
showdata( )-To display the data
Write a program to define an array of 10 object of this class, input the data in this array and then display
this list .

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class student{
private:
int Admisn_no;
char Name[20];
int Class;
int Roll_no;
public:
void getdata(){ clrscr();
cout<<"\n\n\t\t\t\tINPUT\nEnter The Admission Number Of Student \n";
cin>>Admisn_no;
cout<<"\nEnter The Name Of The Student \n";
gets(Name);
cout<<"\nEnter The Class Of The Student\n";
cin>>Class;
cout<<"\nEnter The Roll Number Of The Student\n";
cin>>Roll_no;
}
void showdata(){ clrscr();
cout<<"\n\n\t\t\t\tOUTPUT\n The Admission Number Of Student Is \n"<<Admisn_no;
cout<<"\n The Name Of The Student Is\n"<<Name;
cout<<"\n The Class Of The Student Is\n"<<Class;
cout<<"\n The Roll Number Of The Student Is\n"<<Roll_no;
}
int adms_no(){ return(Admisn_no);}
};
void main(){
student s[10]; // Array of 10 Objects of Class
int n;
for(int i=0;i<10;i++){
s[i].getdata();
} clrscr();
cout<<"\nEnter Admission Number of Student Of which You Want To See Thje Detail\n";
cin>>n;
for(int j=0;j<10;j++)
{ if(n==s[j].Admisn_no)
{ s[j].showdata(); }}
getch(); }

[9].
[9]. Create a class PERSON with the following specifications :
Private : Data members : name-character string, ph long.
Public : A constructor that initialize the name as ‘NULL’ and phone number as 0.
 Getdata() – to get all values from the user.
 Putdata() – to display all the data.
A destructor to destruct all the constructor .

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
class PERSON{
protected: char Name[100];
long int Ph_No;
public:
PERSON() {
strcpy(Name,"NULL");
Ph_No=0; }
void Getdata()
{ cout<<"\n\n"<<"Enter The Person Name : ";
cin>>Name;
cout<<"\n\n"<<"Enter The Phone Number : ";
cin>>Ph_No;
}
void Putdata()
{
cout<<"\n\n"<<"Person Name Is : "<<Name;
cout<<"\n\n"<<"Phone Number Is : "<<Ph_No;
}
~PERSON()
{ cout<<"\n\n"<<"Exit";
getch();

}}P1;
class Spouse:public PERSON{
protected:
char spousename[100];
public:
void Getdata() {
PERSON::Getdata();
cout<<"\n\n"<<"Enter The Spouse Name : ";
cin>>spousename;
}
void Putdata(){
PERSON::Putdata();
cout<<"\n\n"<<"Spouse Name Is : "<<spousename;
}}S1;
class Children:public Spouse{
protected: char childname[100];
public:
void Getdata()
{ Spouse::Getdata();
cout<<"\n\n"<<"Enter The Child Name : ";
cin>>childname; }

[11].
void Putdata()
{ Spouse::Putdata();
cout<<"\n\n"<<"Child Name Is : "<<childname;
} }C1;
void main()
{ clrscr();
P1.Getdata();
S1.Getdata();
C1.Getdata();
cout<<"\n\n"<<"Class Called By Object Of Class PERSON ";
P1.Putdata();
cout<<"\n\n"<<"Class Called By Object Of Class Spouse ";
S1.Putdata();
cout<<"\n\n"<<"Class Called By Object Of Class Children ";
C1.Putdata();
getch();
}

[11]. Write a program to input a text file name, read the contents of the file and create a new file
named COPY.TXT, which shall contain only those words from the original file which don’t start
with an upper case vowel.

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main()
{
clrscr();
fstream fin; //declaring files
fstream temp;
fin.open("binary.txt",ios::in); //openif files
temp.open("copy.txt",ios::out);
while(!fin.eof())
{
char str[30];
fin>>str;
if(str[0]=='A'||str[0]=='E'||str[0]=='I'||str[0]=='O'||str[0]=='U')//comparing vowels;
else
{ temp<<str<<" ";
cout<<" record editted to file "<<endl;
}
}
temp.close();
fin.close(); //closing files
getch();
}

[12].
[12]. Declare a structure telerec in C++, containing name[20] and telephone number. Wrtite a
program to maintain a file telephone record. the program should allow the following functions on the
file :
1) To append records in the file .
2) Display the name and the telephone number .if the telephone number .If telephone number
does not exixst display error message “record not found”.
3) Display the telephone number9s0 for a given name.If the name does not exixt then display
“record not found”.

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<fstream.h>
#include<process.h>
#include<stdio.h>
class telephonerec{
long int tno;
char name[30];
public:
void getdata()
{ clrscr();
cout<<"\n\nEnter The Name : ";
gets(name);
cout<<"\nEnter Telephone Number : ";
cin>>tno; }
void putdata()
{ clrscr();
cout<<"\nName :\n";
puts(name);
cout<<"\nTelephone Number :\n ";
cout<<tno<<"\n"; }
void insert();
void searchbyno();
void searchbyname();
long gettellno(){ return tno; }
char *getname(){ return name; }
}s1;
void telephonerec::searchbyname(){
ifstream fin;
char name[100];
cout<<"Enter Name To Be Searched : ";
gets(name);
fin.open("telrec.txt",ios::in);
if(!fin){cout<<"cannt open";exit(1);}
while(fin.read((char*)&s1,sizeof(s1))){
if(strcmp(name,s1.getname())==0)
s1.putdata();
else
cout<<"\n Record not found"; }
fin.close();
getch();
}

[12].
void telephonerec::insert(){
ofstream fout;
fout.open("telrec.txt",ios::app|ios::out);
char ans='y';
while(ans=='y'){
cout<<"\n\t\t\tFILE INPUT\n";
s1.getdata();
fout.write((char*)&s1,sizeof(s1));
cout<<"Record added to file";
cout<<"\n Want to enter more record\n" ;
cin>>ans; }

fout.close();
getch(); }
void telephonerec::searchbyno()
{ ifstream fin;
fin.open("telrec.txt",ios::in);
long int trnol;
cout<<"Enter Telephone No to be search";
cin>>trnol;
while(fin.read((char*)&s1,sizeof(s1))){
if(trnol==s1.gettellno())
s1.putdata();
else
cout<<"\n Record not found"; }
fin.close();
getch();}
void main(){ clrscr();
int ch;char choice;
do{ cout<<" 1. Insert \n 2. Search By Name \n 3. Search By Number \n 4. Exit\n";
cout<<"\nEnter your choice\n";
cin>>ch;
switch(ch){
case 1: s1.insert(); break;
case 2: s1.searchbyname(); break;
case 3: s1.searchbyno(); break;
default:cout<<"wrong choice"; exit(1);
} cout<<"\nWant to continue\n"<<endl; cin>>choice; }while(choice=='y');
getch();
}

[13].
[13]. A blood bank maintains a data file that contains the following information for every donor:
Name, Date of Birth, Telephone number, Blood group. Write a program in C++ to do the following:
a) Given a blood group, display name, date of birth and phone number of all the persons of the given
blood group.
b)Append records in the file.
c)Input a telephone number and modify the corresponding record.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<fstream.h>
class blood_bank
{
char name[20];
char pno[20];
public:
char bgp[4];
char *gettel(){ return pno; }
void input()
{cout<<"enter the name :";
gets(name);
cout<<"enter the phone no.:";
gets(pno);
cout<<"enter the blood group:";
gets(bgp);
cout<<"want to add more(y/n):";
}
void output()
{cout<<name<<"\t"<<pno<<"\t"<<bgp;
}}s1;
int main()
{int num,loop=1;
char y='y',bgps[5];
blood_bank s;
fstream file;
while(loop)
{cout<<"\n\t enter your choice:\n\t1.append data\n\t2.search using blood group\n";
cout<<"3.modify using telephone no\n\t4.exit\n";
cin>>num;
clrscr();
switch(num)
{case 1: file.open("bloodbank.dat",ios::out|ios::app);
while(y=='y')
{
blood_bank s1;
s1.input();
file.write((char*)&s1,sizeof(s1));
cin>>y;
}
y='y';
file.close();
break;
case 2:
[13].

file.open("bloodbank.dat",ios::in|ios::app);
int chq=1;
cout<<"enter blood group to be searched for";
cin>>bgps;
file.seekg(ios::beg);
cout<<"\n name\tphone no.\tblood group\n";
while(file.read((char*) &s,sizeof(s)) )
{if(!strcmpi(bgps,s.bgp))
{
s.output();
chq=0;
}}
if(!chq)
cout<<"no matches found!!";
file.close();
break;
case 3:
fstream fout,tem;
int trollno,pos;
char pno[10];
char found='f';
fout.open("bloodbank.dat",ios::in);
tem.open("new.dat",ios::app|ios::out);
cout<<"\n enter Telephone no whose record is to be modified";
gets(pno);
while(fout.read((char*)&s1,sizeof(s1))){
if(strcmp(s1.gettel(),pno)==0){
cout<<"\nEnter new Details"<<endl;
s1.input();
tem.write((char*)&s1,sizeof(s1));
found='t';
}
else{ tem.write((char*)&s1,sizeof(s1));}
}
if(found=='f')cout<<"record not found";
fout.close();
tem.close();
remove("bloodbank.dat");
rename("new.dat","bloodbank.dat");
getch();
break;
case 4:
loop=0;
break;
default:
cout<<"wrong input. try again";
file.close();
}}
return 0;
}
[14].
[14].Write a menu driven program in C++ to perform the following functions on a binary
file“ BOOK.DAT” containing objects of the class book:
1.Append Record,
2. Modify a record for a given book no.
3. Delete a record with a given book no.
4. Search for a record with a given Book name
Display a sorted list of records ( sort on Book No. ) Display a sorted list of records ( Sor t on Book
Name).
[15].

[16]
[15]. Write a program to perform Linear Search in an array. ( Using functions).
#include<iostream.h>
#include<conio.h>
int Lsearch(int a[],int n,int value)
{
for(int i=0;i<n;i++)
{ if(a[i]==value)
{ return i; } }
return(-1); }
void main() { clrscr();
int ar[20],N,arr_value;
cout<<"\n Enter the size of array(max 20).\n";
cin>>N;
cout<<"\n Enter the array element\n";
for(int i=0;i<N;i++)
{ cin>>ar[i]; }
char ans='y';
while(ans=='Y'||ans=='y')
{ cout<<"\nEnter Element to be searched..\n";
cin>>arr_value;
if(Lsearch(ar,N,arr_value)==-1)
{ cout<<"\nSorry...\nSearch not found \n"; }
else{ cout<<"\nSerach found at position "<<Lsearch(ar,N,arr_value)+1<<"\n"; }
cout<<"\n Want to enter again(y/n)..\n";
cin>>ans; }
getch();
}

[16]. Write a program to perform Binary Search in an array(Using function).

#include<iostream.h>
#include<conio.h>
int Bsearch(int a[],int s,int value)
{ int beg=0,last=(s-1),mid;
while(beg<=last)
{ mid=(beg+last)/2;
if(value==a[mid])
return(mid);
else if(value>a[mid])
beg=mid+1;
else
last=mid-1; }
return(-1); }
void main(){
clrscr();
int ar[20],n,ar_value,fvalue;
cout<<"\n Enter the size of the array(max 20);\n";
cin>>n;
cout<<"\n Enter the Array element \n";
for(int i=0;i<n;i++)
{ cin>>ar[i]; }
char ans='y';
[17].
while(ans=='y'||ans=='Y')
{
cout<<"\n Enter the Element to be searched for..\n";
cin>>ar_value;
fvalue=Bsearch(ar,n,ar_value);
if(fvalue==-1)
{ cout<<"\n Sorry..Search Not Found\n"; }
Else { cout<<"\n Search found at position "<<fvalue+1<<"\n"; }
cout<<"\nWant To Search Again(y/n)..\n";
cin>>ans;
} getch(); }

[17]. Write a program to insert an element at A ParTicular location in an array.

#include<iostream.h>
#include<conio.h>
int pos(int a[],int s,int value)
{ int pos;
if(value<a[0])
pos=0;
else{ for(int i=0;i<s;i++)
{ if((a[i]<=value)&&(value<a[i+1]))
{ pos=i+1;
break;
}}
if(i==s-1)
pos=s; }
return(pos);
}
void main()
{ clrscr();
int ar[20],ar_value,n,fval;
cout<<"\n Enter the size of the array (max 20)\n";
cin>>n;
cout<<"\n Enter the array element\n";
for(int i=0;i<n;i++)
{ cin>>ar[i]; }
char ans='y';
while(ans=='y'||ans=='Y') {
cout<<"\n Enter element to be inserted\n";
cin>>ar_value;
fval=pos(ar,n,ar_value);
for(i=n;i>fval;i--)
{ ar[i]=ar[i-1]; }
ar[fval]=ar_value;
n+=1;
cout<<"\n The updated array is:-\n";
for(i=0;i<n;i++)
cout<<ar[i]<<" "<<"\n";
cout<<"\nWant to insert again(y/n)..\n";
cin>>ans; }
getch(); }

[18].
[19].
[18]. Write a pRogram to delete an element from an Array.

#include<iostream.h>
#include<conio.h>
int search(int ar[],int s,int v)
{ for(int i=0;i<s;i++)
{ if(ar[i]==v)
return i; }
return(-1);
}
void main()
{ clrscr();
int a[20],arr_value,n,index;
cout<<"\nEnter the array size(max 20)\n";
cin>>n;
cout<<"\nEnter the array elements\n";
for(int i=0;i<n;i++)
{ cin>>a[i]; }
char ans='y';
while(ans=='Y'||ans=='y')
{ cout<<"\n Enter element to be deleted..\n";
cin>>arr_value;
index=search(a,n,arr_value);
if(index!=-1)
{
for(i=index;i<n;i++)
{ a[i]=a[i+1]; }
n-=1;
cout<<"\nThe array after deleting the element is:-\n";
for(i=0;i<n;i++)
{ cout<<a[i]<<" "; }
cout<<"\n\nWant to delete again(y/n)..\n";
cin>>ans; }
else
{ cout<<"\n Sorry...No such element found\n Want to enter again(y/n)..\n";
cin>>ans;
}}
getch();
}

[19] or [20]. Write a progam to perform Sel eTcion Sort to an Array.

#include<iostream.h>
#include<conio.h>
void selsort(int ar[],int s)
{
int sml,pos,tmp;
for(int i=0;i<(s-1);i++)
{ sml=ar[i];
pos=i;
for(int j=i+1;j<s;j++)
[21].
{ if(ar[j]<sml)
{ sml=ar[j]; pos=j; } }
tmp=ar[i];
ar[i]=ar[pos];
ar[pos]=tmp;
cout<<"\n Array after pass "<<i+1<<" is : ";
for(j=0;j<s;j++)
cout<<ar[j]<<" "; }
}
int main()
{ clrscr();
int a[20],value,n,fval;
cout<<"\n Enter the size of the array\n";
cin>>n;
cout<<"\n Enter the array element\n";
for(int i=0;i<n;i++)
{ cin>>a[i]; }
selsort(a,n);
cout<<"\n\n The sorted array is :-\n";
for(i=0;i<n;i++)
cout<<" "<<a[i]<<" ";
getch();
}

[21]. Write a program to implement Insertion Sort to an array .

#include<iostream.h>
#include<conio.h>
#include<limits.h> // for INT_MIN
void Insort(int ar[],int s)
{ int tmp,m;
ar[0]=INT_MIN;
for(int i=1;i<=s;i++)
{ tmp=ar[i];
m=i-1;
while(tmp<ar[m])
{ ar[m+1]=ar[m];
m--; }
ar[m+1]=tmp;
cout<<"\n Array after "<<i<<" go is:- ";
for(int j=1;j<=s;j++)
cout<<ar[j]<<" "; } }
void main()
{ clrscr();
int a[20],ar_val,n,fval;
cout<<"\n Enter the size of the array (max 20)..\n";
cin>>n;
cout<<"\n Enter the array elements\n";
for(int i=0;i<n;i++)
[22].
{ cin>>a[i]; }
Insort(a,n);
cout<<"\n\n The array after Insertion sort is:-\n";
for(i=0;i<n;i++)
{ cout<<a[i]<<" "; }
getch();
}

[22]. Write a program to merge two arrays which are In ascending order, to give resultant in
ascending/ descending order.

#include<iostream.h>
#include<conio.h>
void Merge(int A[],int m,int B[],int n,int C[])
{
int a,b,c;
for(a=0,b=0,c=0;a<m&&b<n;)
{ if(A[a]<=B[b])
{ C[c++]=A[a++]; }
else C[c++]=B[b++]; }
if(a<m)
{ while(a<m)
C[c++]=A[a++]; }
else
{ while(b<n)
C[c++]=B[b++]; } }
void main(){
clrscr();
int A[20],B[20],C[20],m,n,mn=0;
cout<<"\nEnter the size of First array (Ascending)..\n";
cin>>m;
cout<<"\nEnter the First array elements\n";
for(int i=0;i<m;i++)
{ cin>>A[i]; }
cout<<"\nEnter the size of secod array (Ascending)..\n";
cin>>n;
mn=m+n;
cout<<"\nEnter Second array elements\n";
for(i=0;i<n;i++)
cin>>B[i];
Merge(A,m,B,n,C);
cout<<"\n\nThe Merged array (Ascending) is:-\n";
for(i=0;i<mn;i++)
cout<<C[i]<<" ";
cout<<"\n\nThe Merged array (Descending) is:-\n";
for(i=(mn-1);i>=0;i--)
cout<<C[i]<<" ";
getch();
}

[23].
[24].
[23]. Write a function in C++ which accepts an integer Array and its size as arguments/ parameters and
exchanges the values of first half side elements with the second half side elements of the array .

#include<iostream.h>
#include<conio.h>
void swap(int a[],int s)
{ int i,j,tmp,mid;
mid=s/2;
if(s%2==0)
j=mid;
else
j=mid+1;
for(i=0;i<mid;i++,j++)
{ tmp=a[i];
a[i]=a[j];
a[j]=tmp;
}}
void main()
{ clrscr();
int ar[20],n;
cout<<"\nEnter the size of the array (max 20)..\n";
cin>>n;
cout<<"\nEnter the elements of the array..\n";
for(int i=0;i<n;i++)
{ cin>>ar[i]; }
swap(ar,n);
cout<<"\nThe updated Array is..\n";
for(i=0;i<n;i++)
{ cout<<ar[i]<<" "; }
getch();
}
[24]. Write a function in C++ which accepts an integer array and its size as arguments/ parameters and
Assigns the elements in to a two dimensional array of Integers in the following format:
If the array is 1,2,3
The resultant 2D array is:
1 2 3
1 2 0
1 0 0

#include<iostream.h>
#include<conio.h>
void Updat(int a[20][20],int s)
{ int A[20][20];
for(int i=0;i<s;i++)
{ for(int j=0;j<s;j++)
{ { if((i+j)>=s)
A[i][j]=0;
else
A[i][j]=a[i][j];
}
a[i][j]=A[i][j];
[25].
} }}
void main()
{ clrscr();
int ar[20][20],n,i,j;
cout<<"\nEnter The 2D-Array Size (max 20)..\n";
cin>>n;
cout<<"\nEnter The 2D-Array Elements (Row wise)...\n";
for(i=0;i<n;i++)
{ for(j=0;j<n;j++)
{ cin>>ar[i][j]; }
cout<<"\n";
}
Updat(ar,n);
cout<<"\nThe Updated Array Is :-\n";
for(i=0;i<n;i++)
{ for(int j=0;j<n;j++)
{ cout<<" ";
cout<<ar[i][j]<<" ";
} cout<<"\n";
}
getch();
}

[25]. Write a menu driven program which allows the user to perform the following operations on a
stack( Array implementation ) :
1)Push 2)Pop 3) Display

#include<iostream.h>
#include<conio.h>
#include<process.h>
int Pop(int [],int&);
int Push(int [],int&,int);
void Display(int [],int);
const int size=50;
void main()
{ clrscr(); int stack[size],no,top=-1,res;
char ch='y';
int n;
while(ch=='y'||ch=='Y')
{ clrscr();
cout<<"\nEnter your choice :-\n [1]. Push()\n [2]. Pop()\n [3]. Display()\n [4]. Exit()";
cin>>n;
switch(n){
case 1:{ char ans='y';
while(ans=='y'||ans=='Y')
{
cout<<"\n\t\tPush()\nEnter item for insertion :";
cin>>no;
res=Push(stack,top,no);
if(res==-1)
{ cout<<"\nOverflow!!! Programme closing";
[25].

exit(0); }
cout<<"\nThe stack now is\n";
Display(stack,top);
cout<<"\nWant to Push more... ";
cin>>ans; }
}break;
case 2:{ char ans='y';
while(ans=='y'||ans=='Y')
{
cout<<"\n\t\tPop()\nDeletion of elements..";
res=Pop(stack,top);
if(res==-1)
{ cout<<"Underflow!!! Programme closing..";
exit(0); }
else { cout<<"\n Element deleted is:"<<res<<endl; }
cout<<"\nThe stack now is\n";
Display(stack,top);
cout<<"\n Want To Pop More";
cin>>ans; }
}break;
case 3:{ cout<<"\nThe elements of Stack are\n";
Display(stack,top);
cout<<"\n Want To go back";
cin>>ch; }break;
case 4:{ exit(0); }break;
default : { cout<<"\n You have entered a wrong choice..want to enter again.";
cin>>ch; }break;
}getch();
}
int Push(int stack[],int&top,int ele)
{ if(top==size-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);
}
void Display(int stack[],int top)
{ if(top==-1) return;
cout<<stack[top]<<"<--"<<endl;
for(int i=top-1;i>=0;i--)
cout<<stack[i]<<endl;
}

[26].
[26]. Write a menu driven program which allows the user to perform the following operations on a
queue ( Array implementation) :
1)Insert 2)Delete 3)Display
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<process.h>
int Delete(int []);
int Insert(int [],int);
void Display(int [],int,int);
const int size=50;
int queue[size],front=-1,rear=-1;
void main()
{ clrscr();
int no,res;
char ch='y';
int n;
while(ch=='y'||ch=='Y')
{ clrscr();
cout<<"\nEnter your choice :-\n [1]. Insert()\n [2]. Delete()\n [3]. Display()\n [4]. Exit()\n";
cin>>n;
switch(n){
case 1:{ char ans='y';
while(ans=='y'||ans=='Y')
{
cout<<"\n\t\tInsert()\nEnter item for insertion :\n";
cin>>no;
res=Insert(queue,no);
if(res==-1)
{ cout<<"\nOverflow!!! Programme closing";
exit(0); }
cout<<"\nNow the queue (front to rear) is :\n";
Display(queue,front,rear);
cout<<"Want to insert more... ";
cin>>ans;
} }break;
case 2:{ char ans='y';
while(ans=='y'||ans=='Y')
{ cout<<"\n\t\tDelete()\nDeletion of elements..";
res=Delete(queue);
if(res==-1)
{ cout<<"Underflow!!! Programme closing..";
exit(0); }
else { cout<<"\n Element deleted is:"<<res<<endl; }
cout<<"\nThe queue now is (front to rear)\n";
Display(queue,front,rear);
cout<<"\n Want To Delete More";
cin>>ans; } }break;
case 3:{ cout<<"\nThe elements of Queue are(front to rear) \n";
Display(queue,front,rear);
cout<<"\n Want To go back";

[26].
cin>>ch; }break;
case 4:{ exit(0); }break;
default : { cout<<"\n You have entered a wrong choice..want to enter again.";
cin>>ch; }break;
} getch(); }
}
int Insert(int queue[],int ele)
{ if(rear==size-1) return(-1);
else if(rear==-1)
{ front=rear=0;
queue[rear]=ele; }
else{ rear++;
queue[rear]=ele; }
return(0); }
int Delete(int queue[])
{ int ret;
if(front==-1) return(-1);
else { ret=queue[front];
if(front==rear) front=rear=-1;
else front++; }
return(ret);
}
void Display(int queue[],int front,int rear)
{ if(front==-1) return;
for(int i=front;i<rear;i++)
cout<<queue[i]<<"<-\n";
cout<<queue[rear]<<endl;
}

[27]. Write a menu driven program which allows the user to perform the following operations on a
stack( Linked implementation) : 1)Push 2)Pop 3)Display

#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#include<process.h>
struct node{ int info;
node*next;
}*top,*newptr,*save,*ptr;
node*new_node(int);
void Pop();
void Push(node*);
void Display(node*);
void main()
{ clrscr();
top=NULL;
int inf;
char ch='y';
int n;
while(ch=='y'||ch=='Y')
{ clrscr();
cout<<"\nEnter your choice :-\n [1]. Push()\n [2]. Pop()\n [3]. Display()\n [4]. Exit()";
[27].
cin>>n;
switch(n){
case 1:{ char ans='y';
while(ans=='y'||ans=='Y')
{cout<<"\nEnter information for new node :";
cin>>inf;
newptr=new_node(inf);
if(newptr==NULL)
{ cout<<"\nCan't create new node!!! Programme closing";
exit(0); }
Push(newptr);
cout<<"\nWant to enter new node ... ";
cin>>ans;
}}break;
case 2:{ char ans='y';
do{
cout<<"\nThe stack now is:\n";
Display(top); system("pause");
cout<<"\n Want To Pop an element(y/n)";
cin>>ans;
if(ans=='y'||ans=='Y')Pop();
}while(ans=='y'||ans=='Y');
}break;
case 3:{ cout<<"\nThe elements of Stack are\n";
Display(top);
cout<<"\n Want To go back";
cin>>ch; }break;
case 4:{ exit(0); }break;
default : { cout<<"\n You have entered a wrong choice..want to enter again.";
cin>>ch; }break; }
getch(); }
}
node*new_node(int n){
ptr=new node;
ptr->info=n;
ptr->next=NULL;
return(ptr); }
void Push(node*np)
{ if(top==NULL) top=np;
else { save=top; top=np;
np->next=save; }
}
void Pop()
{ if(top==NULL) cout<<"Underflow!!!\n";
else{ ptr=top; top=top->next;
delete ptr; }
}
void Display(node*np)
{ while(np!=NULL) {
cout<<np->info<<" -> ";
np=np->next;
} cout<<"!!\n"; }
[28].
[28].Write a menu driven program which allows the user to perform the following operations on a queue
( linked implementation) :
1)Insert 2)Delete 3)Display

#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#include<process.h>
struct node{ int info;
node*next;
}*frnt,*newptr,*save,*ptr,*rar;
node*new_node(int);
void Insert(node*);
void Delnode();
void Display(node*);
void main()
{ clrscr();
frnt=rar=NULL;
int inf;
char ch='y'; int n;
while(ch=='y'||ch=='Y')
{ clrscr();
cout<<"\nEnter your choice :-\n [1]. Insret()\n [2]. Delete()\n [3]. Display()\n [4]. Exit()";
cin>>n;
switch(n){
case 1:{ cout<<"\n\t\tInsert()";
char ans='y';
while(ans=='y'||ans=='Y')
{
cout<<"\nEnter information for new node :";
cin>>inf;
newptr=new_node(inf);
if(newptr==NULL)
{ cout<<"\nCan't create new node!!! Programme closing";
exit(0); }
Insert(newptr);
cout<<"\nWant to enter new node ... ";
cin>>ans;
} }break;
case 2:{ cout<<"\n\t\tDelete()"; char ans='y';
do{
cout<<"\nThe linked queue now is:\n";
Display(frnt);
cout<<"\n Want To delete node(y/n)";
cin>>ans;
if(ans=='y'||ans=='Y')Delnode();
}while(ans=='y'||ans=='Y'); }break;
case 3:{ cout<<"\nThe elements of Linked queue are\n";
Display(frnt);
cout<<"\n Want To go back";
cin>>ch; }break;
case 4:{ exit(0); }break;
[28].
default : { cout<<"\n You have entered a wrong choice..want to enter again.";
cin>>ch; }break; }
getch(); }
}
node*new_node(int n){
ptr=new node;
ptr->info=n;
ptr->next=NULL;
return(ptr); }
void Insert(node*np)
{ if(frnt==NULL) { frnt=rar=np; }
else { rar->next=np; rar=np; }}
void Delnode()
{ if(frnt==NULL) cout<<"Underflow!!!\n";
else{ ptr=frnt; frnt=frnt->next;
delete ptr; }}
void Display(node*np)
{ while(np!=NULL) {
cout<<np->info<<" -> ";
np=np->next;
} cout<<"!!\n";
}
[30].
[30]. Write a menu driven program which allows the user to perform the following operations on a
circular queue ( linked implementation) :
1)Insert 2)Delete

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<process.h>
int Delete(int cque[]);
int Insert(int [],int);
void Display(int [],int,int);
const int size=7;
int cque[size],front=-1,rear=-1;
void main()
{ clrscr();
int no,res;
char ch='y';
int n;
while(ch=='y'||ch=='Y')
{ clrscr();
cout<<"\nEnter your choice :-\n [1]. Insert()\n [2]. Delete()\n [3]. Display()\n [4]. Exit()\n";
cin>>n;
switch(n){
case 1:{ char ans='y';
while(ans=='y'||ans=='Y')
{ cout<<"\nEnter item for insertion :\n";
cin>>no;
res=Insert(cque,no);
if(res==-1)
{ cout<<"\nOverflow!!! Programme closing";
exit(0); }
Display(cque,front,rear);
cout<<"Want to insert more... ";
cin>>ans;
} }break;
case 2:{ cout<<"\n\t\tDelete()";
no=Delete(cque);
cout<<"\n Element deleted is:"<<no<<endl;
Display(cque,front,rear);
system("pause");
}break;
case 3:{ cout<<"\nThe elements of Circular Queue are(front to rear) \n";
Display(cque,front,rear);
cout<<"\n Want To go back";
cin>>ch; }break;
case 4:{ exit(0); }break;
default : { cout<<"\n You have entered a wrong choice..want to enter again.";
cin>>ch; }break;
} getch(); }
}
int Insert(int cque[],int ele)
{ if(((front==0)&&(rear==size-1))||(front==rear+1)) return(-1);

[30].
else if(rear==-1) front=rear=0;
else if(rear==size-1) rear=0;
else rear++;
cque[rear]=ele;
return(0);
}
int Delete(int cque[])
{ int ret;
if(front==-1) return(-1);
else { ret=cque[front];
if(front==rear) front=rear=-1;
else if(front==size-1)
front=0;
else front++; }
return(ret);
}
void Display(int cque[],int front,int rear)
{ int i=0;
cout<<"\nCircular queue is\n"<<"(front shown as>>>,rear as <<< and free space as-)\n";
if(front==-1) return;
if(rear>=front)
{ for(i=0;i<front;i++) cout<<"-";
cout<<">>>";
for(int i=front;i<rear;i++)
cout<<cque[i]<<"<-";
cout<<cque[rear]<<"<<<"<<endl;
}
else{ for(i=0;i<rear;i++) cout<<cque[i]<<" <- ";
cout<<cque[rear]<<"<<<";
for(;i<front;i++) cout<<"-";
cout<<">>>";
for(i=front;i<size;i++) cout<<cque[i]<<" <- ";
cout<<"\t...wrap around...";
}
}

[1].

[2].
[3].

[4].

[5].
SQL

[1]. Create the table Employee.

=> Create table employee(no int,name char(10),salary int,zone char(10),age int,grade char,dept int);

[2].Create the table department.

=> Create table department(dept int,dname char(10),minsal int,,maxsal int,HOD int);

[3]. Insert data in the table Employee.

=> Insert into empoyee values(1, ’Mukul’, 30000, ’West’, 28, ’A’, 10);

Insert into empoyee values(2, ‘kritika’, 35000, ’Center’, 30, ’A’, 10);

Insert into empoyee values(3, ’Naveen’, 32000, ’West’, 40, ’A’, 20);

Insert into empoyee values(4, ’Uday’, 38000, ’North’, 38, ’A’, 30);

Insert into empoyee values(5, ‘Nupur’, 32000, ’East’, 26, ’A’, 20);

Insert into empoyee values(6, ’Moksh’, 37000, ’South’, 28, ’A’, 10);

Insert into empoyee values(7, ’Shelly’, 36000, ’North’, 26, ’A’, 30);
[4]. Insert data in the table Department.

=> Insert into department values( 10, ‘Sales’, 25000, 32000, 1);

Insert into department values( 20, ‘Finance’, 30000, 50000, 5);

Insert into department values( 30, ‘Admin’, 25000, 40000, 7);

[5]. Display the details of all the employees.

=> Select *from employee;

[6].

[7].

[8].
[9].

[10].

[11].

[6]. Display the Salary ,Zone, and Grade of all the employees.

=> Select salary,zone,grade from employee


[7]. Display the records of all the employees along with their annual salaries. The Salary column of the
table contains monthly salaries of the employee.

=> Select *, salary*12 from employee.

[8].Display the records of all the employees along with their annual salaries. The Salary column of the
table contains monthly salaries of the employee.The new column should be given the name” Annual
Salaries”.

=> select *, salary*12”Annual Salary” from employee.

[9]. Display the details of all the employees who are below 30 years of age.

=> Select *from employee where age<30;

[10]. Display the names of all the employees working in North zone.

=> Select *from employee where zone=’North’;


[11]. Display the salaries of all the employees of department 10.

=> Select *from employee where department=10;

[12].

[13].

[14].
[15].

[16].

[12]. Display the details of all the employees whose Grade is NULL.

=> Select *from employee where grade is NULL;


[13]. Display the details of all the employees whose Grade is not NULL.

=>Select *from employee where grade is not NULL;

[14]. Display the names of various zones from the table Employee.A zone name should appear only
once.

=> Select distinct zone from employee;

[15]. Display the various department numbers from the table Employee.A department number should
be displayed only once.

=> Select distinct dept from employee;

[16]. Display the details of all the employees of department 10 who are above 30 years of age.
=> Select *from employee where dept=10 and age>30;

[17].

[18].

[19].
[20].

[21].

[17]. Display the details of all the employees who are getting a salary of more than 35000 in the
department 30.

=> Select *from employee where dept=30 and salary=35000;

[18]. Display the names and salaries of all the employees who are not working in department 20.

=> Select name,salary from employee where not dept=20;


[19]. Display the names and salaries of all the employees who are working neither in West zone nor in
Centre zone.

=> Select name,salary from employee where not zone=’Center’ and not zone=’West’;

[20]. Display the names of all the employees who are working in department 20 or 30.

=> Select *from employee where Dept=20 or Dept=30.

[21]. Display the details of all the employees whose salary is between 32000 and 38000.

=> Select *from employee where salary>32000 and salary<38000;


[22].

[23].

[24].

[25].
[26].

[22]. Display the details of all the employees whose grade is between ‘ A’ and‘ C’.

=> Select *from employee where Grade>’A’ and Grade<’C’;

[23]. Display the details of all the employees aged above 30 in West zone.

=>Select *from employee where Age>30 and Zone=’West’;


[24]. Display the names of all the employees who are working in department 20 or 30.( Using IN
operator )

=> Select Name from employee where Dept in (20,30);

[25]. Display the names and salaries of all the employees who are working neither in West zone nor in
Centre zone.( Using IN operator )

=> Select Name,Salary from employee where not Zone in (‘West’,’Center’);

[26]. Display the details of all the employees whose salary is between 32000 and 38000.

( Using BETWEEN operator )

=> Select *from employee where Salary between 32000 and 38000;

[27].
[28].

[29].

[30].

[31].
[27]. Display the details of all the employees whose grade is between‘ A’ and‘ C’ .

( Using BETWEEN operator )

=> Select *from employee where Grade between ‘A’ and ‘C’;

[28]. Display the name, salary , and age of all the employees whose names start with ‘ M’.

=> Select Name,Salary,Age from employee where Name like ‘M%’;

[29]. Display the name, salary , and age of all the employees whose names end with‘ a’ .
=> Select Name,Salary,Age from employee where Name like ‘%a’;

[30]. Display the name, salary , and age of all the employees whose names contain ‘ a’.

=> Select Name,Salary,Age from employee where Name like ‘%a%’;

[31]. Display the name, salary , and age of all the employees whose names do not contain ‘ a’.

=> Select Name,Salary,Age from employee where Name not like ‘%a%’;

[32].
[33].

[34].

[35].

[36].
[32]. Display the details of all the employees whose names contain ‘ a’ as the second character .

=> Select *from employee where Name like ‘_a%’;

[33]. Display the sum and average of the salaries of all the employees.

=> Select sum(Salary),avg(Salary) from employee;

[34]. Display the highest and the lowest salaries being paid in department 10.

=> Select max(Salary),min(Salary) from employee where Dept=10;


[35]. Display the number of employees working in department 10.

=> Select count(No) from employee where Dept=10;

[36]. Display the details of all the employees in the ascending order of their salaries.

=> Select *from employee order by Salary;

[37].

[38].
[39].

[40].

[41].
[37]. Display the details of all the employees in the descending order of their name.

=> Select *from employee order by Name DESC;

[38]. Display the details of all the employees in the ascending order of their grades and within grades in
the descending order of their salaries.

=> Select *from employee order by Grade,Salary DESC;

[39]. Display the total number of employees in each department.

=> Select Dept,count(*) from employee group by Dept;

[40]. Display the highest salary , lowest salary , and average salary of each zone.
=> Select Zone,max(Salary),min(Salary),avg(Salary) from employee group by Zone;

[41]. Display the average age of employees in each department only for those departments in which
average age is more than 30.

=> Select Dept,avg(Age) from employee group by Dept having avg(Age)>30;

[42].

[43].
[44].

[45].

[46].
[42]. Put the grade B for all those whose grade is NULL.

=> Update employee set grade=’B’ where grade is NULL;

[43]. Increase the salary of all the employees above 30 years of age by 10%

=> Update employee set Salary=Salary+Salary/10 where Age >30;

[44]. Delete the records of all the employees whose grade is C and salary is below 30000.

=>Delete from employee where garde=’C’ and Salary<30000;

[45]. Delete the records of all the employees of department 10 who are above 40 years of age.

=> Delete from employee where Dept=10 and Age>40;


[46]. Add another column HireDate of type Date in the Employee table.

=>Alter table employee add Hiredate date;

[47].

[48].
[49].

[50].

[47]. Display the details of all the employees who work in Sales department.

=> Select *from employee E,department D where E.Dept=D.dept and Dname=’Sales’;


[48]. Display the Name and Department Name of all the employees.

=>Select Name,Dname from employee E,department D where E.Dept=D.Dept;

[49]. Display the names of all the employees whose salary is out of the specified range for the
corresponding department.

=> Select Name from employee E,department D where E.Dept=D.dept and (Salary not between minsal
and maxsal);

[50]. Display the name of the department and the name of the corresponding HOD for all the
departments.

=>Select distinct Dname,Hod from employee E,department D where E.Dept=D.Dept;

Potrebbero piacerti anche