You are on page 1of 108

CENTRAL MODEL SCHOOL

BARRACKPORE
700120

COMPUTER PRACTICAL
(C++ PROGRAMS, SQL QUERIES)

Name: Debanjan Paul


Roll No.:
Class: XII(Science)
Subject Teacher: Mrs. Sangita Sukul
S.NO PROGRAM/TOPIC REMARK

2
1. Program to print Armstrong numbers from 1
to 500
2. Program to find the largest number among
three numbers
3. Program to input a number and check whether
the number is perfect or not
4. Program to print the prime Fibonacci series
from 1 to 1000
5. Program to print prime factors of a number
6. Program to input a number and check whether
the number is perfect or not
7. Program to print sum of series 1+1/12+1/32+....
....1/n2
8. Program to print Pascal’s triangle
9. Program to create a string and display the
character from even, odd and prime positions
10. Program to store the information of 5
employees and to display the information of
employee depending on the employee number
(Structure based)
11. Menu-driven program to perform various
operations on a string without using built in
functions- i)Find length ii)Reverse string
iii)Copy the string iv)Concatenate two strings
12. Menu-driven program to accept an array and
sort using: i)Selection Sort ii)Insertion Sort
13. Program to create Magic Square of order nxn.
(In such a box, the sum of elements of any row
or column is the same)
14. Write a program to read an integer array, sort
it using bubble sort and search an element
using binary search
15. Write a program to implement merge sort
16. Write a program to insert an element at a
Specific position
17. Write a program to delete an element from a
specific position in a 1-D array

3
18. Write a program to display the country and
corresponding capital
19. Write a program to accept a 2-D array of
integers and display the 2-digit numbers
20. Write a program to multiply two matrices
21. Write a program to create a text file to read
and display uppercase and lowercase and
consonants
22. Write a program to implement various file
operations
23. Write a program to create library management
system
24. Write a program to create linear stack of
integers and implement push and pop
operations
25. Write a program to create linear circular queue
and to perform addition and deletion on it
26. Write a program to implement push and pop
on a stack of array
27. Write a program to create a linked queue
containing employee number, salary and to
perform addition and deletion
28. Write a program to create linear circular queue
and perform addition on it
29. Write a program to create linear stack
containing roll number and age and perform
push and pop on it
30. SQL Queries

PROGRAM 1
4
Program to print Armstrong numbers from 1 to 500
#include<iostream.h>

void main()

int a,d,c=0;

cout<<"The armstrong numbers till 500 are:"<<endl;

for(int i=1;i<=500;i++)

a=i; c=0;

while(a!=0)

d=a%10;

c=c+(d*d*d);

a=a/10;

if(c==i)

cout<<i<<endl;

5
6
PROGRAM 2
Program to find the largest number among three
numbers
#include<iostream.h>

void main()

int a,b,c,h;

cout<<"Enter the three numbers"<<endl;

cin>>a>>b>>c;

h=a;

if(b>h)

h=b;

if(c>h)

h=c;

cout<<"The largest number="<<h;

7
8
PROGRAM 3
Program to input a number and check whether the
number is perfect or not
#include<iostream.h>

void main()

int n,i=1,sum=0;

cout<<"Enter a number:";

cin>>n;

for(i=1;i<n;i++)

if(n%i==0)

sum+=i;

if(sum==n)

cout<<n<<" is a perfect number";

else

cout<<n<<" is not a perfect number";

9
10
PROGRAM 4
Program to print the prime Fibonacci series from 1
to 1000
#include<iostream.h>

void main()

int i,c=0,first=1,second=1,next;

cout<<"The prime Fibonacci numbers from 1 to 1000 are:"<<endl;

cout<<first<<endl<<second<<endl;

for(i=2;i<=15;i++)

next=first+second;

for(i=1;i<=next;i++)

if(next%i==0)

c++;

if(c==2)

cout<<next<<endl;

first=second;

second=next;

11
}

12
PROGRAM 5
Program to print prime factors of a number
#include<iostream.h>

void main()

int n,i,j,c=0;

cout<<"Enter the desired number-";

cin>>n;

cout<<"Prime factors of "<<n<<" are-"<<endl;

for(i=1;i<=n;i++)

{ c=0;

if(n%i==0)

for(j=1;j<=i;j++)

{if(i%j==0)

{c++;}}

if(c==2)

cout<<i<<endl;

13
14
PROGRAM 6
Program to input a number and check whether the
number is perfect or no
#include<iostream.h>

void main()

int n,d,c=0;

cout<<"Enter your number-";

cin>>n;

while(n!=0)

d=n%10;

c=c+d;

n=n/10;

if(c==1)

break;

if(n==0)

{n=c; c=0;}

15
}

cout<<"The number is a magic number";

16
PROGRAM 7
Program to print sum of series
1+1/1^2+1/3^2+........1/n^2
#include<iostream.h>

void main()

double s=1; int n;

cout<<"Enter the limit of series="<<endl;

cin>>n;

for(int i=1;i<=n;i++)

if(i%2!=0)

s=s+(1/(i*i));

cout<<"The sum of series is="<<(double)s;

17
18
PROGRAM 8
Program to print Pascal’s triangle
#include<iostream.h>

void main()

int n,k,i,x;

cout<<"Enter a row number for Pascal's Triangle: ";

cin>>n;

for(i=0;i<=n;i++)

x=1;

for(k=0;k<=i;k++)

cout<<x<<" ";

x=x*(i-k)/(k+1);

cout<<endl;

19
20
PROGRAM 9
Program to create a string and display the
character from even, odd and prime positions
#include<iostream.h>

#include<stdio.h>

#include<string.h>

void main()

char s[50]; int i,j,c=0;

cout<<"Enter a word in 50 characters- ";

gets(s); int l=strlen(s);

cout<<"Characters at even positions:"<<endl;

for(i=0;i<l;i++)

if((i+1)%2==0)

cout<<"Pos "<<(i+1)<<":"<<s[i]<<endl;

cout<<"Characters at odd positions:"<<endl;

for(i=0;i<l;i++)

21
if((i+1)%2!=0)

cout<<"Pos "<<(i+1)<<":"<<s[i]<<endl;

cout<<"Characters at prime positions:"<<endl;

for(i=0;i<l;i++)

c=0;

for(j=1;j<=(i+1);j++)

if((i+1)%j==0)

c++;

if(c==2)

cout<<"Pos "<<(i+1)<<":"<<s[i]<<endl;

22
PROGRAM 10
Program to store the information of 5 employees
and to display the information of employee
depending on the employee number (Structure
based)

#include<iostream.h>

23
#include<string.h>

#include<stdio.h>

struct emp{

int empno;

char name[100];

char desig[50];

};

emp ob[5];

void main()

int i,n,p;

for(i=0;i<5;i++)

cout<<(i+1)<<".Enter the employee number: "; cin>>ob[i].empno;

cout<<"Enter the name: "; gets(ob[i].name);

cout<<"Enter the designation: "; gets(ob[i].desig); cout<<endl;

cout<<"Now enter the number of the employee you wish to view";

cin>>n;

for(i=0;i<5;i++)

if(ob[i].empno==n)

p=i;

24
break;}

cout<<"\nTHE DETAILS OF THE EMPLOYEE-"<<endl;

cout<<"Employee Number: "<<ob[p].empno<<endl;

cout<<"Employee Name: "; puts(ob[p].name); cout<<endl;

cout<<"Employee Designation: "; puts(ob[p].desig);

25
PROGRAM 11
Menu-driven program to perform various
operations on a string without using built in
functions- i)Find length ii)Reverse string iii)Copy
the string iv)Concatenate two strings
#include<iostream.h>

#include<math.h>

#include<stdio.h>

int i,k;

void main()

int slen(char []);

void srev(char [],char []);

void scopy(char [],char []);

void sconcat(char [],char [],char []);

int ch,l; char s[100],a[100];

26
cout<<"Enter the string in 100 characters:"; gets(s);

cout<<"Enter 1 to find length"<<endl;

cout<<"Enter 2 to reverse"<<endl;

cout<<"Enter 3 to copy to another varaible"<<endl;

cout<<"Enter 4 to concatenate two strings"<<endl; cin>>ch;

switch(ch)

case 1: l=slen(s);

cout<<"The length of the string is:"<<l;

break;

case 2: srev(s,a);

cout<<"The reversed string is:"; puts(a);

break;

case 3: scopy(s,a);

cout<<"The string has been copied. a[]= ";

puts(a);

break;

case 4: char q[50],r[150];

cout<<"Enter new string in 50 characters: ";

gets(q);

sconcat(s,q,r);

cout<<"New concatenated string: "; puts(r);

27
break;

default: cout<<"Wrong Input";

int slen(char v[])

for(i=0;v[i]!='\0';i++);

return i;

void srev(char d[],char f[])

for(int j=slen(d)-1,k=0;j>=0;j--,k++)

f[k]=d[j];

f[k]='\0';

void scopy(char h[],char t[])

for(int z=0;z<slen(h);z++)

t[z]=h[z];

t[z]='\0';

28
}

void sconcat(char k[],char l[],char p[])

for(int q=0;k[q]!='\0';q++)

p[q]=k[q];

for(int e=0;l[e]!='\0';e++)

p[q+e]=l[e];

p[q+e]='\0';

29
PROGRAM 12
Menu-driven program to accept an array and sort
using: i)Selection Sort ii)Insertion Sort
#include<iostream.h>

void main()

void selc(int []); void insr(int []);

int ch,i,ar[10];

cout<<"Enter array of 10 elements: ";

for(i=0;i<10;i++)

cin>>ar[i];

cout<<"Enter 1 for selection sort"<<endl;

cout<<"Enter 2 for insertion sort"<<endl;

30
cin>>ch;

switch(ch)

case 1: cout<<"You chose selection sort:"<<endl;

selc(ar);

cout<<"The sorted array is:"<<endl;

for(i=0;i<10;i++)

cout<<ar[i]<<endl;

break;

case 2: cout<<"You chose insertion sort:"<<endl;

insr(ar);

cout<<"The sorted array is:"<<endl;

for(i=0;i<10;i++)

cout<<ar[i]<<endl;

void selc(int num[])

int i,j,small,pos,temp;

for(i=0;i<10;i++)

31
small=num[i];

pos=i;

for(j=i+1;j<10;j++)

if(num[j]<small)

{small=num[j]; pos=j;}

temp=num[i];

num[i]=num[pos];

num[pos]=temp;

} }

void insr(int num[])

int i,j,key;

for(j=1;j<10;j++)

{ key=num[j];

for(i=9;(i>=0)&&(num[i]<key);i--)

num[i+1]=num[i];

num[i+1] = key;

}}

32
33
PROGRAM 13
Program to create Magic Square of order nxn.
(In such a box, the sum of elements of any row or
column is the same)
#include<iostream.h>

#include<iomanip.h>

void main()

const int n=7;

cout<<"Magic square of order: 7"<<endl;

int MagicSquare[n][n];

int newRow,

newCol;

//Set the indices for the middle of the bottom i

int i=0 ;

int j=n/2;

34
//Fill each element of the array using the magic array

for ( int value = 1; value <= n*n; value++ )

MagicSquare[i][j]=value;

// Find the next cell, wrapping around if necessary.

newRow=(i+1)%n;

newCol=(j+1)%n;

// If the cell is empty, remember those indices for the

// next assignment.

if(MagicSquare[newRow][newCol]==0)

i=newRow;

j=newCol;

else

// The cell was full. Use the cell above the previous one.

i=(i-1+n)%n;

for(int x=0;x<n;x++)

35
{

for(int y=0;y<n;y++)

cout<<MagicSquare[x][y]<<" ";

cout<<endl;

}}

36
PROGRAM 14
Write a program to read an integer array, sort it
using bubble sort and search an element using
binary search
#include<iostream.h>

void main()

void Sort(int [],int); int bi(int [],int,int);

int n,a[50],p,it;

cout<<"Enter number of elements(max 50 elements):"; cin>>n;

cout<<"Enter the array:";

for(int i=0;i<n;i++)

cin>>a[i];

Sort(a,n);

cout<<"The Sorted array: ";

for(int z=0;z<n;z++)

cout<<a[z]<<" ";

cout<<"\nEnter the item to be searched: "; cin>>it;

p=bi(a,n,it);

if(p==-1)

cout<<"Not found!!";

37
else

cout<<it<<" found at position "<<(p+1);

void Sort(int AR[],int size)

{int tmp,ctr=0;

for(int i=0;i<size;i++)

{ for(int j=0;j<(size-1);j++)

{ if(AR[j]>AR[j+1])

{ tmp=AR[j];

AR[j]=AR[j+1];

AR[j+1]=tmp;

int bi(int AR[],int size,int item)

{ int beg,last,mid;

beg=0; last=size-1;

while(beg<=last)

{ mid=(beg+last)/2;

if(item==AR[mid])

return mid;

else if(item>AR[mid])

38
beg=mid+1;

else if(item<AR[mid])

last=mid-1;

else

break;

return -1;

39
PROGRAM 15
Write a program to implement merge sort
#include <iostream.h>

#include <conio.h>

#define MAX 10

static int merge_arr[MAX+MAX],sort_arr[MAX+MAX];

class mergesort{

int arr1[MAX],arr2[MAX],n1,n2,n3;

public:

void getdata();

void showdata(int);

void mergeLogic();

void sortLogic();

};

void mergesort :: getdata(){

int i;

cout<<"\n--Data Must be Entered in Sorted Order for each Array--\n\n";

cout<<"How many elements you require 1st -> Array: ";

cin>>n1;

40
for(i=0;i<n1;i++)

cin>>arr1[i];

cout<<"How many elements you require 2nd -> Array: ";

cin>>n2;

for(i=0;i<n2;i++)

cin>>arr2[i];

n3=n1+n2;

void mergesort :: showdata(int select){

int i;

if(select==1){

cout<<"\n\n--Array 1--\n";

for(i=0;i<n1;i++)

cout<<arr1[i]<<" ";

else if(select==2){

cout<<"\n\n--Array 2--\n";

for(i=0;i<n2;i++)

cout<<arr2[i]<<" ";

else if(select==3){

cout<<"\n\n--Sorted Array--\n";

for(i=0;i<n3;i++)

41
cout<<sort_arr[i]<<" ";

void mergesort :: mergeLogic(){

int i,j,c;

for(i=0;i<n1;i++)

merge_arr[i] = arr1[i];

for(j=i,c=0;j<n3;j++,c++)

merge_arr[j] = arr2[c];

void mergesort :: sortLogic(){

//before sort call mergeLogic

mergeLogic();

int i,j,first=0,second=n1,third=n3;

i=first;

j=second;

static int c=0;

42
while(i<second && j<third){

if(merge_arr[i] < merge_arr[j]){

sort_arr[c]=merge_arr[i];

i++;

else{

sort_arr[c]=merge_arr[j];

j++;

c++;

if(i<second){

while(i<second){

sort_arr[c]=merge_arr[i];

i++;

c++;

if(j<third){

while(j<third){

sort_arr[c]=merge_arr[j];

j++;

43
c++;

/*void mergesort :: sortLogic(){ static int i,j,c=0; while(i<n1 && j<n2)


{ if(arr1[i] < arr2[j]){ sort_arr[c]=arr1[i]; i++; } else{
sort_arr[c]=arr2[j]; j++; } c++; } if(i<n1){ while(i<n1){
sort_arr[c]=arr1[i]; i++; c++; } } if(j<n2){ while(j<n2)
{ sort_arr[c]=arr2[j]; j++; c++; } }} */void main(){

clrscr();

cout<<"\n*****Merge Sort*****\n";

mergesort obj;

obj.getdata();

obj.sortLogic();

obj.showdata(1);

obj.showdata(2);

obj.showdata(3);

getch();

44
45
PROGRAM 16
Write a program to insert an element at a Specific
position
#include<iostream.h>

#include <stdio.h>

int main()

int array[100], position, c, n, value;

printf("Enter number of elements in array\n");

scanf("%d", &n);

printf("Enter %d elements\n", n);

for (c = 0; c < n; c++)

scanf("%d", &array[c]);

printf("Enter the location where you wish to insert an element\n");

scanf("%d", &position);

printf("Enter the value to insert\n");

scanf("%d", &value);

46
for (c = n - 1; c >= position - 1; c--)

array[c+1] = array[c];

array[position-1] = value;

printf("Resultant array is\n");

for (c = 0; c <= n; c++)

printf("%d\n", array[c]);

return 0;

PROGRAM 17

47
Write a program to delete an element from a
specific position in a 1-D array
#include <stdio.h>

int main()

int array[100], position, c, n;

printf("Enter number of elements in array\n");

scanf("%d", &n);

printf("Enter %d elements\n", n);

for ( c = 0 ; c < n ; c++ )

scanf("%d", &array[c]);

printf("Enter the location where you wish to delete element\n");

scanf("%d", &position);

if ( position >= n+1 )

printf("Deletion not possible.\n");

else

for ( c = position - 1 ; c < n - 1 ; c++ )

array[c] = array[c+1];

48
printf("Resultant array is\n");

for( c = 0 ; c < n - 1 ; c++ )

printf("%d\n", array[c]);

return 0;

PROGRAM 18

49
Write a program to display the country and
corresponding capital
#include<iostream.h>

#include<stdio.h>

#include<string.h>

struct ca{

char co[20];

char cap[20];

};

void main()

char cn[20]; int i;

cout<<"Ente 5 countries and their capitals"<<endl;

ca stor[5];

for(i=0;i<5;i++)

cout<<(i+1)<<".Country: "; gets(stor[i].co);

cout<<"Capital: "; gets(stor[i].cap); cout<<endl;

cout<<"Enter the country name whose capital you want to see:";

gets(cn);

cout<<"COUNTRY"<<" "<<"CAPITAL"<<endl;

50
for(i=0;i<5;i++)

{ if(strcmp(cn,stor[i].co)==0)

{ cout.write(stor[i].co,strlen(stor[i].co));

cout<<" ";

cout.write(stor[i].cap,strlen(stor[i].cap));

PROGRAM 19
51
Write a program to accept a 2-D array of integers
and display the 2-digit numbers
#include<iostream.h>

void main()

int ar[10][10],r,c,i,j,s=0,d;

cout<<"Enter number of rows(max 10): "; cin>>r;

cout<<"Enter number of columns(max 10): ";cin>>c;

cout<<endl;

cout<<"Enter the elements: ";

for(i=0;i<r;i++)

for(j=0;j<c;j++)

cin>>ar[i][j];

cout<<"\nThe array you entered is: ";

for(i=0;i<r;i++)

cout<<endl;

for(j=0;j<c;j++)

cout<<ar[i][j]<<" ";

cout<<"\nThe two digit elements are: ";

for(i=0;i<r;i++)

52
{

for(j=0;j<c;j++)

int n=ar[i][j]; s=0;

while(n!=0)

d=n%10;

s++;

n=n/10;

if(s==2)

cout<<ar[i][j]<<",";

53
54
PROGRAM 20
Write a program to multiply two matrices
#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a[3][3],b[3][3],i,j,k,s;

cout<<"First 3x3 Matrix enter elements"<<endl;

for(i=0;i<3;i++)

for(j=0;j<3;j++)

cin>>a[i][j];

cout<<"Second 3x3 Matrix enter elements"<<endl;

for(i=0;i<3;i++)

for(j=0;j<3;j++)

cin>>b[i][j];

55
}

cout<<"Multiplication is"<<endl;

for(i=0;i<3;i++)

for(j=0;j<3;j++)

for(k=0;k<3;k++)

s=s+a[i][k]*b[k][j];

cout<<s<<" ";

s=0;

cout<<endl;

getch();

56
57
PROGRAM 21
Write a program to create a text file to read and
display uppercase and lowercase and consonants
#include<iostream.h>

#include<fstream.h>

#include<stdlib.h>

void main()

ofstream fout;

fout.open("Aschars",ios::app);

if(!fout)

cout<<"The file cannot be opened!!\n";

char ch; int line=0;

for(int i=33;i<128;i++)

fout.put(((char)i));

fout.close();

ifstream fin;

fin.open("Aschars",ios::in);

58
fin.seekg(0);

for(i=33;i<128;i++)

fin.get(ch);

cout<<"Uppercase"<<endl;

for(i=65;i<122;i++)

if(i>=65&&i<=90)

{cout<<" "<<i<<"=";

cout.put((char)i);

if(!(i%8))

{cout<<endl; line++;}}

cout<<endl<<"Lowercase"<<endl;

for(i=65;i<122;i++)

if(i>=97&&i<=122)

{cout<<" "<<i<<"=";

cout.put((char)i);

if(!(i%8))

{cout<<endl; line++;}}

cout<<endl<<"Vowels"<endl;

for(i=65;i<122;i++)

59
{

if(char(i)=='a'||char(i)=='A'||char(i)=='e'||char(i)=='E'||char(i)=='I'

||char(i)=='i'||char(i)=='O'||char(i)=='o'||char(i)=='u'

||char(i)=='U')

{cout<<" "<<i<<"=";

cout.put((char)i);

if(!(i%8))

{cout<<endl; line++;}}

} }

60
PROGRAM 22
Write a program to implement various file
operations
#include <iostream.h>

#include <fstream.h>

#include <conio.h>

static int totrec=0;

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)

61
{

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<<name<<endl;

cout<<"Enter Age : ";

int age;

cin>>age;

outfile<<age<<endl;

cout<<"Enter programming language known by him\her : ";

char lang[25];

cin>>lang;

outfile<<lang<<endl;

totrec= totrec + 1;

outfile.close();

break;

case 2 : {

ofstream outfile;

outfile.open("emp",ios::app);

62
cout<<"\n\nPlease enter the details as per demanded\n";

cout<<"\nEnter the name : ";

char name[20];

cin>>name;

outfile<<name<<endl;

cout<<"Enter Age : ";

int age;

cin>>age;

outfile<<age<<endl;

cout<<"Enter programming language known by him : ";

char lang[25];

cin>>lang;

outfile<<lang<<endl;

totrec = totrec + 1;

outfile.close();

break;

case 3 : {

ofstream outfile;

outfile.open("emp",ios::ate);

cout<<"Are you interested in adding record\nenter y or n\n";

char ans;

cin>>ans;

if(ans=='y' || ans=='Y')

63
{

cout<<"\n\nPlease enter the details as per demanded\n";

cout<<"\nEnter the name : ";

char name[20];

cin>>name;

outfile<<name<<endl;

cout<<"Enter Age : ";

int age;

cin>>age;

outfile<<age<<endl;

cout<<"Enter programming language known by him : ";

char lang[25];

cin>>lang;

outfile<<lang<<endl;

totrec = totrec + 1;

outfile.close();

break;

case 4 : {

ifstream infile;

infile.open("emp",ios::in);

const int size=80;

char line[size];

64
int counter=totrec;

while(counter > 0)

infile.getline(line,size);

cout<<"\n\nNAME : "<<line<<endl;

infile.getline(line,size);

cout<<"AGE : "<<line<<endl;

infile.getline(line,size);

cout<<"LANGUAGE : "<<line<<endl;

counter--;

infile.close();

getch();

break;

case 5 : goto out;

default : cout<<"\nInvalid Choice\nTRY AGAIN\n";

out:

65
66
PROGRAM 23
Write a program to create library management
system
#include <iostream.h>

#include <iomanip.h>

#include<stdio.h>

#include<string.h>

#include<conio.h>

class library

char author[50],title[50];

int price[15];

char pub[50];

int s;

public:

void getdata(void);

void display(void);

};

const int size=10;

library ord[size];

67
void library :: getdata(void)

cout<<"How many Entry you want to make(max 10):-";

cin>>s;

for(int i=0;i<s;i++)

cout<<"\nEnter Author Name :- ";

gets(ord[i].author);

cout<<"Enter Book Title :- ";

gets(ord[i].title);

cout<<"Enter Price of Book :- ";

cin>>ord[i].price[i];

cout<<"Enter Publisher of Book :- ";

gets(ord[i].pub);

void library :: display(void)

cout<<setw(50)<<"LIBRARY DATABASE";

cout<<endl<<endl;

for(int a=0;a<40;a++)

cout<<"*-";

68
cout<<endl;

cout<<"AUTHOR NAME"<<setw(20)<<"BOOK
TITLE"<<setw(22)<<"PRICE"<<setw(18)<<"PUBLISHER"<<endl;

for(int b=0;b<40;b++)

cout<<"*-";

cout<<endl;

for(int i=0;i<s;i++)

cout.write(ord[i].author,strlen(ord[i].author));

cout<<" ";

cout.write(ord[i].title,strlen(ord[i].title));

cout<<" "<<price[i]<<" ";

cout.write(ord[i].pub,strlen(ord[i].pub))<<endl;

void main()

library o1;

o1.getdata();

o1.display();

getch();

69
70
PROGRAM 24
Write a program to create linear stack of integers
and implement push and pop operations
#include<iostream.h>

#include<stdlib.h>

#include<process.h>

struct Node{ int info;

Node *next;

}*top,*newptr,*save,*ptr;

Node *Create(int);

void Push(Node*);

void Display(Node*);

void Pop();

int main()

top=NULL;

int inf; char ch='y';

while(ch=='y'||ch=='Y')

{ cout<<"\nEnter information for the new node...";

cin>>inf;

newptr=Create(inf);

if(newptr==NULL)

71
{ cout<<"\nCannot create new node!!! Aborting!!\n";

system("pause");

exit(1);

Push(newptr);

cout<<"\nPress Y to enter more nodes,N to exit...";

cin>>ch;

system("cls");

do

{ cout<<"\nThe stack now is:\n";

Display(top); system("pause");

cout<<"Want to pop an element?(y/n)...";

cin>>ch;

if(ch=='y'||ch=='Y')

Pop();

}while(ch=='y'||ch=='Y');

return 0;

Node *Create(int n)

{ptr=new Node;

ptr->info=n;

ptr->next=NULL;

72
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<<"->";

73
np=np->next;

cout<<"!!!\n";

OUTPUT:

Enter Information for the new node...6

Press Y to enter more nodes, N to exit...y

Enter Information for the new node...8

Press Y to enter more nodes, N to exit...y

Enter Information for the new node...9

Press Y to enter more nodes, N to exit...n

The Stack now is:

9->8->6->!!!

Want to pop an element?(y/n)...y

The Stack now is:

8->6->!!!

Want to pop an element?(y/n)...y

The Stack now is:

6->!!!

Want to pop an element?(y/n)...n

74
PROGRAM 25
Write a program to create linear circular queue and
to perform addition and deletion on it
#include<iostream.h>

#include<stdlib.h>

#include<process.h>

int Insert_in_CQ(int[],int);

void Display(int[],int,int);

int Del_in_CQ(int CQueue[]);

const int size=7;

int CQueue[size],front=-1,rear=-1;

int main()

{int Item,res,ch;

do{ system("cls");

cout<<"\t\t\tCircular Queue Menu\n";

cout<<"\t1.Insert\n";

cout<<"\t2.Delete\n";

cout<<"\t3.Display\n";

cout<<"\t4.Exit\n";

cout<<"Enter your choice...";

cin>>ch;

switch(ch)

75
{ case 1:cout<<"\nEnter item for insertion: ";

cin>>Item;

res=Insert_in_CQ(CQueue,Item);

if(res==-1) cout<<"Overflow!!\n";

else

{ cout<<"\nNow the Cir_Queue is:\n";

Display(CQueue,front,rear);

system("pause");

break;

case 2:Item=Del_in_CQ(CQueue);

cout<<"Element deleted is:"<<Item<<endl;

Display(CQueue,front,rear);

system("pause");

break;

case 3:Display(CQueue,front,rear);

system("pause");

break;

case 4:break;

default:cout<<"Inavlid input..\n";

system("pause");

break;

}while(ch!=4);

76
return 0;

int Insert_in_CQ(int CQueue[],int ele)

if((front==0&&rear==size-1)||(front==rear+1))

return -1;

else if(rear==-1) front=rear=0;

else if(rear==size-1) rear=0;

else rear++;

CQueue[rear]=ele;

return 0;

void Display(int CQueue[],int front,int rear)

{int i=0;

cout<<"\nCir_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(i=front;i<rear;i++) cout<<CQueue[i]<<"<-";

cout<<CQueue[rear]<<"<<<"<<endl;

77
else

{ for(i=0;i<rear;i++) cout<<CQueue[i]<<"<-";

cout<<CQueue[rear]<<"<<<";

for(;i<front;i++) cout<<"-";

cout<<">>>";

for(i=front;i<size;i++) cout<<CQueue[i]<<"<-";

cout<<"\t...wrap around...";

int Del_in_CQ(int CQueue[])

{ int ret;

if(front==-1) return -1;

else

{ ret=CQueue[front];

if(front==rear) front=rear=-1;

else if(front==size-1)

front=0;

else front++;

return ret;

78
OUTPUT:

Circular Queue Menu

1. Insert
2. Delete
3. Display
4. Exit

Enter your choice(1-4)...1

Enter Item for insertion: 9

Now the Cir_Queue is:

Cir_Queue is:

(Front shown as>>>,Rear as<<< and free space as -)

>>>3<-5<-8<-9<<<

Circular Queue Menu

1. Insert
2. Delete
3. Display
4. Exit

Enter your choice(1-4)...2

Enter Item for insertion: 3

Now the Cir_Queue is:

Cir_Queue is:

(Front shown as>>>,Rear as<<< and free space as -)

>>>5<-8<-9<<<

Circular Queue Menu

1. Insert
2. Delete
3. Display

79
4. Exit

Enter your choice(1-4)...4

80
PROGRAM 26
Write a program to implement push and pop on a
stack of array
#include<iostream.h>

#include<process.h>

int Pop(int[],int&);

int Push(int[],int&,int);

void Display(int[],int);

const int size=50;

int main()

{int Stack[size],Item,top=-1,res;

char ch='y';

while(ch=='y'||ch=='Y')

{ cout<<"\nEnter ITEM for insertion:";

cin>>Item;

res=Push(Stack,top,Item);

if(res==-1)

{ cout<<"Overflow!! Aborting!!\n";

exit(1);

cout<<"\nThe Stack now is:\n";

Display(Stack,top);

cout<<"\nWant to insert more elements?(y/n)...";

81
cin>>ch;

cout<<"Now deletion of elements begins...\n";

ch='y';

while(ch=='y'||ch=='Y')

{ res=Pop(Stack,top);

if(res==-1)

{ cout<<"Underflow!! Aborting!!\n";

exit(1);

else

{ cout<<"\nElement deleted is:"<<res<<endl;

cout<<"\n The Stack now is:\n";

Display(Stack,top);

cout<<"\nWant to delete more elements>(y/n)...";

cin>>ch;

return 0;

int Push(int Stack[],int &top,int ele)

{if(top==size-1) return -1;

else

{ top++;

82
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;

83
84
PROGRAM 27
Write a program to create a linked queue containing
employee number, salary and to perform addition
and deletion
#include<iostream.h>

#include<stdlib.h>

#include<process.h>

struct emp{ int empno;

int sal;

emp *next;

}*front,*newptr,*save,*ptr,*rear;

emp *Create(int,int);

void Insert(emp*);

void Display(emp*);

void DelNode_Q();

int main()

front=rear=NULL;

int num,sa; char ch='y';

while(ch=='y'||ch=='Y')

{ cout<<"\nEnter Employee Number:"; cin>>num;

cout<<"Enter Salary:"; cin>>sa;

85
newptr=Create(num,sa);

if(newptr==NULL)

{ cout<<"\nCannot create new node!!! Aborting!!\n";

exit(1);

Insert(newptr);

cout<<"\nPress Y to enter more Employees,N to exit...";

cin>>ch;

system("cls");

do

{ cout<<"\nThe Linked Queue now is(Front to rear):\n";

Display(front);

cout<<"Want to delete first node?(y/n)...";

cin>>ch;

if(ch=='y'||ch=='Y')

DelNode_Q();

}while(ch=='y'||ch=='Y');

return 0;

emp *Create(int n,int m)

{ptr=new emp;

ptr->empno=n;

86
ptr->sal=m;

ptr->next=NULL;

return ptr;

void Insert(emp *np)

{if(front==NULL) front=rear=np;

else

{ rear->next=np; rear=np;}

void DelNode_Q()

{ if(front==NULL) cout<<"Underflow!!\n";

else

{ ptr=front;

front=front->next;

delete ptr;

void Display(emp *np)

{while(np!=NULL)

{ cout<<”\n(Number,Salary)”<<np->empno<<”,”<<np->sal<<”->”;

87
np=np->next;

}cout<<”!!!\n”;

OUTPUT:

Enter Employee Number: 312

Enter Salary: 80000

Press Y to enter more Employees,N to exit...Y

Enter Employee Number: 756

Enter Salary: 50000

Press Y to enter more Employees,N to exit...N

The Linked Queue now is(Front to rear):

(Number,Salary)->756,50000->312,80000->!!!

Want to delete first node?(y/n)...y

The Linked Queue now is(Front to rear):

(Number,Salary)->312,80000->!!!

Want to delete first node?(y/n)...n

88
PROGRAM 28
Write a program to create linear circular queue and
perform addition on it

#include<iostream.h>

#include<stdlib.h>

#include<process.h>

int Insert_in_CQ(int[],int);

void Display(int[],int,int);

const int size=7;

int CQueue[size],front=-1,rear=-1;

int main()

{int Item,res,ch;

do{ system("cls");

cout<<"\t\t\tCircular Queue Menu\n";

cout<<"\t1.Insert\n";

cout<<"\t2.Display\n";

cout<<"\t3.Exit\n";

cout<<"Enter your choice...";

cin>>ch;

switch(ch)

{ case 1:cout<<"\nEnter item for insertion: ";

89
cin>>Item;

res=Insert_in_CQ(CQueue,Item);

if(res==-1) cout<<"Overflow!!\n";

else

{ cout<<"\nNow the Cir_Queue is:\n";

Display(CQueue,front,rear);

system("pause");

break;

case 2:Display(CQueue,front,rear);

system("pause");

break;

case 3:break;

default:cout<<"Inavlid input..\n";

system("pause");

break;

}while(ch!=4);

return 0;

int Insert_in_CQ(int CQueue[],int ele)

if((front==0&&rear==size-1)||(front==rear+1))

90
return -1;

else if(rear==-1) front=rear=0;

else if(rear==size-1) rear=0;

else rear++;

CQueue[rear]=ele;

return 0;

void Display(int CQueue[],int front,int rear)

{int i=0;

cout<<"\nCir_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(i=front;i<rear;i++) cout<<CQueue[i]<<"<-";

cout<<CQueue[rear]<<"<<<"<<endl;

else

{ for(i=0;i<rear;i++) cout<<CQueue[i]<<"<-";

cout<<CQueue[rear]<<"<<<";

for(;i<front;i++) cout<<"-";

cout<<">>>";

for(i=front;i<size;i++) cout<<CQueue[i]<<"<-";

91
cout<<"\t...wrap around...";

OUTPUT:

Circular Queue Menu

1. Insert

2. Display

3. Exit

Enter your choice(1-4)...1

Enter Item for insertion: 9

Now the Cir_Queue is:

Cir_Queue is:

(Front shown as>>>,Rear as<<< and free space as -)

>>>3<-5<-8<-9<<<

Circular Queue Menu

1. Insert

2. Delete

3. Display

4. Exit

Enter your choice(1-4)...4

92
PROGRAM 29
Write a program to create linear stack containing
roll number and age and perform push and pop on it

#include<iostream.h>

#include<stdlib.h>

#include<process.h>

struct stu{ int roll,age;

stu *next;

}*top,*newptr,*save,*ptr;

stu *Create(int,int);

void Push(stu*);

void Display(stu*);

void Pop();

int main()

top=NULL;

int r,a; char ch='y';

while(ch=='y'||ch=='Y')

{ cout<<"\nEnter student roll no.: "; cin>>r;

cout<<"Enter student's age: "; cin>>a;

newptr=Create(r,a);

93
if(newptr==NULL)

{ cout<<"\nCannot create new node!!! Aborting!!\n";

system("pause");

exit(1);

Push(newptr);

cout<<"\nPress Y to enter more nodes,N to exit...";

cin>>ch;

system("cls");

do

{ cout<<"\nThe stack now is:\n";

Display(top); system("pause");

cout<<"Want to pop an element?(y/n)...";

cin>>ch;

if(ch=='y'||ch=='Y')

Pop();

}while(ch=='y'||ch=='Y');

return 0;

stu *Create(int n,int m)

{ptr=new stu;

ptr->roll=n; ptr->age=m;

94
ptr->next=NULL;

return ptr;

void Push(stu *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(stu *np)

while(np!=NULL)

95
{ cout<<"\n(Rollno,age)->”<<np->roll<<",”<<np->age<<"->”;

np=np->next;

cout<<"!!!\n”;

OUTPUT:

Enter student roll no.: 12

Enter student’s age: 16

Press Y to enter more nodes,N to exit...Y

Enter student roll no.: 10

Enter student’s age: 15

Press Y to enter more nodes,N to exit...Y

Enter student roll no.: 23

Enter student’s age: 16

Press Y to enter more nodes,N to exit...N

The stack now is:

(Rollno,age)->23,16->10,15->12,16->!!!

Want to pop an element?(y/n)...y

The stack now is:

(Rollno,age)->10,15->12,16->!!!

Want to pop an element?(y/n)...n

SQL QUERIES
96
Table: EMPLOYEEINFO
ENO ENAME JOB MGR HIREDATE SAL COMM DPTNO
7369 MS Dhoni Clerk 7902 17-DEC-80 2800 20
7499 Ricky Ponting Salesman 7698 20-FEB-81 3600 300 30
7521 Rahul Dravid Salesman 7698 22-FEB-81 5250 500 30
7566 Sachin Tendulkar Manager 7839 02-APR-81 4975 20
7654 Steve Waugh Salesman 7698 28-SEP-81 6250 1400 30
7698 Sourav Ganguly Manager 7839 01-MAY-81 5850 30
7782 VVS Laxman Manager 7839 09-JUN-81 2450 10
7788 Shikhar Dhawan Analyst 7566 19-APR-87 5000 20
7839 Donald Bradman President 17-NOV-81 5000 10
7844 Piyush Chawla Salesman 7698 08-SEP-81 4500 30
7876 Arjuna Ranatunga Clerk 7788 23-MAY-87 6100 20
7900 Dale Steyn Clerk 7698 03-DEC-81 4950 30
7902 Rishi Kaushik Analyst 7566 03-DEC-81 3500 3600 20
7934 Cristiano Ronaldo Clerk 7782 23-JAN-82 5300 10

QUESTIONS:
A. To select all the columns of the above table
B. To list the name and employee number from the above table
C. To list the names, hiredate and salary of all the employees
D. To display the employee name and the incremented value of SAL as
SAL+300
E. To list ht employee name and annual salary(Annual salary=12*SAL+100)
F. Display the name and SAL where COMM is NULL
G. To list the DISTINCT department number from the table
H. To list the UNIQUE jobs from the table
I. To list the salary where salary is less than the commission
J. To list the salary between 3000 and 4000
K. To list the MGR which are between IN7902, 7566, 7788
L. To list the enames starting with ‘S’
M. To list all the columns where salary is greater than 3100
N. To list all the columns in ascending order of hiredate
O. To list all the columns in ascending order of DeptNo and descending order
of salary
P. To display the enames and job of employees hired between Feb 20,1981
and May 1,1981

97
Q. Display the enames and deptno of all the employees in department 20 and
30 in alphabetical ORDERBY name
R. To list the names and salary of all the employees who earn more than 1200
and are in department 10 or 40
S. To list the names and hiredate of all the employees who were hired in 1981
T. To list the employees who do not have managers
U. To list name and salary of all the employees where COMM is NOT NULL
V. To list names of all employees where the second letter of their name is ‘a’
W.To list the names and jobs of all the mployees who work in department 20
and their manager is 7788
X. To list the deptno,job and sum of salary group by deptno and job
Y. To list the enames which are not starting with ‘R’
Z. To add a new row containing the following data(7936, ‘Glen Mcgrath’,
‘Analyst’, 7799, ’23-Dec-82’, 5450, 20)

SOLUTIONS(QUERIES WITH OUTPUTS):

98
A. SELECT * FROM EMPLOYEEINFO;

ENO ENAME JOB MGR HIREDATE SAL COMM DEPTNO


7369 MS Dhoni Clerk 7902 17-DEC-80 2800 20
7499 Ricky Ponting Salesman 7698 20-FEB-81 3600 300 30
7521 Rahul Dravid Salesman 7698 22-FEB-81 5250 500 30
7566 Sachin Tendulkar Manager 7839 02-APR-81 4975 20
7654 Steve Waugh Salesman 7698 28-SEP-81 6250 1400 30
7698 Sourav Ganguly Manager 7839 01-MAY-81 5850 30
7782 VVS Laxman Manager 7839 09-JUN-81 2450 10
7788 Shikhar Dhawan Analyst 7566 19-APR-87 5000 20
7839 Donald Bradman President 17-NOV-81 5000 10
7844 Piyush Chawla Salesman 7698 08-SEP-81 4500 30
7876 Arjuna Ranatunga Clerk 7788 23-MAY-87 6100 20
7900 Dale Steyn Clerk 7698 03-DEC-81 4950 30
7902 Rishi Kaushik Analyst 7566 03-DEC-81 3500 3600 20
7934 Cristiano Ronaldo Clerk 7782 23-JAN-82 5300 10

B. SELECT ENAME, ENO


FROM EMPLOYEEINFO;
ENO ENAME
7369 MS Dhoni
7499 Ricky Ponting
7521 Rahul Dravid
7566 Sachin Tendulkar
7654 Steve Waugh
7698 Sourav Ganguly
7782 VVS Laxman
7788 Shikhar Dhawan
7839 Donald Bradman
7844 Piyush Chawla
7876 Arjuna Ranatunga
7900 Dale Steyn
7902 Rishi Kaushik
7934 Cristiano Ronaldo

C. SELECT ENAME,HIREDATE,SAL
FROM EMPLOYEEINFO;
ENO ENAME SAL
7369 MS Dhoni 2800
7499 Ricky Ponting 3600
7521 Rahul Dravid 5250

99
7566 Sachin Tendulkar 4975
7654 Steve Waugh 6250
7698 Sourav Ganguly 5850
7782 VVS Laxman 2450
7788 Shikhar Dhawan 5000
7839 Donald Bradman 5000
7844 Piyush Chawla 4500
7876 Arjuna Ranatunga 6100
7900 Dale Steyn 4950
7902 Rishi Kaushik 3500
7934 Cristiano Ronaldo 5300

D. SELECT ENAME, SAL+300


FROM EMPLOYEEINFO;
ENAME SAL
MS Dhoni 3100
Ricky Ponting 3900
Rahul Dravid 5550
Sachin Tendulkar 5275
Steve Waugh 6550
Sourav Ganguly 6150
VVS Laxman 2750
Shikhar Dhawan 5300
Donald Bradman 5300
Piyush Chawla 4800
Arjuna Ranatunga 6400
Dale Steyn 5250
Rishi Kaushik 3800
Cristiano Ronaldo 5600

E. SELECT ENAME,’gets annual salary’, 12*SAL+100


FROM EMPLOYEEINFO;
ENAME
MS Dhoni gets annual salary 33700
Ricky Ponting gets annual salary 43300
Rahul Dravid gets annual salary 63100
Sachin Tendulkar gets annual salary 59800
Steve Waugh gets annual salary 75100
Sourav Ganguly gets annual salary 70300
VVS Laxman gets annual salary 29500
Shikhar Dhawan gets annual salary 60100
Donald Bradman gets annual salary 60100
Piyush Chawla gets annual salary 54100

100
Arjuna Ranatunga gets annual salary 73300
Dale Steyn gets annual salary 59500
Rishi Kaushik gets annual salary 42100
Cristiano Ronaldo gets annual salary 63700

F. SELECT ENAME,SAL
FROM EMPLOYEEINFO
WHERE COMM IS NULL;
ENAME SAL
MS Dhoni 2800
Sachin Tendulkar 4975
Steve Waugh 6250
VVS Laxman 2450
Shikhar Dhawan 5000
Donald Bradman 5000
Piyush Chawla 4500
Arjuna Ranatunga 6100
Dale Steyn 4950
Cristiano Ronaldo 5300

G. SELECT DISTINCT DEPTNO


FROM EMPLOYEEINFO;
DEPTNO
20
30
10

H. SELECT UNIQUE JOB


FROM EMPLOYEEINFO;
JOBS
Clerk
Salesman
Manager
Analyst
President

I. SELECT SAL

101
FROM EMPLOYEEINFO
WHERE SAL<COMM;
SAL
3500

J. SELECT SAL
FROM EMPLOYEEINFO
WHERE SAL BETWEEN 3000 AND 4000;
SAL
2800
3600
2450
4950
3500

K. SELECT MGR
FROM EMPLOYEEINFO
WHERE MGR IN(‘7902’,’7566’,’7788’);
MGR
7902
7566
7788
7566

L. SELECT ENAME
FROM EMPLOYEEINFO
WHERE ENAME LIKE “S%”;
ENAME
Sachin Tendulkar
Steve Waugh
Sourav Ganguly
Shikhar Dhawan

M. SELECT * FROM EPLOYEEINFO

102
WHERE SAL>3100;
ENO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7499 Ricky Ponting Salesman 7698 20-FEB-81 3600 300 30
7521 Rahul Dravid Salesman 7698 22-FEB-81 5250 500 30
7566 Sachin Tendulkar Manager 7839 02-APR-81 4975 20
7654 Steve Waugh Salesman 7698 28-SEP-81 6250 1400 30
7698 Sourav Ganguly Manager 7839 01-MAY-81 5850 30
7788 Shikhar Dhawan Analyst 7566 19-APR-87 5000 20
7839 Donald Bradman President 17-NOV-81 5000 10
7844 Piyush Chawla Salesman 7698 08-SEP-81 4500 30
7876 Arjuna Ranatunga Clerk 7788 23-MAY-87 6100 20
7900 Dale Steyn Clerk 7698 03-DEC-81 4950 30
7902 Rishi Kaushik Analyst 7566 03-DEC-81 3500 3600 20
7934 Cristiano Ronaldo Clerk 7782 23-JAN-82 5300 10

N. SELECT * FROM EMPLOYEEINFO


ORDER BY HIREDATE;
ENO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 MS Dhoni Clerk 7902 17-DEC-80 2800 20
7499 Ricky Ponting Salesman 7698 20-FEB-81 3600 300 30
7521 Rahul Dravid Salesman 7698 22-FEB-81 5250 500 30
7566 Sachin Tendulkar Manager 7839 02-APR-81 4975 20
7698 Sourav Ganguly Manager 7839 01-MAY-81 5850 30
7782 VVS Laxman Manager 7839 09-JUN-81 2450 10
7844 Piyush Chawla Salesman 7698 08-SEP-81 4500 30
7654 Steve Waugh Salesman 7698 28-SEP-81 6250 1400 30
7839 Donald Bradman President 17-NOV-81 5000 10
7900 Dale Steyn Clerk 7698 03-DEC-81 4950 30
7902 Rishi Kaushik Analyst 7566 03-DEC-81 3500 3600 20
7934 Cristiano Ronaldo Clerk 7782 23-JAN-82 5300 10
7788 Shikhar Dhawan Analyst 7566 19-APR-87 5000 20
7876 Arjuna Ranatunga Clerk 7788 23-MAY-87 6100 20

O. SELECT * FROM EMPLOYEEINFO


ORDER BY DEPTNO ASC, SAL DESC;
ENO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7934 Cristiano Ronaldo Clerk 7782 23-JAN-82 5300 10
7839 Donald Bradman President 17-NOV-81 5000 10
7782 VVS Laxman Manager 7839 09-JUN-81 2450 10
7876 Arjuna Ranatunga Clerk 7788 23-MAY-87 6100 20
7788 Shikhar Dhawan Analyst 7566 19-APR-87 5000 20
7566 Sachin Tendulkar Manager 7839 02-APR-81 4975 20

103
7902 Rishi Kaushik Analyst 7566 03-DEC-81 3500 3600 20
7369 MS Dhoni Clerk 7902 17-DEC-80 2800 20
7654 Steve Waugh Salesman 7698 28-SEP-81 6250 1400 30
7698 Sourav Ganguly Manager 7839 01-MAY-81 5850 30
7521 Rahul Dravid Salesman 7698 22-FEB-81 5250 500 30
7900 Dale Steyn Clerk 7698 03-DEC-81 4950 30
7844 Piyush Chawla Salesman 7698 08-SEP-81 4500 30
7499 Ricky Ponting Salesman 7698 20-FEB-81 3600 300 30

P. SELECT ENAME,JOB
FROM EMPLOYEEINFO
WHERE HIREDATE BETWEEN ’20-FEB-81’ AND ’01-MAY-81’;
ENO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7499 Ricky Ponting Salesman 7698 20-FEB-81 3600 300 30
7521 Rahul Dravid Salesman 7698 22-FEB-81 5250 500 30
7566 Sachin Tendulkar Manager 7839 02-APR-81 4975 20
7698 Sourav Ganguly Manager 7839 01-MAY-81 5850 30

Q. SELECT ENAME, JOB


FROM EMPLOYEEINFO
WHERE (DEPTNO=20 OR DEPTNO=30)
ORDER BY ENAME;
ENAME JOB
Arjuna Ranatunga Clerk
MS Dhoni Clerk
Rishi Kaushik Analyst
Sachin Tendulkar Manager
Shikhar Dhawan Analyst

R. SELECT ENAME, SAL


FROM EMPLOYEEINFO
WHERE (SAL>1200 AND (DEPTNO=10 OR DEPTNO=30));
ENAME SAL
VVS Laxman 2450
Donald Bradman 5000
Cristiano Ronaldo 5300
Ricky Ponting 3600

104
Rahul Dravid 5250
Steve Waugh 6250
Sourav Ganguly 5850
Piyush Chawla 4500
Dale Steyn 4950

S. SELECT ENAME, HIREDATE


FROM EMPOYEEINFO
WHERE HIREDATE LIKE “%81”;
ENAME HIREDATE
Ricky Ponting 20-FEB-81
Rahul Dravid 22-FEB-81
Sachin Tendulkar 02-APR-81
Sourav Ganguly 01-MAY-81
VVS Laxman 09-JUN-81
Piyush Chawla 08-SEP-81
Steve Waugh 28-SEP-81
Donald Bradman 17-NOV-81
Dale Steyn 03-DEC-81
Rishi Kaushik 03-DEC-81

T. SELECT ENAME
FROM EMPLOYEEINFO
WHERE MGR IS NULL;
7839 Donald Bradman

U. SELECT ENAME, SAL


FROM EMPLOYEEINFO
WHERE COMM IS NOT NULL;
ENAME SAL
Ricky Ponting 3600
Rahul Dravid 5250
Steve Waugh 6250
Rishi Kaushik 3500

105
V. SELECT ENO, ENAME
FROM EMPLOYEEINFO
WHERE ENAME LIKE “_a%”;
ENO ENAME
7499 Ricky Ponting
7521 Rahul Dravid
7566 Sachin Tendulkar
7900 Dale Steyn

W. SELECT ENAME, JOB


FROM EMPLOYEEINFO
WHERE (DEPTNO=20 AND MGR=7788);
ENO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7876 Arjuna Ranatunga Clerk 7788 23-MAY-87 6100 20

X. SELECT JOB, sum(SAL)


FROM EMPLOYEEINFO
GROUP BY JOB;
JOBS sum(SAL)
Clerk 19150
Salesman 19600
Manager 13275
Analyst 13950
President 5000

Y. SELECT ENAME
FROM EMPLOYEEINFO
WHERE ENAME NOT LIKE “R%”;
ENAME
VVS Laxman
Donald Bradman
Cristiano Ronaldo
MS Dhoni
Sachin Tendulkar

106
Shikhar Dhawan
Arjuna Ranatunga
Steve Waugh
Sourav Ganguly
Piyush Chawla
Dale Steyn

Z. INSERT INTO EMPLOYEEINFO


VALUES(7936,’Glen Mcgrath’,’Analyst’,7799,’23-DEC-82’,20);
SELECT * FROM EMPLOYEEINFO;
ENO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 MS Dhoni Clerk 7902 17-DEC-80 2800 20
7499 Ricky Ponting Salesman 7698 20-FEB-81 3600 300 30
7521 Rahul Dravid Salesman 7698 22-FEB-81 5250 500 30
7566 Sachin Tendulkar Manager 7839 02-APR-81 4975 20
7654 Steve Waugh Salesman 7698 28-SEP-81 6250 1400 30
7698 Sourav Ganguly Manager 7839 01-MAY-81 5850 30
7782 VVS Laxman Manager 7839 09-JUN-81 2450 10
7788 Shikhar Dhawan Analyst 7566 19-APR-87 5000 20
7839 Donald Bradman President 17-NOV-81 5000 10
7844 Piyush Chawla Salesman 7698 08-SEP-81 4500 30
7876 Arjuna Ranatunga Clerk 7788 23-MAY-87 6100 20
7900 Dale Steyn Clerk 7698 03-DEC-81 4950 30
7902 Rishi Kaushik Analyst 7566 03-DEC-81 3500 3600 20
7934 Cristiano Ronaldo Clerk 7782 23-JAN-82 5300 10
7936 Glen Mcgrath Analyst Clerk 23-DEC-82 5450 20

107
108

You might also like