You are on page 1of 192

EXP. NO. 1 DATE: 12-4-12 ARRAYS AIM: To perform insertion, deletion and printing operations on an array. CODE: #include<iostream.

h> #include<conio.h> #include<process.h> int a[101], n, i, lb=0, ub=0; void printing() { cout<<"\nCurrent status of array: \n"; for(i=lb;i<=ub;i++) cout<<a[i]<<" "; cout<<endl; } void insertion() { if(ub-lb+1>101) { cout<<"\nOverflow error!\n"; getch();
1|Page

} else { int pos; cout<<"\nEnter position of insertion: "; cin>>pos; ub++; if(pos<=ub) { for(i=ub;i>=pos+1;i--) a[i]=a[i-1]; cout<<"\nEnter element to be inserted: "; cin>>a[pos]; } else { cout<<"\nEnter element to be inserted: "; cin>>a[pos]; } } printing(); } void deletion() { int pos; cout<<"\nEnter position of deletion: ";
2|Page

cin>>pos; if(pos<=ub) { for(i=pos;i<=ub;i++) a[i]=a[i+1]; ub--; } else cout<<"\nError, cannot delete!\n"; printing(); } void main() { clrscr(); int ch; cout<<"\nCreate your array!\n"; cout<<"\nHow many elements in the array? Number should be <100 : "; cin>>n; cout<<"\nEnter elements of array: \n"; for(i=1;i<=n;i++) cin>>a[i]; lb=1; ub=n; printing(); p: clrscr(); cout<<"\nMain Menu\n"; cout<<"1. Insertion\n";
3|Page

cout<<"2. Deletion\n"; cout<<"3. Printing\n"; cout<<"4. Exit\n"; cout<<"Enter your choice: "; cin>>ch; switch(ch) { case 1:insertion(); getch(); goto p; case 2:deletion(); getch(); goto p; case 3:printing(); getch(); goto p; case 4:cout<<"\nPress any key to exit."; getch(); exit(0); default: cout<<"\nWrong option! Enter again!\n"; getch(); goto p; } } SAMPLE OUTPUT FOR THIS PROGRAM Create your array! How many elements in the array? Number should be <100: 4
4|Page

Enter elements of array 1 2 4 5 Current status of array 1 2 4 5 Press any key Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 1 Enter position of insertion 3 Enter element to be inserted 3 Current status of array 1 2 3 4 5 Press any key Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit
5|Page

Enter your choice: 2 Enter position of deletion 5 Current status of array 1 2 3 4 Press any key Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 4 Press any key to exit.

6|Page

EXP. NO. 2 DATE: 9-8-12 STACK AS AN ARRAY AIM: To perform insertion, deletion and printing operations on a static stack. CODE: #include<iostream.h> #include<conio.h> #include<process.h> int stack[101], top=0, i; void insertion() { if(top==100) { cout<<"Overflow error\n"; getch(); } else { top++; cout<<"Enter a value to insert\n"; cin>>stack[top]; }
7|Page

} void deletion() { if(top==0) { cout<<"Underflow error\n"; getch(); } else { int g=stack[top]; cout<<g<<" deleted!\n"; top--; } } void printing() { cout<<"\nCurrent status of stack\n"; for(i=top;i>=1;i--) cout<<stack[i]<<" "; } void main() { int ch; do {
8|Page

cout<<"\nMain Menu\n"; cout<<"1. Insertion\n"; cout<<"2. Deletion\n"; cout<<"3. Printing\n"; cout<<"4. Exit\n"; cout<<"Enter your choice: "; cin>>ch; switch(ch) { case 1: insertion(); break; case 2: deletion(); break; case 3: printing(); break; case 4: cout<<"Press any key to exit."; getch(); exit(0); } //end of switch } //end of do loop while ((ch>=1) && (ch<=4)); getch(); } SAMPLE OUTPUT FOR THIS PROGRAM Main Menu 1. Insertion 2. Deletion
9|Page

3. Printing 4. Exit Enter your choice: 1 Enter a value to insert 7 Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 1 Enter a value to insert 8 Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 1 Enter a value to insert 9 Main Menu 1. Insertion 2. Deletion 3. Printing
10 | P a g e

4. Exit Enter your choice: 3 Current status of stack 789 Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 2 9 deleted! Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 3 Current status of stack 78 Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 4
11 | P a g e

Press any key to exit.

12 | P a g e

EXP. NO. 3 DATE: 30-8-12 QUEUE AS AN ARRAY AIM: To perform insertion, deletion and printing operations on a static queue. CODE: #include<iostream.h> #include<conio.h> #include<process.h> int queue[101], front=0, rear=0, i; void insertion() { if(rear+1>100) { cout<<"Overflow error\n"; getch(); } else { if((front==0)&&(rear==0)) front=rear=1; else rear++;
13 | P a g e

cout<<"Enter an element to insert\n"; cin>>queue[rear]; } }

void deletion() { if(front==0) { cout<<"Underflow error\n"; getch(); } else if(front==rear) { int g=queue[front]; cout<<g<<" deleted!\n"; front=rear=0; } else { int g=queue[front]; cout<<g<<" deleted!\n"; front++; } } void printing() { cout<<"\nCurrent status of queue\n";
14 | P a g e

for(i=front;i<=rear;i++) cout<<queue[i]<<" "; } void main() { int ch; do { cout<<"\nMain Menu\n"; cout<<"1. Insertion\n"; cout<<"2. Deletion\n"; cout<<"3. Printing\n"; cout<<"4. Exit\n"; cout<<"Enter your choice: "; cin>>ch; switch(ch) { case 1: insertion(); break; case 2: deletion(); break; case 3: printing(); break; case 4: cout<<"Press any key to exit."; getch(); exit(0); } //end of switch } //end of do loop
15 | P a g e

while ((ch>=1) && (ch<=4)); getch(); } SAMPLE OUTPUT FOR THIS PROGRAM Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 1 Enter an element to insert 1995 Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 1 Enter an element to insert 19 Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit
16 | P a g e

Enter your choice: 1 Enter an element to insert 12 Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 3 Current status of queue 1995 19 12 Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 2 1995 deleted! Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 3
17 | P a g e

Current status of queue 19 12 Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 4 Press any key to exit.

18 | P a g e

EXP. NO. 4 DATE: 16-8-12 STACK AS A LINKED LIST AIM: To perform insertion, deletion and printing operations on a dynamic stack. CODE: #include<iostream.h> #include<conio.h> #include<process.h> struct SLL { int a; float b; char c; SLL *next; } *top, *temp, *ptr; void insertion() { ptr=new SLL; if(ptr==NULL) { cout<<"Overflow error\n"; getch();
19 | P a g e

} else { cout<<"Enter values for a, b, c\n"; cout<<"a is int, b is float, c is char\n"; cin>>ptr->a>>ptr->b>>ptr->c; ptr->next=top; top=ptr; } } void deletion() { if(top==NULL) { cout<<"Underflow error\n"; getch(); } else { temp=top; cout<<temp->a<<" "<<temp->b<<" "<<temp->c<<" deleted!\n"; top=top->next; delete(temp); } } void printing() {
20 | P a g e

temp=top; while(temp!=NULL) { cout<<temp->a<<" "<<temp->b<<" "<<temp->c<<endl; temp=temp->next; } } void main() { int ch; do { cout<<"\nMain Menu\n"; cout<<"1. Insertion\n"; cout<<"2. Deletion\n"; cout<<"3. Printing\n"; cout<<"4. Exit\n"; cout<<"Enter your choice: "; cin>>ch; switch(ch) { case 1: insertion(); break; case 2: deletion(); break; case 3: printing(); break; case 4: cout<<"Press any key to exit.";
21 | P a g e

getch(); exit(0); } //end of switch } //end of do loop while ((ch>=1) && (ch<=4)); getch(); } SAMPLE OUTPUT FOR THIS PROGRAM Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 1 Enter values for a, b, c a is int, b is float, c is char 4 5.3 r Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 1 Enter values for a, b, c a is int, b is float, c is char 6 2.44 b
22 | P a g e

Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 3 Current status of stack 6 2.44 b 4 5.3 r Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 2 6 2.44 b deleted! Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 3 Current status of stack 4 5.3 r Main Menu
23 | P a g e

1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 4 Press any key to exit.

24 | P a g e

EXP. NO. 5 DATE: 6-9-12 QUEUE AS A LINKED LIST AIM: To perform insertion, deletion and printing operations on a dynamic queue. CODE: #include<iostream.h> #include<conio.h> #include<process.h> struct QLL { int a; float b; char c; QLL *next; } *front, *rear, *temp, *ptr; void insertion() { ptr=new QLL; if(ptr==NULL) { cout<<"Overflow error\n"; getch();
25 | P a g e

} else if((front==NULL)&&(rear==NULL)) { cout<<"Enter values for a, b, c\n"; cout<<"a is int, b is float, c is char\n"; cin>>ptr->a>>ptr->b>>ptr->c; ptr->next=NULL; front=rear=ptr; } else { rear->next=ptr; ptr->next=NULL; rear=ptr; cout<<"Enter values for a, b, c\n"; cout<<"a is int, b is float, c is char\n"; cin>>ptr->a>>ptr->b>>ptr->c; } } void deletion() { if(front==NULL) { cout<<"Underflow error\n"; getch(); } else if(front==rear) {
26 | P a g e

temp=front; cout<<temp->a<<" "<<temp->b<<" "<<temp->c<<" deleted!\n"; front=rear=NULL; delete(temp); } else { temp=front; cout<<temp->a<<" "<<temp->b<<" "<<temp->c<<" deleted!\n"; front=front->next; delete(temp); } } void printing() { temp=front; while(temp!=NULL) { cout<<temp->a<<" "<<temp->b<<" "<<temp->c<<endl; temp=temp->next; } } void main() { int ch; do {
27 | P a g e

cout<<"\nMain Menu\n"; cout<<"1. Insertion\n"; cout<<"2. Deletion\n"; cout<<"3. Printing\n"; cout<<"4. Exit\n"; cout<<"Enter your choice: "; cin>>ch; switch(ch) { case 1: insertion(); break; case 2: deletion(); break; case 3: printing(); break; case 4: cout<<"Press any key to exit."; getch(); exit(0); } //end of switch } //end of do loop while ((ch>=1) && (ch<=4)); getch(); } SAMPLE OUTPUT FOR THIS PROGRAM Main Menu 1. Insertion 2. Deletion
28 | P a g e

3. Printing 4. Exit Enter your choice: 1 Enter values for a, b, c a is int, b is float, c is char 10 5.3 c Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 1 Enter values for a, b, c a is int, b is float, c is char 25 4.05 k Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 1 Enter values for a, b, c a is int, b is float, c is char 14 3.14 p Main Menu 1. Insertion
29 | P a g e

2. Deletion 3. Printing 4. Exit Enter your choice: 3 Current status of queue: 10 5.3 c 25 4.05 k 14 3.14 p Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 2 10 5.3 c deleted! Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 3 Current status of queue: 25 4.05 k 14 3.14 p Main Menu 1. Insertion
30 | P a g e

2. Deletion 3. Printing 4. Exit Enter your choice: 4 Press any key to exit.

31 | P a g e

EXP. NO. 6 DATE: 13-9-12 CIRCULAR QUEUE AIM: To perform insertion, deletion and printing operations on a static circular queue. CODE: #include<iostream.h> #include<conio.h> #include<process.h> int cqueue[11], front=0, rear=0, i, j; void insertion() { if((front==0)&&(rear==10)||(front==rear+1)) { cout<<"Overflow error\n"; getch(); } else if(front==0) front=rear=1; else if(rear==10) rear=1; else rear++; cout<<"Enter element to be inserted\n"; cin>>cqueue[rear];
32 | P a g e

} void deletion() { if(front==0) { cout<<"Underflow error\n"; getch(); } else if(front==rear) { cout<<cqueue[front]<<" deleted!\n"; front=rear=0; } else if(front==10) front=1; else { cout<<cqueue[front]<<" deleted!\n"; front++; } } void printing() { if(front==0) { cout<<"Queue is empty!\n"; getch(); }
33 | P a g e

else if(front<=rear) { cout<<"Current status of queue:\n"; for(i=front;i<=rear;i++) cout<<cqueue[i]<<" "; } else { cout<<"Current status of queue\n"; for(i=front;i<=10;i++) cout<<cqueue[i]<<" "; for(j=1;j<=rear;j++) cout<<cqueue[j]<<" "; } } void main() { int ch; do { cout<<"\nMain Menu\n"; cout<<"1. Insertion\n"; cout<<"2. Deletion\n"; cout<<"3. Printing\n"; cout<<"4. Exit\n"; cout<<"Enter your choice: "; cin>>ch; switch(ch)
34 | P a g e

{ case 1: insertion(); break; case 2: deletion(); break; case 3: printing(); break; case 4: cout<<"Press any key to exit."; getch(); exit(0); } //end of switch } //end of do loop while ((ch>=1) && (ch<=4)); getch(); } SAMPLE OUTPUT FOR THIS PROGRAM Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 1 Enter element to be inserted 16 Main Menu 1. Insertion
35 | P a g e

2. Deletion 3. Printing 4. Exit Enter your choice: 1 Enter element to be inserted 35 Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 1 Enter element to be inserted 84 Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 3 Current status of queue: 16 35 84 Main Menu 1. Insertion 2. Deletion 3. Printing
36 | P a g e

4. Exit Enter your choice: 2 16 deleted! Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 3 Current status of queue: 35 84 Main Menu 1. Insertion 2. Deletion 3. Printing 4. Exit Enter your choice: 4 Press any key to exit.

37 | P a g e

EXP. NO. 7 DATE: 26-4-12 SEARCH IN AN ARRAY AIM: To perform search in an array using linear search and binary search. CODE: #include<iostream.h> #include<conio.h> #include<process.h> const int size=25; int bs(int a[], int n, int data) { int low,high,mid; low=0; high=n-1; while(low<=high) { mid=(low+high)/2; if(a[mid]==data) return(mid); else if(data>a[mid]) low=mid+1; else high=mid-1;
38 | P a g e

} return(-1); } int ls(int a[],int n, int data) { int i=0; while(i<n) { if(a[i]==data) return (i); i++; } return (-1); } void main() { int a[size], n, i, data, pos, ch; cout<<"\nHow many elements? Should be less than "<<size<<endl; cin>>n; cout<<"\nEnter the elements of your array in ascending order\n"; for(i=0;i<n;i++) cin>>a[i]; cout<<"\nThis is your array\n"; for(i=0;i<n;i++) cout<<a[i]<<" ";
39 | P a g e

cout<<endl; do { cout<<"\nMain Menu\n"; cout<<"1. Binary Search\n"; cout<<"2. Linear Search\n"; cout<<"3. Exit\n"; cout<<"Enter your choice: "; cin>>ch; switch(ch) { case 1: cout<<"\nEnter element to be searched\n"; cin>>data; pos=bs(a, n, data); break; case 2: cout<<"\nEnter element to be searched\n"; cin>>data; pos=ls(a, n, data); break; case 3: cout<<"Press any key to exit."; getch(); exit(0); } //end of switch if (pos==-1) cout<<"\n Search unsuccessful!\n"; else
40 | P a g e

{ cout<<"\n Search successful!\n"; cout<<data<<" found at position "<<pos+1<<endl;

} } //end of do loop while (ch>=1 && ch<=3); getch(); }

SAMPLE OUTPUT FOR THIS PROGRAM How many elements? Should be less than 20 6 Enter the elements of your array in ascending order 112358 This is your array 112358 Main Menu 1. Binary Search 2. Linear Search 3. Exit Enter your choice: 1 Enter element to be searched 8 Search successful!
41 | P a g e

8 found at position 6 Main Menu 1. Binary Search 2. Linear Search 3. Exit Enter your choice: 2 Enter element to be searched 21 Search unsuccessful! Main Menu 1. Binary Search 2. Linear Search 3. Exit Enter your choice: 2 Enter element to be searched 2 Search successful! 2 found at position 3 Main Menu 1. Binary Search 2. Linear Search 3. Exit Enter your choice: 3 Press any key to exit.
42 | P a g e

EXP. NO. 8 DATE: 7-6-12 SORTING AN ARRAY AIM: To sort an array using insertion sort, selection sort and bubble sort. CODE: #include<iostream.h> #include<conio.h> #include<process.h> const int size=25; void selection(int a[], int n) { int i, pass, temp, min_index; for(pass=0;pass<n-1;pass++) { min_index=pass; for(i=pass+1;i<n;i++) { if(a[i]<a[min_index]) min_index=i; } if(pass!=min_index) { temp=a[pass];
43 | P a g e

a[pass]=a[min_index]; a[min_index]=temp; } } void insort(int a[], int n) { int i, j, pos, current; for(i=1;i<n;i++) { current=a[i]; pos=0; while((pos<i)&&(a[pos]<=current)) pos++; if(pos!=i) { for(j=i-1;j>=pos;j--) a[j+1]=a[j]; a[pos]=current; } } } void bubble(int a[], int n) { int i, pass, last, temp, exchs; pass=0; last=n-1;
44 | P a g e

do { pass++; exchs=0; for(i=0;i<last;i++) { if(a[i]>a[i+1]) { temp=a[i]; a[i]=a[i+1]; a[i+1]=temp; exchs++; } } last--; }while((exchs!=0)&&(pass!=n-1)); cout<<"No. of passes used for sorting: "<<pass<<endl; } void main() { clrscr(); int a[size], n, i, ch; cout<<"\nHow many elements? Should be less than "<<size<<endl; cin>>n; p: clrscr(); cout<<"\nMain Menu\n";
45 | P a g e

cout<<"1. Selection Sort\n"; cout<<"2. Insertion Sort\n"; cout<<"3. Bubble Sort\n"; cout<<"4. Exit\n"; cout<<"Enter your choice: "; cin>>ch; switch (ch) { case 1: { clrscr(); cout<<"\nEnter the elements of new array to be sorted\n"; for(i=1;i<=n;i++) cin>>a[i]; cout<<endl; cout<<"This is your array\n"; for(i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl; selection(a,n); cout<<"\nYour array, now sorted:\n"; for(i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl; getch(); goto p; } case 2:
46 | P a g e

{ clrscr(); cout<<"\nEnter the elements of new array to be sorted\n"; for(i=1;i<=n;i++) cin>>a[i]; cout<<endl; cout<<"This is your array\n"; for(i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl; insort(a,n); cout<<"\nYour array, now sorted:\n"; for(i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl; getch(); goto p; } case 3: { clrscr(); cout<<"\nEnter the elements of new array to be sorted\n"; for(i=1;i<=n;i++) cin>>a[i]; cout<<endl; cout<<"This is your array\n"; for(i=1;i<=n;i++)
47 | P a g e

cout<<a[i]<<" "; cout<<endl; bubble(a,n); cout<<"\nYour array, now sorted:\n"; for(i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl; getch(); goto p; } case 4: cout<<"\nPress any key to exit"; getch(); exit(0); } //end of switch getch(); } SAMPLE OUTPUT FOR THIS PROGRAM How many elements? Should be less than 25 5 Main Menu 1. Selection Sort 2. Insertion Sort 3. Bubble Sort 4. Exit Enter your choice: 1
48 | P a g e

Enter elements of new array to be sorted 55 33 11 99 77 This is your array 55 33 11 99 77 Your array, now sorted: 11 33 55 77 99 Main Menu 1. Selection Sort 2. Insertion Sort 3. Bubble Sort 4. Exit Enter your choice: 2 Enter the elements of new array to be sorted 88 44 66 22 111 This is your array 88 44 66 22 111 Your array, now sorted: 22 44 66 88 111
49 | P a g e

Main Menu 1. Selection Sort 2. Insertion Sort 3. Bubble Sort 4. Exit Enter your choice: 3 Enter the elements of new array to be sorted 2 1 5 8 21 This is your array 2 1 5 8 21 No. of passes used for sorting: 1 Your array, now sorted: 1 2 5 8 21 Main Menu 1. Selection Sort 2. Insertion Sort 3. Bubble Sort 4. Exit Enter your choice: 4 Press any key to exit.

50 | P a g e

EXP. NO. 9 DATE: 19-4-12 MATRIX OPERATIONS AIM: To perform operations on a two-dimensional array, i.e. addition, subtraction,product of two matrices and transpose of a matrix. CODE: #include <conio.h> #include <process.h> #include <iostream.h> int a[100][100], b[100][100], m, n, p, q, i, j, k; void addition() { t: cout<<"\nEnter cin>>m; cout<<"\nEnter cin>>n; cout<<"\nEnter cin>>p; cout<<"\nEnter cin>>q; if(m!=p||n!=q)

no. of rows of matrix 1: "; no. of columns of matrix 1: "; no. of rows of matrix 2: "; no. of columns of matrix 2: ";

51 | P a g e

{ cout<<"\nEnter matrices properly!\n"; goto t;

} else { cout<<"\nEnter elements of matrix 1\n"; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) cin>>a[i][j]; } cout<<"\nEnter elements of matrix 2\n"; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) cin>>b[i][j]; } cout<<"\nGiven matrix 1 is\n"; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) cout<<a[i][j]<<" "; cout<<endl; } cout<<"\nGiven matrix 2 is\n"; for(i=1;i<=m;i++) { for(j=1;j<=n;j++)
52 | P a g e

cout<<b[i][j]<<" "; cout<<endl; } cout<<"\nAdded matrix is\n"; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) cout<<a[i][j]+b[i][j]<<" "; cout<<endl; } getch(); } //end of else } //end of addition void subtraction() { g: cout<<"\nEnter no. of rows of matrix 1: "; cin>>m; cout<<"\nEnter no. of columns of matrix 1: "; cin>>n; cout<<"\nEnter no. of rows of matrix 2: "; cin>>p; cout<<"\nEnter no. of columns of matrix 2: "; cin>>q; if(m!=p||n!=q) { cout<<"\nEnter matrices properly!\n"; goto g;
53 | P a g e

} else { cout<<"\nEnter elements of matrix 1\n"; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) cin>>a[i][j]; } cout<<"\nEnter elements of matrix 2\n"; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) cin>>b[i][j]; } cout<<"\nGiven matrix 1 is\n"; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) cout<<a[i][j]<<" "; cout<<endl; } cout<<"\nGiven matrix 2 is\n"; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) cout<<b[i][j]<<" "; cout<<endl; }
54 | P a g e

} } //end of subtraction

cout<<"\nSubtracted matrix is\n"; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) cout<<a[i][j]-b[i][j]<<" "; cout<<endl; } getch();

void product() { d: cout<<"\nEnter no. of rows of matrix 1: "; cin>>m; cout<<"\nEnter no. of columns of matrix 1: "; cin>>n; cout<<"\nEnter no. of rows of matrix 2: "; cin>>p; cout<<"\nEnter no. of columns of matrix 2: "; cin>>q; if(n!=p) { cout<<"\nEnter matrices properly!\n"; goto d; } else {
55 | P a g e

int c[100][100]; cout<<"\nEnter elements of matrix 1\n"; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) cin>>a[i][j]; } cout<<"\nEnter elements of matrix 2\n"; for(i=1;i<=p;i++) { for(j=1;j<=q;j++) cin>>b[i][j]; } cout<<"\nGiven matrix 1 is\n"; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) cout<<a[i][j]<<" "; cout<<endl; } cout<<"\nGiven matrix 2 is\n"; for(i=1;i<=p;i++) { for(j=1;j<=q;j++) cout<<b[i][j]<<" "; cout<<endl; } cout<<"\nThe product of the matrices is\n"; for(i=1;i<=m;i++)
56 | P a g e

{ for(j=1;j<=q;j++) { c[i][j]=0; for(k=1;k<=n;k++) c[i][j]+=a[i][k]*b[k][j]; cout<<c[i][j]<<" "; } cout<<endl; } //end of for loop getch(); } //end of else } //end of product void transpose() { cout<<"\nEnter no. of rows of the matrix: "; cin>>m; cout<<"\nEnter no. of columns of the matrix: "; cin>>n; cout<<"\nEnter the values of the matrix\n"; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) cin>>a[i][j]; } cout<<"\nGiven matrix is\n"; for(i=1;i<=m;i++) {
57 | P a g e

} cout<<"\nTranspose of the matrix is\n"; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) cout<<a[j][i]<<" "; cout<<endl; } getch(); } void main() { p: clrscr(); cout<<"\nMain Menu\n"; cout<<"1. Addition\n"; cout<<"2. Subtraction\n"; cout<<"3. Product\n"; cout<<"4. Transpose\n"; cout<<"5. Exit\n"; cout<<"Enter your choice: "; int ch; cin>>ch; switch(ch) {
58 | P a g e

for(j=1;j<=n;j++) cout<<a[i][j]<<" "; cout<<endl;

case 1: addition(); goto p; case 2: subtraction(); goto p; case 3: product(); goto p; case 4: transpose(); goto p; case 5: cout<<"\nPress any key to exit."; getch(); exit(0); default: cout<<"\nWrong option! Select again"; getch(); goto p; } } SAMPLE OUTPUT FOR THIS PROGRAM Main Menu 1. Addition 2. Subtraction 3. Product 4. Transpose 5. Exit Enter your choice: 1 Enter no. of rows of matrix 1: 2 Enter no. of columns of matrix 1: 2
59 | P a g e

Enter no. of rows of matrix 2: 2 Enter no. of columns of matrix 2: 2 Enter elements of matrix 1 1001 Enter elements of matrix 2 0220 Given matrix 1 is 10 01 Given matrix 2 is 02 20 Added matrix is 12 21 Main Menu 1. Addition 2. Subtraction 3. Product 4. Transpose 5. Exit Enter your choice: 2 Enter no. of rows of matrix 1: 3
60 | P a g e

Enter no. of columns of matrix 1: 3 Enter no. of rows of matrix 2: 3 Enter no. of columns of matrix 2: 3 Enter elements of matrix 1 2 3 4 3 4 5 4 5 5 Enter elements of matrix 2 1 -3 5 0 2 4 3 0 4 Given 2 3 3 4 4 5 Given 1 -3 0 2 3 0 matrix 1 is 4 5 5 matrix 2 is 5 4 4

Subtracted matrix is 1 6 -1 3 2 1 1 5 1 Main Menu 1. Addition 2. Subtraction 3. Product


61 | P a g e

4. Transpose 5. Exit Enter your choice: 3 Enter Enter Enter Enter no. of rows of matrix 1: 3 no. of columns of matrix 1: 2 no. of rows of matrix 2: 2 no. of columns of matrix 2: 3

Enter elements of matrix 1 2 1 3 2 -1 1 Enter elements of matrix 2 000000 Given matrix 1 is 2 1 3 2 -1 1 Given matrix 2 is 000 000 The product of the matrices is 000 000 000 Main Menu
62 | P a g e

1. Addition 2. Subtraction 3. Product 4. Transpose 5. Exit Enter your choice: 4 Enter no. of rows of the matrix: 3 Enter no. of columns of the matrix: 2 Enter the values of the matrix 1 -2 -3 2 1 -2 3 2 1 Given matrix is 1 -2 -3 2 1 -2 321 Transpose of the matrix is 123 -2 1 2 -3 -2 1 Main Menu 1. Addition 2. Subtraction 3. Product 4. Transpose 5. Exit Enter your choice: 5 Press any key to exit.
63 | P a g e

EXP. NO. 10 DATE: 26-7-12 SINGLE LEVEL INHERITANCE AIM: To maintain a database of employees and managers using single level inheritance. CODE: #include<iostream.h> #include<conio.h> #include<stdio.h> #include<ctype.h> #include<process.h> int i, m, n, count=0; class person { char name[50]; char address[50]; char department[50]; public: int emp_no; void readdata() { cout<<"\nEmployee number: "; cin>>emp_no; cout<<"Name: ";
64 | P a g e

gets(name); cout<<"Address: "; gets(address); cout<<"Department: "; gets(department); cout<<endl; } void displaydata() { cout<<"Employee no.: "<<emp_no<<endl; cout<<"Name : "; puts(name); cout<<"Address: "; puts(address); cout<<"Department: "; puts(department); cout<<endl; } int give_emp_no(int j) { int flag=0; if(j==emp_no) flag=1; return flag; } } e[100]; class manager: public person { public: int numemp; void readmandata();
65 | P a g e

void showmandata(); int get_a_no(int o) { int fi=0; if(o==emp_no) fi=1; return fi; } } f[100]; void manager::readmandata() { readdata(); cout<<"No. of employees working under him/her: \n"; cin>>numemp; } void manager:: showmandata() { displaydata(); cout<<"No. of employees working under him/her: "<<numemp<<endl; } void menu() { p: clrscr(); cout<<"\nMain Menu\n";
66 | P a g e

cout<<"1. Accepting employee details\n"; cout<<"2. Accepting manager details\n"; cout<<"3. Display employee details\n"; cout<<"4. Display manager details\n"; cout<<"5. Exit\n"; int ch; cout<<"Enter your choice: "; cin>>ch; switch(ch) { case 1: { cout<<"\nHow many employees: "; cin>>n; for(i=1;i<=n;i++) e[i].readdata(); cout<<"\nDetails saved!"; getch(); goto p; } case 2: { cout<<"\nHow many managers?\n"; cin>>m; for(i=1;i<=m;i++) f[i].readmandata(); cout<<"\nDetails saved!"; getch(); goto p;
67 | P a g e

} case 3: { clrscr(); for(i=1;i<=n;i++) { cout<<"Details of employee "<<i<<endl; e[i].displaydata(); } getch(); goto p; } case 4: { int code, fl; clrscr(); cout<<"\nEnter manager code(emp. no of manager) for displaying details: "; cin>>code; for(i=1;i<=m;i++) { fl=f[i].get_a_no(code); if(fl==1) { cout<<"\nDetails of manager "<<i<<endl; f[i].showmandata(); break; } else
68 | P a g e

cout<<"\nEnter correct codes!\n"; } getch(); goto p; } case 5: { cout<<"Press any key to exit."; getch(); exit(0); } default: goto p; } }

void main() { clrscr(); menu(); getch(); } SAMPLE OUTPUT FOR THIS PROGRAM Main Menu 1. Accepting employee details 2. Accepting manager details 3. Display employee details 4. Display manager details
69 | P a g e

5. Exit Enter your choice: 1 How many employees? : 2 Enter details of employee 1 Employee number: 10 Name: Mona Lisa Address: Museum de Louvre Department: Accounts Enter details of employee 2 Employee number: 8 Name: Ubanish Lahari Address: Anfield Department: Research Details saved! Main Menu 1. Accepting employee details 2. Accepting manager details 3. Display employee details 4. Display manager details 5. Exit Enter your choice: 2 How many managers? : 1 Enter details of manager 1
70 | P a g e

Employee no. : 5 Name: Brendan Rodgers Address: Liverpool Department: HR No. of employees working under him/her: 3 Details saved! Main Menu 1. Accepting employee details 2. Accepting manager details 3. Display employee details 4. Display manager details 5. Exit Enter your choice: 3 Details of employee 1 Employee number: 10 Name: Mona Lisa Address: Museum de Louvre Department: Accounts Details of employee 2 Employee number: 8 Name: Ubanish Lahari Address: Anfield Department: Research
71 | P a g e

Main Menu 1. Accepting employee details 2. Accepting manager details 3. Display employee details 4. Display manager details 5. Exit Enter your choice: 4 Enter manager code (emp. no of manager) for displaying details: 5 Details of manager 1 Employee no. : 5 Name: Brendan Rodgers Address: Liverpool Department: HR No. of employees working under him/her: 3 Main Menu 1. Accepting employee details 2. Accepting manager details 3. Display employee details 4. Display manager details 5. Exit Enter your choice: 5 Press any key to exit.

72 | P a g e

EXP. NO. 11 DATE: 2-8-12 MULTILEVEL INHERITANCE AIM: To create the annual report of a college using multilevel inheritance. CODE: #include<iostream.h> #include<conio.h> #include<stdio.h> const int LEN=80; class Person { char name[LEN]; int age; public: void readperson(); void displayperson() { cout<<"Name: "; cout.write(name, LEN); cout<<"\nAge: "<<age<<endl; } };
73 | P a g e

void Person::readperson() { for(int i=0;i<LEN;i++) name[i]=' '; cout<<"Enter name of the person: "; gets(name); cout<<"Enter age: "; cin>>age; } class Student:public Person { int rollno; float average; public: void readstudent() { readperson(); cout<<"Enter roll number: "; cin>>rollno; cout<<"Enter average marks: "; cin>>average; } void disp_rollno() { cout<<"Roll no: "<<rollno<<endl; } float getaverage() {
74 | P a g e

return average; } }; class GradStudent:public Student { char subject[LEN]; char working; public: void readit(); void displaysubject() { cout<<"Subject: "; cout.write(subject, LEN); } char workstatus() { return working; } }; void GradStudent::readit() { readstudent(); for(int i=0;i<LEN;i++) subject[i]=' '; cout<<"Enter main subject: "; gets(subject); cout<<"Working? (Y/N): ";
75 | P a g e

cin>>working; } int main() { clrscr(); const int size=5; GradStudent grad[size]; int year, num_working=0, non_working=0, div1=0, total=0, number; float topscore=0, score, wperc, nwperc; cout<<"Enter year: "; cin>>year; for(int i=0; i<size; i++) { cout<<"\nEnter details for graduate "<<i+1<<endl; grad[i].readit(); total++; if(grad[i].workstatus()=='Y') num_working++; else non_working++; score=grad[i].getaverage(); if(score>topscore) { topscore=score; number=i; } if(score>=60.0) div1++; }
76 | P a g e

clrscr(); i=number; cout<<"\n"<<"\t\tReport for the year "<<year<<endl; cout<<"-------------------------------------------------------------------------\n"; cout<<"Working graduates: "<<num_working<<endl; cout<<"Non-working graduates: "<<non_working<<endl; cout<<"\nDetails of the Top Scorer\n"; grad[i].displayperson(); grad[i].displaysubject(); nwperc=((float)non_working/(float)total)*100; wperc=((float)div1/(float)total)*100; cout<<"\nAverage marks: "<<grad[i].getaverage()<<endl; cout<<endl<<nwperc<<"% of the graduates this year are non-working and "<<wperc<<"% are first divisioners!\n"; getch(); return 0; } SAMPLE OUTPUT FOR THIS PROGRAM Enter year: 2012 Enter details for graduate 1 Enter name of the person: Mark Zuckerberg Enter age: 20
77 | P a g e

Enter roll number: 3 Enter average marks: 98 Enter main subject: Computers Working? (Y/N): Y Enter details for graduate 2 Enter name of the person: Eduardo Saverin Enter age: 22 Enter roll number: 12 Enter average marks: 845 Enter main subject: History Working? (Y/N): N Enter details for graduate 3 Enter name of the person: Dustin Moskovitz Enter age: 20 Enter roll number: 13 Enter average marks: 65 Enter main subject: Mech Working? (Y/N): N Enter details for graduate 4 Enter name of the person: Bill Gates Enter age: 22 Enter roll number: 4 Enter average marks: 94 Enter main subject: Arts Working? (Y/N): N
78 | P a g e

Enter details for graduate 5 Enter name of the person: Chuck Norris Enter age: 23 Enter roll number: 18 Enter average marks: 83 Enter main subject: English Working? (Y/N): Y Report for the year 2012 ---------------------------------------------------------------Working graduates: 2 Non-working graduates: 3 Details of the Top Scorer Name: Mark Zuckerberg Age: 20 Subject: Computers Average marks: 98 60% of the graduates this year are non-working and 100% are first divisioners!

79 | P a g e

EXP. NO. 12 DATE: 20-7-12 MULTIPLE INHERITANCE AIM: To maintain a database of students using multiple inheritance. CODE: #include<iostream.h> #include<conio.h> #include<stdio.h> #include<ctype.h> #include<process.h> int n, i, j; class person { char name[100]; int age; public: void readdata() { cout<<"Enter person's name: "; gets(name); cout<<"Enter person's age: "; cin>>age; cout<<endl;
80 | P a g e

} void dispdata() { cout<<"Name: "; puts(name); cout<<"Age: "<<age<<endl; } }; class subject { char subject[50]; public: void readsubject() { cout<<"Enter subject: "; gets(subject); cout<<endl; } void displaysubject() { cout<<"Subject: "; puts(subject); } }; class student:person, subject { int roll, mark; char grade;
81 | P a g e

public: void getdata() { readdata(); readsubject(); cout<<"Enter student's roll no.: "; cin>>roll; cout<<"Enter student's mark: "; cin>>mark; cout<<endl; computegrade(); } void computegrade() { if(mark<=200) grade='D'; else if ((mark>200)&&(mark<=240)) grade='C'; else if ((mark>240)&&(mark<=320)) grade='B'; else if(mark>320) grade='A'; } void showdata() { dispdata(); displaysubject(); cout<<"Mark: "<<mark<<endl; cout<<"Grade: "<<grade<<endl;
82 | P a g e

cout<<endl; } } e[100]; void menu() { p: clrscr(); cout<<"The multiple inheritance program!\n\n"; cout<<"\nMain Menu\n"; cout<<"1. Enter details\n"; cout<<"2. Display details\n"; cout<<"3. Exit\n"; cout<<"Enter your choice: "; int ch; cin>>ch; switch(ch) { case 1: { cout<<"\nAccepting details\n\n"; cout<<"How many students? : "; cin>>n; cout<<endl; for(i=1;i<=n;i++) { cout<<\nEnter details of student <<i<<endl; e[i].getdata(); }
83 | P a g e

} case 2: { cout<<"\nDisplaying details\n\n"; for(i=1;i<=n;i++) { cout<<"Details of student "<<i<<endl; e[i].showdata(); } getch(); goto p; } case 3: { cout<<"Press any key to exit."; getch(); exit(0); } default: goto p; } } void main() { clrscr(); menu();
84 | P a g e

cout<<"Details saved!\n"; getch(); goto p;

getch(); } SAMPLE OUTPUT FOR THIS PROGRAM Main Menu 1. Enter details 2. Display details 3. Exit Enter your choice: 1 Accepting details How many students? : 2 Enter Enter Enter Enter Enter Enter Enter Enter Enter Enter Enter Enter details of student 1 persons name: Bruno Mars persons age: 16 subject: English students roll no. : 12 students mark: 265 details of student 2 persons name: Katy Perry persons age: 17 subject: Math students roll no. : 16 students mark: 350
85 | P a g e

Details saved! Main Menu 1. Enter details 2. Display details 3. Exit Enter your choice: 2 Displaying details Details of student 1 Name: Bruno Mars Age: 16 Subject: English Mark: 265 Grade: B Details of student 2 Name: Katy Perry Age: 17 Subject: Math Mark: 350 Grade: A Main Menu 1. Enter details 2. Display details 3. Exit Enter your choice: 3
86 | P a g e

Press any key to exit.

87 | P a g e

EXP. NO. 13 DATE: 21-6-12 CONSTRUCTORS AND DESTRUCTORS AIM: To maintain the database of a bookshop with implementation of constructors and destructors. CODE: #include<iostream.h> #include<conio.h> #include<ctype.h> #include<string.h> #include<stdio.h> #include<process.h> int n, i; class stocks { char author[100]; char title[100]; long price; char publisher[100]; int stock; public: stocks() { price=0;
88 | P a g e

stock=0; } stocks(int &r) { stock=r; } void getdata() { cout<<"\nEnter title: "; gets(title); cout<<"\nEnter author: "; gets(author); cout<<"\nEnter publisher: "; gets(publisher); cout<<"\nEnter cost: "; cin>>price; cout<<"\nEnter stock: "; cin>>stock; cout<<endl; } void calculate(int); int check(char a[], char t[]) { int flag=0; if((strcmp(a, author)==0)&&(strcmp(t, title)==0)) flag=1; return flag; } void display();
89 | P a g e

} e[100]; void stocks::calculate(int copies) { char ans; int fla=1, sto=0, st=0; if(copies>stock) { cout<<"Sorry! Not enough stock!\n\n"; while(fla) { cout<<"Do you want to purchase "<<stock<<" copies?\n"; cin>>ans; if(toupper(ans)=='Y') { cout<<"\nPurchased!\n"; stocks s1(sto); stock=0; break; } else { cout<<"\nThanks for visiting! Come back later :)\n"; cout<<"Press any key to exit."; getch(); exit(0); } } }
90 | P a g e

else { cout<<"\nBook purchased!\n"; st=stock-copies; stocks s2(st); stock=st; } } void stocks::display() { cout<<"Title: "; puts(title); cout<<"Author: "; puts(author); cout<<"Publisher: "; puts(publisher); cout<<"Cost: "<<price<<endl; cout<<"Stock: "<<stock<<endl; } void menu() { p: clrscr(); cout<<"\nMain Menu\n"; cout<<"1. Adding books to database\n"; cout<<"2. Purchasing book(s)\n"; cout<<"3. Exit\n";
91 | P a g e

cout<<"What would you like to do? : "; int ch; cin>>ch; switch(ch) { case 1: { cout<<"\nHow many books are you entering? : "; cin>>n; for(i=1;i<=n;i++) { cout<<"\nEnter details of book "<<i; e[i].getdata(); } cout<<"\nBooks added!\n"; getch(); goto p; } case 2: { int noofcopies, pos; char au[100], ti[100]; q: cout<<"Enter the title you are looking for: "; gets(ti); cout<<"\nEnter the author you are looking for: "; gets(au); int fla=0; for(i=1;i<=n;i++)
92 | P a g e

{ fla=e[i].check(au,ti); if(fla==1) { pos=i; break; } } if(fla==0) { cout<<"Sorry! We don't have such a book!\n"; cout<<"Enter again!\n"; goto q; } else { cout<<"\nHere are the details of your book! \n\n"; e[pos].display(); cout<<"How many copies do you need? : "; cin>>noofcopies; cout<<endl; e[pos].calculate(noofcopies); } getch(); goto p; } case 3: { cout<<"\nThanks for coming! Press any key to exit.";
93 | P a g e

getch(); exit(0); } default: { cout<<"\nWrong option! Enter again!\n"; getch(); goto p; } } } void main() { clrscr(); menu(); getch(); } SAMPLE OUTPUT FOR THIS PROGRAM Main Menu 1. Adding books to database 2. Purchasing book(s) 3. Exit What would you like to do? : 1 How many books are you entering? : 2
94 | P a g e

Enter details of book 1 Enter title: Champions League Dreams Enter author: Rafa Benitez Enter publisher: Pan Macmillan Enter cost: 295 Enter stock: 5 Enter details of book 2 Enter title: Steven Gerrard: My Liverpool Story Enter author: Steven Gerrard Enter publisher: Zebra Press Enter cost: 595 Enter stock: 4 Books added! Main Menu 1. Adding books to database 2. Purchasing book(s) 3. Exit What would you like to do? : 2 Enter the title you are looking for: Champions League Dreams
95 | P a g e

Enter the author you are looking for: Rafa Benitez Here are the details of your book! Title: Champions League Dreams Author: Rafa Benitez Publisher: Pan Macmillan Cost: 295 Stock: 5 How many copies do you need? : 7 Sorry! Not enough stock! Do you want to purchase 5 copies? : Y Purchased! Main Menu 1. Adding books to database 2. Purchasing book(s) 3. Exit What would you like to do? : 3 Thanks for coming! Press any key to exit..

96 | P a g e

EXP. NO. 14 DATE: 12-7-12 BANK PROGRAM (CLASS) AIM: To create a program to maintain the records of a bank with the help of a class. CODE: #include<iostream.h> #include<conio.h> #include<ctype.h> #include<stdio.h> #include<process.h> int i, n; class bank { char name[100]; long acc_no; char type; long balance; public: int check(int); void initialise(); void deposit(float amt); void withdraw(float wit); void dispdata();
97 | P a g e

} c[50]; void bank::initialise() { cout<<"Enter name of account holder: "; gets(name); cout<<"Enter account no. : "; cin>>acc_no; cout<<"Enter account type(S/C): "; cin>>type; type=toupper(type); cout<<"Enter balance: "; cin>>balance; } void bank::deposit(float amt) { clrscr(); balance+=amt; cout<<"\nAmount deposited! \n"; cout<<"Balance: "<<balance<<endl; } void bank::withdraw(float wit) { char ans; if((balance-wit)<1000) {
98 | P a g e

cout<<"\nMinimum balance for maintaining account is Rs. 1000.\n"; cout<<"You can withdraw maximum of "<<balance-1000<<" rupees.\n"; cout<<"Do you want to withdraw "<<balance-1000<<" rupees? (Y/N): "; cin>>ans; if(ans=='y'||ans=='Y') { balance=1000; cout<<"\nAmount withdrawn!\n"; } } else { balance-=wit; cout<<"\nAmount withdrawn!\n"; cout<<"Balance: "<<balance<<endl; } } void bank::dispdata() { cout<<"\nAccount number: "<<acc_no<<endl; cout<<"Account holder's name: "; puts(name); cout<<"Account type: "<<type<<endl; cout<<"Balance: "<<balance<<"\n\n"; }
99 | P a g e

int bank::check(int aceno) { int flag=0; if(aceno==acc_no) flag=1; return flag; } void menu() { int ch; p: clrscr(); cout<<"\nMain Menu\n"; cout<<"1. Initialise accounts\n"; cout<<"2. Deposit money in an account\n"; cout<<"3. Withdraw money from an account\n"; cout<<"4. Display account details\n"; cout<<"5. Exit\n"; cout<<"Enter your choice: "; cin>>ch; switch(ch) { case 1: { cout<<"\nHow many accounts are you initialising? : "; cin>>n; for(i=1;i<=n;i++)
100 | P a g e

{ cout<<"\nEnter details for account holder "<<i<<endl; c[i].initialise();

} cout<<"\nData saved!\n"; getch(); goto p;

} case 2: { long int acno; float amt; q: int flag=0; cout<<"\nEnter account number: "; cin>>acno; for(i=1;i<=n;i++) { flag=c[i].check(acno); if(flag==1) { cout<<"\nEnter the amount to be deposited: "; cin>>amt; c[i].deposit(amt); break; } else flag=0; }
101 | P a g e

if(flag==0) { cout<<"\nNo such account number exists!\n"; int count=1; while(count==1) { char ans; cout<<"\nDo you want to re-enter account number? (Y/N): "; cin>>ans; if(ans=='y'||ans=='Y') { getch(); goto q; } else if(ans=='n'||ans=='N') { getch(); goto p; } } } getch(); goto p; } case 3: { long int ano; float tot;
102 | P a g e

int flag=0; r: cout<<"\nEnter account number: "; cin>>ano; for(i=1;i<=n;i++) { flag=c[i].check(ano); if(flag==1) { cout<<"\nEnter the amount to be withdrawn\n"; cin>>tot; c[i].withdraw(tot); break; } else flag=0; } if(flag==0) { char ans; cout<<"\nNo such account number exists!\n"; int count=1; while(count==1) { cout<<"\nDo you want to re-enter account number? (Y/N): "; cin>>ans; if(ans=='y'||ans=='Y') { getch();
103 | P a g e

goto r; } else if(ans=='n'||ans=='N') { getch(); goto p; } } getch(); goto p; } case 4: { int no, flag=0; s: cout<<"\nEnter the account number whose details you wish to see: "; cin>>no; for(i=1;i<=n;i++) { flag=c[i].check(no); if(flag==1) { c[i].dispdata(); break; } else flag=0; }
104 | P a g e

if(flag==0) { char ans; cout<<"\nNo such account number exists!\n"; int count=1; while(count==1) { cout<<"\nDo you want to re-enter account number? (Y/N): "; cin>>ans; if(ans=='y'||ans=='Y') { getch(); goto s; } else if(ans=='n'||ans=='N') { getch(); goto p; } } } getch(); goto p; } case 5: { cout<<"\nPress any key to exit.\n"; getch();
105 | P a g e

exit(0); } default: { cout<<"\nWrong option! Enter again!\n"; getch(); goto p; }

} }

void main() { clrscr(); menu(); getch(); } SAMPLE OUTPUT FOR THIS PROGRAM Main Menu 1. Initialise accounts 2. Deposit money in an account 3. Withdraw money from an account 4. Display account details 5. Exit Enter your choice: 1 How many accounts are you initializing? : 2
106 | P a g e

Enter Enter Enter Enter Enter Enter Enter Enter Enter Enter

details for account holder 1 name of account holder: Bradley Cooper account no. : 69 account type (S/C) : S balance: 20000 details for account holder 2 name of account holder: Heath Ledger account no. : 10 account type (S/C) : C balance: 35000

Data saved! Main Menu 1. Initialise accounts 2. Deposit money in an account 3. Withdraw money from an account 4. Display account details 5. Exit Enter your choice: 2 Enter account number: 69 Enter the amount to be deposited: 15000 Amount deposited! Balance: 35000
107 | P a g e

Main Menu 1. Initialise accounts 2. Deposit money in an account 3. Withdraw money from an account 4. Display account details 5. Exit Enter your choice: 3 Enter account number: 10 Enter the amount to be withdrawn: 5000 Amount withdrawn! Balance: 30000 Main Menu 1. Initialise accounts 2. Deposit money in an account 3. Withdraw money from an account 4. Display account details 5. Exit Enter your choice: 4 Enter the account number whose details you wish to see: 69 Account number: 69 Account holders name: Bradley Cooper Account type: S Balance: 35000
108 | P a g e

Main Menu 1. Initialise accounts 2. Deposit money in an account 3. Withdraw money from an account 4. Display account details 5. Exit Enter your choice: 5 Press any key to exit.

109 | P a g e

EXP. NO. 15 DATE: 5-7-12 EMPLOYEE PROGRAM (CLASS) AIM: To create a program to maintain the records of employees in a company with the help of a class. CODE: #include<iostream.h> #include<ctype.h> #include<conio.h> #include<stdio.h> #include<process.h> int i, n, sno=1; class employee { char name[100]; long reg_no; float salary; char designation[100]; public: int check(long); void getdata(); void displist(int,int); void disprec(); }e[100];
110 | P a g e

void employee::getdata() { cout<<"Enter employee name: "; gets(name); cout<<"Enter registration no.: "; cin>>reg_no; cout<<"Enter salary: "; cin>>salary; cout<<"Enter designation: "; gets(designation); cout<<endl; } void employee::disprec() { cout<<"\nEmployee name: "; puts(name); cout<<"Registration no. : "<<reg_no<<endl; cout<<"Salary: "<<salary<<endl; cout<<"Designation: "; puts(designation); cout<<endl; } void employee::displist(int cord, int sno) { gotoxy(1,cord); cout<<sno; gotoxy(5,cord);
111 | P a g e

puts(name); gotoxy(21,cord); cout<<reg_no; gotoxy(41,cord); cout<<salary; gotoxy(49,cord); puts(designation); cout<<"\n\n";

int employee::check(long aceno) { int fla=0; if(aceno==reg_no) fla=1; else fla=0; return fla; } void add(int po) { if(po<=n) { for(i=n;i>=po;i--) e[i+1]=e[i]; e[po].getdata(); } if(po==n+1) e[po].getdata();
112 | P a g e

n++; } void del(int post) { for(i=post;i<n;i++) e[i]=e[i+1]; n--; } void menu() { p: clrscr(); cout<<"\nMain Menu\n"; cout<<"1. Accepting employee details\n"; cout<<"2. Displaying particular employee record\n"; cout<<"3. Displaying entire employee database\n"; cout<<"4. Adding employee to database\n"; cout<<"5. Deleting employee from the database\n"; cout<<"6. Exit\n"; cout<<"Enter your choice: "; int ch; cin>>ch; switch(ch) { case 1: { cout<<"\nHow many employees? : ";
113 | P a g e

} case 2: { long accno; q: cout<<"\nEnter employee number to display details: "; cin>>accno; int flag=0; for(i=1;i<=n;i++) { flag=e[i].check(accno); if(flag==1) { e[i].disprec(); break; } else flag=0; } if(flag==0) { cout<<"\nNo such employee number exists!\n";
114 | P a g e

cin>>n; for(i=1;i<=n;i++) { cout<<"\nEnter details of employee "<<i<<endl; e[i].getdata(); } getch(); goto p;

int cc=1; char ans; while(cc) { cout<<"\nDo you want to re-enter? (Y/N) : "; cin>>ans; if(toupper(ans)=='Y') goto q; else if(toupper(ans)=='N') goto p; } } getch(); goto p; } case 3: { clrscr(); cout<<"\nThe entered employee details are: \n\n"; gotoxy(1,4); cout<<"Sno"; gotoxy(5,4); cout<<"Employee name"; gotoxy(21,4); cout<<"Registration no."; gotoxy(41,4); cout<<"Salary"; gotoxy(49,4); cout<<"Designation"<<"\n\n";
115 | P a g e

int coord=6, so=1; for(i=1;i<=n;i++) { e[i].displist(coord,so); coord+=2; so+=1; } getch(); goto p; } case 4: { cout<<"\nThe details of the entered employees are:\n\n"; for(i=1;i<=n;i++) { cout<<i<<"."<<"\n"; e[i].disprec(); } int pos; u: cout<<"\nIn which position do you want to add the record? : "; cin>>pos; if(pos>n+1) { cout<<"Position "<<n+1<<" is vacant!\n\n"; int cc=1; char ans; while(cc)
116 | P a g e

{ cout<<"Do you want to add the employee over there? (Y/N) : "; cin>>ans; if(toupper(ans)=='Y') { getch(); goto u; } else if(toupper(ans)=='N') { getch(); goto p; } } } cout<<endl; add(pos); cout<<"\nEmployee added!\n"; getch(); goto p; } case 5: { t: cout<<"\nEnter employee number for deletion: "; long ano; cin>>ano; int flag=0, pos=0;
117 | P a g e

for(i=1;i<=n;i++) { flag=e[i].check(ano); if(flag==1) { pos=i; break; } } if(flag==0) { cout<<"\nNo such employee number exists!\n"; int cc=1; char ans; while(cc) { cout<<"\nDo you want to re-enter? (Y/N) : "; cin>>ans; if(toupper(ans)=='Y') goto t; else if(toupper(ans)=='N') goto p; } } del(pos); cout<<"\nEmployee deleted!\n"; getch(); goto p; }
118 | P a g e

case 6: { cout<<"\nPress any key to exit."; getch(); exit(0); } default: { cout<<"\nWrong option! Enter again!"; getch(); goto p; } } }

void main() { clrscr(); menu(); getch(); } SAMPLE OUTPUT FOR THIS PROGRAM Main Menu 1. Accepting employee details 2. Displaying particular employee record 3. Displaying entire employee database 4. Adding employee to database
119 | P a g e

5. Deleting employee from database 6. Exit Enter your choice: 1 How many employees? : 2 Enter Enter Enter Enter Enter Enter Enter Enter Enter Enter details of employee 1 employee name: Michael Owen registration no. : 10 salary: 8000 designation: Secretary details of employee 2 employee name: Robin van Persie registration no. : 20 salary: 35000 designation: Manager

Details saved! Main Menu 1. Accepting employee details 2. Displaying particular employee record 3. Displaying entire employee database 4. Adding employee to database 5. Deleting employee from database 6. Exit Enter your choice: 2
120 | P a g e

Enter employee no. to display details: 20 Employee name: Robin van Persie Registration no. : 20 Salary: 35000 Designation: Manager Main Menu 1. Accepting employee details 2. Displaying particular employee record 3. Displaying entire employee database 4. Adding employee to database 5. Deleting employee from database 6. Exit Enter your choice: 4 The details of the entered employees are: 1. Employee name: Michael Owen Registration no. : 10 Salary: 8000 Designation: Secretary 2. Employee name: Robin van Persie Registration no. : 20 Salary: 35000 Designation: Manager
121 | P a g e

In which position do you want to add the record: 3 Enter employee name: Jesus Fernandes Saez Enter registration no. : 30 Enter salary: 30000 Enter designation: Sales Executive Employee added! Main Menu 1. Accepting employee details 2. Displaying particular employee record 3. Displaying entire employee database 4. Adding employee to database 5. Deleting employee from database 6. Exit Enter your choice: 3 The entered employee details are: Sno Employee name 1 2 3 Michael Owen Robin van Persie Jesus Fernandes Saez Reg.no Salary Designation 10 20 30 8000 35000 30000 Secretary Manager Sales Executive
122 | P a g e

Main Menu 1. Accepting employee details 2. Displaying particular employee record 3. Displaying entire employee database 4. Adding employee to database 5. Deleting employee from database 6. Exit Enter your choice: 5 Enter employee number for deletion: 20 Employee deleted! Main Menu 1. Accepting employee details 2. Displaying particular employee record 3. Displaying entire employee database 4. Adding employee to database 5. Deleting employee from database 6. Exit Enter your choice: 6 Press any key to exit.

123 | P a g e

EXP. NO. 16 DATE: 18-10-12 CALCULATION OF MEAN, MEDIAN, MODE AND STANDARD DEVIATION AIM: To create a program to calculate the mean, median, mode and standard deviation of a set of numbers. CODE: #include<iostream.h> #include<conio.h> #include<math.h> #include<process.h> int a[100], n; void mean() { int sum=0,i; for(i=0;i<n;i++) { sum=sum+a[i]; } cout<<"\nMean: "<<(float)(sum/n); getch(); } void median()
124 | P a g e

{ cout<<"\nMedian: "; if((n-1)%2==0) { cout<<a[n/2]; } else { cout<<(a[n/2]+a[(n+2)/2])/2; } getch(); } void mode() { int b[100][2], c=0, t, k=0, i, j; c=a[0]; for(i=0;i<100;i++) { b[i][0]=0; } b[0][1]=a[0]; for(i=0;i<n;i++) { if(a[i]==c) { b[k][0]++; } else
125 | P a g e

{ c=a[i]; k++; b[k][0]++; b[k][1]=a[i]; } } for(i=0;i<=k;i++) { for(j=0;j<k;j++) { if(b[j][0]<b[j+1][0]) { int t=b[j][0]; b[j][0]=b[j+1][0]; b[j+1][0]=t; t=b[j][1]; b[j][1]=b[j+1][1]; b[j+1][1]=t; } } } c=b[0][0]; for(i=0;i<=k;i++) { if(b[i][0]==c) { cout<<"\nMode: "<<b[i][1]<<endl; }
126 | P a g e

else break; } getch();

void stddev() { int sum=0, i; float x, dev=0, z=0; for(i=0;i<n;i++) { sum=sum+a[i]; } x=sum/n; for(i=0;i<n;i++) { dev=dev+pow((x-a[i]),2); } z=dev/n; cout<<"\nStandard deviation: "<<(float)(sqrt(z)); getch(); } void main() { clrscr(); int ch, i, j; cout<<"How many numbers? : "; cin>>n;
127 | P a g e

cout<<"\nEnter the numbers\n"; for(i=0;i<n;i++) cin>>a[i]; //sorting the array for(i=0;i<n;i++) { for(j=0;j<n-1;j++) { if(a[j]>a[j+1]) { int t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } p: cout<<"\n\nMain Menu\n"; cout<<"1. Mean\n"; cout<<"2. Median\n"; cout<<"3. Mode\n"; cout<<"4. Standard Deviation\n"; cout<<"5. Exit\n"; cout<<"Enter your choice: "; cin>>ch; switch(ch) { case 1: mean(); goto p;
128 | P a g e

case 2: median(); goto p; case 3: mode(); goto p; case 4: stddev(); goto p; case 5: cout<<"\nPress any key to exit."; getch(); exit(0); default: cout<<"\nWrong option! Enter again!"; goto p; } //end of switch } //end of main SAMPLE OUTPUT FOR THIS PROGRAM How many numbers? : 10 Enter the numbers 12 22 20 36 22 19 43 40 40 30 Main Menu 1. Mean 2. Median 3. Mode 4. Standard Deviation 5. Exit Enter your choice: 1
129 | P a g e

Mean: 28 Main Menu 1. Mean 2. Median 3. Mode 4. Standard Deviation 5. Exit Enter your choice: 2 Median: 33 Main Menu 1. Mean 2. Median 3. Mode 4. Standard Deviation 5. Exit Enter your choice: 3 Mode: 22 Mode:40 Main Menu 1. Mean 2. Median 3. Mode 4. Standard Deviation
130 | P a g e

5. Exit Enter your choice: 4 Standard deviation: 10.26645 Main Menu 1. Mean 2. Median 3. Mode 4. Standard Deviation 5. Exit Enter your choice: 5 Press any key to exit.

131 | P a g e

EXP. NO. 17 DATE: 11-11-12 SALESMAN PROGRAM (POINTERS) AIM: To find the salesman with the maximum sales from a group of salesmen with the help of pointers. CODE: #include<iostream.h> #include<conio.h> #include<string.h> class salesman { char name[11]; float q1_sal, q2_sal, q3_sal, q4_sal, tot_sal; public: salesman() { strcpy(name, " "); q1_sal=q2_sal=q3_sal=q4_sal=0; } void getdata(char *s, float i, float j, float k, float l) { strcpy(name, s); q1_sal=i; q2_sal=j;
132 | P a g e

q3_sal=k; q4_sal=l; } void calc_tot() { tot_sal=q1_sal+q2_sal+q3_sal+q4_sal; } char *get_name() { return name; } float get_q1() { return q1_sal; } float get_q2() { return q2_sal; } float get_q3() { return q3_sal; } float get_q4() { return q4_sal; } float get_tot() {
133 | P a g e

return tot_sal; } salesman *max_sal(salesman *S) { if(!S) S=this; else { float f1, f2; f1=S->get_tot(); f2=this->get_tot(); if(f1<f2) S=this; } return S; } }; salesman *sp; void printit(salesman *sp) { cout<<"\nSalesman with maximum sales: \n"; cout<<"\nName: "; char *ss=sp->get_name(); cout.write(ss,11); cout<<endl; cout<<"\nTotal sales: "<<sp->get_tot()<<endl; }
134 | P a g e

void main() { clrscr(); //Enter whatever names you want in the correct places salesman Torres, Cazorla, Aguero, Ganso, Caroline; float q1, q2, q3, q4; sp=&Torres; cout<<"\nEnter sales in four quarters for Torres: \n"; cin>>q1>>q2>>q3>>q4; Torres.getdata("Torres",q1,q2,q3,q4); Torres.calc_tot(); sp=Torres.max_sal(sp); cout<<"\nEnter sales in four quarters for Cazorla: \n"; cin>>q1>>q2>>q3>>q4; Cazorla.getdata("Cazorla",q1,q2,q3,q4); Cazorla.calc_tot(); sp=Cazorla.max_sal(sp); cout<<"\nEnter sales in four quarters for Aguero: \n"; cin>>q1>>q2>>q3>>q4; Aguero.getdata("Aguero",q1,q2,q3,q4); Aguero.calc_tot(); sp=Aguero.max_sal(sp); cout<<"\nEnter sales in four quarters for Ganso: \n"; cin>>q1>>q2>>q3>>q4; Ganso.getdata("Ganso",q1,q2,q3,q4); Ganso.calc_tot(); sp=Ganso.max_sal(sp); cout<<"\nEnter sales in four quarters for Caroline: \n";
135 | P a g e

cin>>q1>>q2>>q3>>q4; Caroline.getdata("Caroline",q1,q2,q3,q4); Caroline.calc_tot(); sp=Caroline.max_sal(sp); printit(sp); getch(); } SAMPLE OUTPUT FOR THIS PROGRAM Enter sales in four quarters for Torres: 520 400 320 410 Enter sales in four quarters for Cazorla: 250 350 400 260 Enter sales in four quarters for Aguero: 260 350 400 410 Enter sales in four quarters for Ganso:
136 | P a g e

260 360 450 240 Enter sales in four quarters for Caroline: 240 500 120 300 Salesman with maximum sales: Name: Torres Total sales: 1650

137 | P a g e

EXP. NO. 18 DATE: 27-9-12 TEXT FILE AIM: To use file handling to create a poem in the form of a text file, and perform various operations on it. CODE: #include<fstream.h> #include<conio.h> #include<stdio.h> #include<string.h> #include<ctype.h> #include<process.h> char a[500]; void getdata() { ofstream f; f.open("recpr13.txt",ios::out); cin.getline(a,500,'$'); f<<a; f.close(); cout<<"\nPoem saved!\n"; } void display()
138 | P a g e

{ ifstream f; f.open("recpr13.txt",ios::in); f>>a; f.seekg(0); char ch='\0'; while(f.get(ch)) cout<<ch; f.close(); } int spaces() { ifstream f; f.open("recpr13.txt",ios::in); f>>a; f.seekg(0); int sp=0; char ch; while(f.get(ch)) { if(ch==' ') sp++; } return sp; } int lines() {
139 | P a g e

ifstream f; f.open("recpr13.txt",ios::in); f>>a; f.seekg(0); int li=0; char ch; while(f.get(ch)) { if(ch=='\n') li++; } return li; } int the() { ifstream f; f.open("recpr13.txt",ios::in); f>>a; f.seekg(0); int th=0; char word[5]; while(f>>word) { if((strcmp(word,"the")==0)||(strcmp(word,"The")==0)) th++; } return th; }
140 | P a g e

int sentences() { ifstream f; f.open("recpr13.txt",ios::in); f>>a; f.seekg(0); int se=0; char ch; while(f.get(ch)) { if(ch=='.') { f.get(ch); if(isalpha(ch)||isspace(ch)||ch=='\n') se++; } } return se; } void menu() { j: clrscr(); cout<<"\nText File: Main Menu\n"; cout<<"1. Accept a poem\n"; cout<<"2. Count the no. of spaces in the poem\n"; cout<<"3. Count the no. of lines in the poem\n";
141 | P a g e

cout<<"4. Count the no. of sentences in the poem\n"; cout<<"5. Count the no. of occurences of 'the' in the poem\n"; cout<<"6. Exit\n"; cout<<"Enter your choice: "; int ch; cin>>ch; switch(ch) { case 1: { clrscr(); cout<<"Enter your story!\n"; cout<<"Use '$' in the next line to end the poem.\n\n"; getdata(); cout<<"\nThe entered poem is\n\n"; display(); getch(); goto j; } case 2: { clrscr(); int sp=0; cout<<"\nThe entered story is\n\n"; display(); cout<<endl; sp=spaces(); cout<<"\nThe no. of spaces in the story is: "<<sp<<endl;
142 | P a g e

getch(); goto j; } case 3: { clrscr(); int l=0; cout<<"\nThe entered poem is\n\n"; display(); cout<<endl; l=lines(); cout<<"\nThe no. of lines in the poemis: "<<l<<endl; getch(); goto j; } case 4: { clrscr(); cout<<"\nThe entered poem is\n\n"; display(); cout<<endl; int se=0; se=sentences(); cout<<"\nThe no. of sentences in the poemis: "<<se<<endl; getch(); goto j; } case 5: {
143 | P a g e

clrscr(); cout<<"\nThe entered poem is\n\n"; display(); cout<<endl; int th=0; th=the(); cout<<"\nThe no. of occurences of 'the' is: "<<th<<endl; getch(); goto j; } case 6: { cout<<"\nPress any key to exit."; getch(); exit(0); } default: goto j; } } void main() { clrscr(); menu(); getch(); } SAMPLE OUTPUT FOR THIS PROGRAM
144 | P a g e

Text File: Main Menu 1. Accept a poem 2. Count the no. of spaces in the poem 3. Count the no. of lines in the poem 4. Count the no. of sentences in the poem 5. Count the no. of occurrences of the in the poem 6. Exit Enter your choice: 1 Enter your poem! Use $ in the next line to end the poem. I am just a little bit, Caught in the middle. Life is a maze, And love is a riddle. $ Poem saved! The entered poem is I am just a little bit, Caught in the middle. Life is a maze, And love is a riddle. Text File: Main Menu 1. Accept a poem
145 | P a g e

2. Count the no. of spaces in the poem 3. Count the no. of lines in the poem 4. Count the no. of sentences in the poem 5. Count the no. of occurrences of the in the poem 6. Exit Enter your choice: 2 The entered poem is I am just a little bit, Caught in the middle. Life is a maze, And love is a riddle. The no. of spaces in the poem is: 15 Text File: Main Menu 1. Accept a poem 2. Count the no. of spaces in the poem 3. Count the no. of lines in the poem 4. Count the no. of sentences in the poem 5. Count the no. of occurrences of the in the poem 6. Exit Enter your choice: 3 The entered poem is I am just a little bit, Caught in the middle.
146 | P a g e

Life is a maze, And love is a riddle. The no. of lines in the poem is: 4 Text File: Main Menu 1. Accept a poem 2. Count the no. of spaces in the poem 3. Count the no. of lines in the poem 4. Count the no. of sentences in the poem 5. Count the no. of occurrences of the in the poem 6. Exit Enter your choice: 4 The entered poem is I am just a little bit, Caught in the middle. Life is a maze, And love is a riddle. The no. of sentences in the poem is: 2 Text File: Main Menu 1. Accept a poem 2. Count the no. of spaces in the poem 3. Count the no. of lines in the poem 4. Count the no. of sentences in the poem 5. Count the no. of occurrences of the in the poem
147 | P a g e

6. Exit Enter your choice: 5 The entered poem is I am just a little bit, Caught in the middle. Life is a maze, And love is a riddle. The no. of occurrences of the are: 1 Text File: Main Menu 1. Accept a poem 2. Count the no. of spaces in the poem 3. Count the no. of lines in the poem 4. Count the no. of sentences in the poem 5. Count the no. of occurrences of the in the poem 6. Exit Enter your choice: 6 Press any key to exit.

148 | P a g e

EXP. NO. 19 DATE: 4-10-12 BINARY FILE AIM: To use file handling to maintain records of students in the form of a binary file. CODE: #include<fstream.h> #include<conio.h> #include<string.h> #include<stdio.h> #include<ctype.h> #include<process.h> int n, i; class stud { char name[100]; int clas, mark, rollno; public: void getdata() { cout<<"\nEnter name: "; gets(name); cout<<"Enter class: "; cin>>clas;
149 | P a g e

cout<<"Enter roll no.: "; cin>>rollno; cout<<"Enter mark: "; cin>>mark; } void putdata() { cout<<"\nName: "; puts(name); cout<<"Class: "<<clas<<endl; cout<<"Roll no.: "<<rollno<<endl; cout<<"Mark: "<<mark<<endl; } void modify() { char nm[100]; int cls, mrk; putdata(); cout<<"\nEnter new name (enter '.' to retain old one) : "; gets(nm); if(strcmp(nm,".")!=0) strcpy(name,nm); cout<<"\nEnter new class (enter -1 to retain old one) : "; cin>>cls; if(cls!= -1) clas=cls; cout<<"\nEnter new mark (enter -1 to retain old one) : "; cin>>mrk; if(mrk!= -1)
150 | P a g e

mark=mrk; } int retno() { return rollno; } } e[100], b, c; void menu() { q: clrscr(); cout<<"\nBinary File: Main Menu\n"; cout<<"1. Accept students' data\n"; cout<<"2. Insert a student's data\n"; cout<<"3. Delete a student's data\n"; cout<<"4. Modify a student's data\n"; cout<<"5. Exit\n"; cout<<"Enter your choice: "; int ch; cin>>ch; switch(ch) { case 1: { cout<<"\nHow many students? : "; cin>>n; ofstream f; f.open("cs.dat",ios::out);
151 | P a g e

for(i=1;i<=n;i++) { cout<<"\nEnter details of student "<<i<<endl; e[i].getdata(); f.write((char*)&e[i],sizeof(e[i])); } f.close(); cout<<"\nDetails saved!"; getch(); goto q; } case 2: { int pos; cout<<"\nEnter position in which you want to enter the student: "; cin>>pos; ifstream g; ofstream h; h.open("temp.dat",ios::out|ios::app); g.seekg(0); g.open("cs.dat",ios::in); for(i=1;i<=n;i++) { g.read((char*)&e[i],sizeof(e[i])); h.write((char*)&e[i],sizeof(e[i])); } cout<<"\nEnter details of student to be inserted\n"; b.getdata();
152 | P a g e

h.write((char*)&b,sizeof(e[i])); for(i=pos;i<=n;i++) { g.read((char*)&e[i],sizeof(e[i])); h.write((char*)&e[i],sizeof(e[i])); } g.close(); h.close(); remove("cs.dat"); rename("temp.dat","cs.dat"); cout<<"\nHere are the contents of the file after insertion:\n"; ifstream fio; fio.open("cs.dat",ios::in); fio.seekg(0); while(fio.read((char*)&c,sizeof(c))) { c.putdata(); } fio.close(); getch(); goto q; } case 3: { int no; cout<<"\nEnter the roll no. of student for deletion: "; cin>>no; ifstream k;
153 | P a g e

k.open("cs.dat",ios::in); k.seekg(0); char ans='y'; ofstream o; o.open("temp1.dat",ios::out|ios::app); while(k.read((char*)&c,sizeof(c))) { if(c.retno()==no) { cout<<"\Are you sure you want to delete this record?(Y/N): "; cin>>ans; if(toupper(ans)=='N') o.write((char*)&c,sizeof(c)); } else o.write((char*)&c,sizeof(c)); } k.close(); o.close(); remove("cs.dat"); rename("temp1.dat","cs.dat"); cout<<"\nHere are the contents of the file after deletion:\n"; ifstream file; file.open("cs.dat",ios::out|ios::beg); while(file.read((char*)&b,sizeof(b))) { b.putdata(); }
154 | P a g e

} case 4: { int rno; cout<<"\nEnter roll no. of student for modification: "; cin>>rno; fstream gio; gio.open("cs.dat",ios::in|ios::out|ios::beg); int pos; while(!gio.eof()) { pos=gio.tellg(); gio.read((char*)&c,sizeof(c)); if(c.retno()==rno) { c.modify(); gio.seekg(pos); gio.write((char*)&c,sizeof(c)); break; } } gio.close(); cout<<"\nThe contents of the file after modification:\n"; ifstream m; m.open("cs.dat",ios::in|ios::beg); while(m.read((char*)&b,sizeof(b)))
155 | P a g e

file.close(); getch(); goto q;

{ b.putdata(); } getch(); goto q; } case 5: { cout<<"\nPress any key to exit."; getch(); exit(0); } default: goto q;

} }

void main() { clrscr(); menu(); getch(); } SAMPLE OUTPUT FOR THIS PROGRAM Binary File: Main Menu 1. Accept students data 2. Insert a students data 3. Delete a students data
156 | P a g e

4. Modify a students data 5. Exit Enter your choice: 1 How many students? : 2 Enter details of student 1 Enter Enter Enter Enter name: Ras al Ghul class: 10 roll no. : 13 mark: 78

Enter details of student 2 Enter Enter Enter Enter name: Bruce Wayne class: 12 roll no. : 4 mark: 89

Details saved! Binary File: Main Menu 1. Accept students data 2. Insert a students data 3. Delete a students data 4. Modify a students data 5. Exit Enter your choice: 2
157 | P a g e

Enter position in which you want to enter the student: 3 Enter details of student to be inserted Enter Enter Enter Enter name: Alfred Pennyworth class: 11 roll no. : 1 mark: 66

Here are the contents of the file after insertion: Name: Ras al Ghul Class: 10 Roll no. : 13 Mark: 78 Name: Bruce Wayne Class: 12 Roll no. : 4 Mark: 89 Name: Alfred Pennyworth Class: 11 Roll no. : 1 Mark: 66 Binary File: Main Menu 1. Accept students data
158 | P a g e

2. Insert a students data 3. Delete a students data 4. Modify a students data 5. Exit Enter your choice: 3 Enter the roll no. of student for deletion: 13 Are you sure you want to delete this record?(Y/N): Y Here are the contents of the file after deletion: Name: Bruce Wayne Class: 12 Roll no. : 4 Mark: 89 Name: Alfred Pennyworth Class: 11 Roll no. : 1 Mark: 66 Binary File: Main Menu 1. Accept students data 2. Insert a students data 3. Delete a students data 4. Modify a students data 5. Exit Enter your choice: 4
159 | P a g e

Enter roll no. of student for modification: 4 Name: Bruce Wayne Class: 12 Roll no. : 4 Mark: 89 Enter new name (enter . to retain old one) : . Enter new class (enter -1 to retain old one) : -1 Enter new mark (enter -1 to retain old one) : 93 The contents of the file after modification: Name: Bruce Wayne Class: 12 Roll no. : 4 Mark: 93 Name: Alfred Pennyworth Class: 11 Roll no. : 1 Mark: 66 Binary File: Main Menu 1. Accept students data 2. Insert a students data 3. Delete a students data
160 | P a g e

4. Modify a students data 5. Exit Enter your choice: 5 Press any key to exit.

161 | P a g e

EXP. NO. 20 DATE: 14-6-12 REPORT CARD GENERATION AIM: To generate the report card of a batch of students with the help of structures. CODE: #include<iostream.h> #include<conio.h> #include<stdio.h> #include<stdlib.h> #include<string.h> #include<process.h> int n, check[50], temp; char corr[50], cor[50]; struct student { char name[25]; long int rollno; int mark[5], rank, total, flag; } count[50], fail[50]; struct subject { char subjects[20];
162 | P a g e

} sub[5]; void getdata() { clrscr(); strcpy(sub[1].subjects, "English"); strcpy(sub[2].subjects, "CS"); strcpy(sub[3].subjects, "Maths"); strcpy(sub[4].subjects, "Physics"); strcpy(sub[5].subjects, "Chemistry"); cout<<"\n\tSTUDENT DETAILS\n"; cout<<"\nHow many students? : "; cin>>n; char *tp; for(int i=1;i<=n;i++) { count[i].total=0; cout<<"\nEnter details of student "<<i<<endl; cout<<"\nName: "; gets(count[i].name); cout<<"\nRoll no.: "; cin>>count[i].rollno; for(int j=1;j<=5;j++) { cout<<"\nMark in "<<sub[j].subjects<<": "; count[i].mark[j]=atoi(gets(tp)); cout<<endl; count[i].total+=count[i].mark[j]; }
163 | P a g e

cout<<"\n\n"; } clrscr(); int l=4; cout<<"\nThe entered details are: \n"; for(i=1;i<=n;i++) { cout<<"\nStudent "<<i<<endl; cout<<"\nName: "<<count[i].name; cout<<"\nRoll no.: "<<count[i].rollno; for(int h=1;h<=5;h++) { if(count[i].mark[h]==0) temp=count[i].total; } cout<<count[i].total; cout<<"\n\n"; l++; } l=1; for(i=1;i<=n;i++) { fail[l]=count[i]; l++; } int temp; for(i=1;i<=n;i++) { for(int j=1;j<=n-1;j++)
164 | P a g e

{ if(fail[j].total<fail[j+1].total) { temp=fail[j].total; fail[j].total=fail[j+1].total; fail[j+1].total=temp; } } int k=1; for(i=1;i<=n;i++) { count[i].flag=0; for(int j=1;j<=5;j++) { if(count[i].mark[j]==0||count[i].mark[j]<33) { check[k]=i; count[i].total=0; } } } cout<<"\n\nDetails saved!\n"; strcpy(corr, count[2].name); strcpy(cor, count[5].name); } void rank() {
165 | P a g e

student tell[50]; int k=1; for(int i=1;i<=n;i++) { tell[k]=count[i]; k++; } k--; int t; char *u; tell[k+1].total=0; for(i=1;i<=k+1;i++) { for(int j=1;j<=k;j++) { if(tell[j].total<tell[j+1].total) { t=tell[j].total; tell[j].total=tell[j+1].total; tell[j+1].total=t; strcpy(u, tell[j].name); strcpy(tell[j].name, tell[j+1].name); strcpy(tell[j+1].name, u); } } } int ctr=0; int ran=1; int cnt=0;
166 | P a g e

int j; tell[n+1].total=0; for(i=1;i<=n;i++) { for(j=i+1;j<=n+1;j++) { if(tell[i].total==tell[j].total) { cnt=0; for(int r=1;r<=ctr;r++) ran++; tell[i].rank=ran; tell[j].rank=ran; for(int l=j+1;l<=n+1;l++) { if(tell[j].total==tell[l].total) { tell[l].rank=ran; cnt++; } } ctr++; i+=ctr+cnt; break; } else { for(k=1;k<=ctr;k++) {
167 | P a g e

ran++; } tell[i].rank=ran; ran++; ctr=0; break; } } if(tell[i-1].total==tell[i-2].total) { tell[i-1].rank=ran; tell[i-2].rank=ran+1; } else tell[i-1].rank=ran+1; int l=1; for(i=1;i<=n;i++) { count[l]=tell[i]; l++; } for(i=1;i<=n;i++) { if(count[i].total==0) count[i].rank=0; } cout<<"\n\nRank processed!\n"; }
168 | P a g e

void display() { clrscr(); student print[50], tell[50]; char *s; int p=1; for(int j=1;j<=n;j++) { print[p]=fail[j]; p++; } p--; for(int i=1;i<=n;i++) { for(j=i+1;j<=n;j++) { if(strcmp(print[i].name,print[j].name)>0) { strcpy(s, print[i].name); strcpy(print[i].name, print[j].name); strcpy(print[j].name, s); } } } cout<<"\t\t\tREPORT CARD\n"; cout<<"----------------------------------------------------------\n\n"; int lt=1;
169 | P a g e

gotoxy(1,4); cout<<"Sno"; gotoxy(5,4); cout<<"Name"; gotoxy(19,4); cout<<"Eng"; gotoxy(28,4); cout<<"Comp"; gotoxy(37,4); cout<<"Math"; gotoxy(44,4); cout<<"Phy"; gotoxy(52,4); cout<<"Chem"; gotoxy(62,4); cout<<"Tot"; gotoxy(69,4); cout<<"Rank\n\n"; int sno=1, coord=6; do { for(i=1;i<=n;i++) { if(strcmp(print[lt].name, count[i].name)==0) { gotoxy(1,coord); cout<<sno; gotoxy(5,coord); puts(count[i].name);
170 | P a g e

gotoxy(19,coord); cout<<count[i].mark[1]; gotoxy(28,coord); cout<<count[i].mark[2]; gotoxy(37,coord); cout<<count[i].mark[3]; gotoxy(44,coord); cout<<count[i].mark[4]; gotoxy(52,coord); cout<<fail[i].mark[5]; gotoxy(62,coord); cout<<count[i].total; gotoxy(68,coord); if(count[i].rank==0) cout<<"-"; else cout<<count[i].rank; cout<<"\n\n"; } } lt++; sno++; coord+=2; } while(lt<=n); } void menu() { int ch; p:
171 | P a g e

clrscr(); cout<<"\nREPORT CARD GENERATION - Main Menu\n"; cout<<"1. Accepting student details\n"; cout<<"2. Processing rank\n"; cout<<"3. Displaying the report card\n"; cout<<"4. Exit\n"; cout<<"Enter your choice: "; cin>>ch; switch(ch) { case 1: { getdata(); getch(); goto p; } case 2: { rank(); getch(); goto p; } case 3: { display(); getch(); goto p; } case 4:
172 | P a g e

{ cout<<"\nPress any key to exit."; getch(); exit(0); } default: { cout<<"\nWrong option! Enter again."; getch(); goto p; } } } void main() { clrscr(); menu(); getch(); } SAMPLE OUTPUT FOR THIS PROGRAM REPORT CARD GENERATION Main Menu 1. Accepting student details 2. Processing rank 3. Displaying the report card 4. Exit Enter your choice: 1
173 | P a g e

STUDENT DETAILS How many students? : 2 Enter details of student 1 Name: Raheem Sterling Roll no. : 16 Mark in English: 87 Mark in CS: 69 Mark in Maths: 93 Mark in Physics: 82 Mark in Chemistry: 73 Enter details of student 2 Name: Ubanish Lahari Roll no. : 4 Mark in English: 96 Mark in CS: 65
174 | P a g e

Mark in Maths: 70 Mark in Physics: 62 Mark in Chemistry: 74 The entered details are Student 1 Name: Raheem Sterling Roll no. : 16 Student 2 Name: Ubanish Lahari Roll no. : 2 Details saved! REPORT CARD GENERATION Main Menu 1. Accepting student details 2. Processing rank 3. Displaying the report card 4. Exit Enter your choice: 2 Rank processed!
175 | P a g e

REPORT CARD GENERATION Main Menu 1. Accepting student details 2. Processing rank 3. Displaying the report card 4. Exit Enter your choice: 3 REPORT CARD --------------------------------------------------------Sno Name 1 2 Ubanish Lahari Raheem Sterling Eng Comp Math Phy Chem Total Rank 96 65 87 69 70 93 62 82 74 73 367 404 2 1

REPORT CARD GENERATION Main Menu 1. Accepting student details 2. Processing rank 3. Displaying the report card 4. Exit Enter your choice: 4 Press any key to exit.

176 | P a g e

EXP. NO. 21 DATE: 8-11-2012 SQL COMMANDS I TABLE: Name Malvika Karan Aniket Craig Cristiano Shimoli Vignesh Roll 101 102 103 104 105 106 107 Class C12 M12 C12 C12 E12 C12 C12 Age 16 17 17 17 17 18 17 Marks 90 92 93 92 95 94 95 DOB 10-Dec-95 20-May-95 07-Aug-95 11-Jun-95 05-Oct-95 15-Nov-95 23-Sep-95

QUESTIONS: 1. Create the table given. 2. Show the details. 3. Insert values as given above into the table. 4. Display all the details present in table SECTION1. 5. Display all the details of SECTION1 in descending order based on name.
177 | P a g e

6. Select all the details from table SECTION1 where the name of the student starts with S. 7. Print age and number of students in the age group 13 to 15. 8. Print the sum of marks from table SECTION1. 9. Print minimum, maximum and average values from table SECTION1. 10. Print how many classes are there. 11. Reset the values of class to M12 where roll no. is 107 from table SECTION1. 12. Delete record where roll no. is equal to 107. 13. Print age alone in descending order. 14. Print name and roll no. from table SECTION1 where mark is less than 93 and class is C12. 15. Add a new attribute mark to a decimal value holder. 16. Modify attribute mark to a decimal value holder. 17. Print the atomic values of class.

178 | P a g e

18. Display name, roll no. from table SECTION1 where mark of student is between 91 and 91. 19. How many marks are there in database. 20. Create a view called SECTION2 and copy marks and roll no. alone into this database. 21. Drop the view table. 22. Create another table called SECTION3 which has details called name, roll no. and class. Insert data on your own. 23. Join the two tables together such that the screen should have name and roll no. only. 24. Delete the SECTION1. COMMANDS: SQL> CREATE TABLE SECTION1(NAME CHAR(20),ROLL NUMBER(38),CLASS CHAR(10),AGE INTEGER,MARKS INTERGER,DOB DATE); Table created. SQL> DESC SECTION1; Name Null? Type --------------------------------- -------- ---NAME CHAR(20)
179 | P a g e

ROLL CLASS AGE MARKS DOB

NUMBER(38) CHAR(10) NUMBER(38) NUMBER(38) DATE

SQL> INSERT INTO SECTION1 VALUES(MALVIKA, 101,C12,15,90,10-Dec-96); 1 row created. SQL> INSERT INTO SECTION1 VALUES(KARAN, 102,M12,14,92,20-May-98); 1 row created. SQL> INSERT INTO SECTION1 VALUES(ANIKET, 103,C12,15,93,07-Aug-97); 1 row created. SQL> INSERT INTO SECTION1 VALUES(CRAIG, 104,C12,14,92,11-Jun-98); 1 row created. SQL> INSERT INTO SECTION1 VALUES(CRISTIANO, 105,E12,13,95,05-Oct-99); 1 row created. SQL> INSERT INTO SECTION1 VALUES(SHIMOLI, 106,C12,13,94,15-Nov-99); 1 row created.
180 | P a g e

SQL> INSERT INTO SECTION1 VALUES(VIGNESH, 107,C12,13,95,23-Sep-99); 1 row created. SQL> SELECT * FROM SECTION1; Name Roll Class Age Marks Dob -------------------------------------------------------------Rhea 101 C12 16 90 10-Dec-95 Karan 102 M12 17 92 20-May-95 Aniket 103 C12 17 93 07-Aug-95 Craig 104 C12 17 92 11-Jun-95 Cristiano 105 E12 17 95 05-Oct-95 Shimoli 106 C12 18 94 15- Nov-94 Vignesh 107 C12 17 95 23-Sep-95 7 rows selected SQL>SELECT *FROM SECTION1 ORDER BY NAME DESC Name Roll Class Age Marks Dob -------------------------------------------------------------Craig 104 C12 17 92 11-Jun-95 Vignesh 107 C12 17 95 23-Sep-95 Cristiano 105 E12 17 95 05-Oct-95 Shimoli 106 C12 18 94 15-Nov-94 Malvika 101 C12 16 90 10-Dec-95 Aniket 103 C12 17 93 07-Aug-95 Karan 102 M12 17 92 20-May-95
181 | P a g e

7 rows selected SQL>SELECT *FROM SECTION1 WHERE NAME LIKE S%; Name Roll Class Age Marks Dob -------------------------------------------------------------Cristiano 105 E12 17 95 05-Oct-95 Shimoli 106 C12 18 94 15-Nov-94 Vignesh 107 C12 17 95 23-Sep-95 SQL>SELECT AGE,COUNT(AGE) FROM SECTION1 GROUP BY AGE HAVING AGE BETWEEN 13 AND 15 AGE ----13 14 15 COUNT ---------3 2 2

SQL>SELECT SUM(MARKS) FROM SECTION1; SUM(MARKS) --------------651 SQL> SELECT MIN(MARKS),MAX(MARKS),AVG(MARKS) FROM SECTION1; MIN(MARKS) MAX(MARKS) AVG(MARKS) --------------------------------------------90 95 93
182 | P a g e

SQL>SELECT COUNT(DISTINCT CLASS) FROM SECTION1; COUNT(DISTINCT CLASS) -----------------3 SQL>UPDATE SECTION1 SET CLASS=M12 WHERE ROLL=107; 1 ROW UPDATE SQL>DELETE FROM SECTION1 WHERE ROLL=107; 1 ROW DELETED SQL>SELECT * FROM SECTION1 ORDER BY AGE DESC; Name Roll Class Age Marks Dob -------------------------------------------------------------Malvika 101 C12 16 90 10-Dec-95 Aniket 103 C12 17 93 07-Aug-95 Karan 102 M12 17 92 20-May-95 Craig 104 C12 17 92 11-Jun-95 Cristiano 105 E12 17 95 05-Oct-95 Shimoli 106 C12 18 94 15-Nov-94 6 ROWS SELECTED SQL>SELECT NAME,ROLL FROM SECTION1 WHERE MARKS<93 AND CLASS=C12
183 | P a g e

NAME ---------MALVIKA CRAIG

ROLL -------101 104

SQL>ALTER TABLE SECTION1 ADD(GAME CHAR(10)); TABLE ALTERED SQL>SELECT DISTINCT CLASS FROM SECTION1; CLASS -------C12 E12 M12 SQL>SELECT NAME,ROLL FROM SECTION1 WHERE MARKS BETWEEN 91 AND 94; NAME -----------KARAN ANIKET CRAIG SHIMOLI ROLL ---------102 103 104 106

SQL>SELECT COUNT(DISTINCT MARKS) FROM SECTION1; COUNT(DISTINCT MARKS) ---------------------5


184 | P a g e

SQL>CREATE VIEW SECTION2 AS SELECT MARKS,ROLL FROM SECTION1; VIEW CREATED SQL>DROP VIEW SECTION2; VIEW DROPPED SQL>CREATE TABLE SECTION3(NAME CHAR(10),ROLL NUMBER(380,CLASS CHAR(4)); TABLE CREATED SQL>INSERT INTO SECTION3 VALUES(PAULINE,108,M12); 1 Row created

SQL>SELECT NAME,ROLL FROM SECTION3 UNION SELECT NAME,ROLL FROM SECTION1; NAME ROLL ------------------------KARAN 102 ANIKET 103 PAULINE 108 MALVIKA 101 SHIMOLI 106 CRISTIANO 105 CRAIG 104 7 Rows selected
185 | P a g e

SQL>DROP TABLE SECTION1; Table dropped

186 | P a g e

EXP. NO. 22 DATE: 22-11-2012 SQL COMMANDS II TABLES: Table: Interiors


NO 1 2 3 ITEMNAME SLEEPWELL SHISHI PRINCESS TYPE DATEOFSTOCK PRICE DISCOUNT DOUBLE BED 23-FEB-02 32000 15 BABY COT 20-JAN-02 9000 10 BABY COT 19-JAN-02 8500 10

Table: Newones
NO 1 2 3 ITEMNAME KING SIZE RECLINER JINGLE TYPE DATEOFSTOCK PRICE DISCOUNT DOUBLE BED 23-MAR-03 20000 20 SOFA 20-FEB-03 15000 15 BABY COT 21-FEB-03 7000 10

QUESTIONS: 1. Create the table interiors. 2. Insert values into interiors table. 3. Display contents of table interiors. 4. Create the table networks.
187 | P a g e

5. Insert values into newones table. 6. Display the contents of table newones. 7. To show all information about the sofas from the interiors table. 8. To list the itemnames and which are priced at more than 10000 from the interiors table. 9. To list itemname and type of those items in which date of stock is before 22-01-2002 from the interiors table in descending order of itemname. 10. To display itemname and date of stock of those items ,in which the discount percentage is more than 15 from interiors table. 11. To count the number of items ,whose type is double bed from interiors table. 12. To insert a new row in the newones table with the following data: 14,india teak ,office table , 28-MAR-03, 15000,20. COMMANDS: SQL>CREATE TABLE INTERIORS (NO INTEGER,
188 | P a g e

ITEMNAME CHAR(15), TYPE CHAR(15), DATEOFSTOCK DATE, PRICE INTEGER, DISCOUNT INTEGER); Table created. SQL>INSERT INTO INTERIORS VALUES(1,SLEEPWELL, DOUBLE BED ,23-FEB-02, 32000,15); 1 row created SQL>INSERT INTO INTERIORS VALUES(2,SHISHI , BABY COT ,20-JAN-02, 9000,10); 1 row created SQL>INSERT INTO INTERIORS VALUES(3,PRINCESS, BABY COT ,19-FEB-02, 8500,10); 1 row created SQL>SELECT* FROM INTERIORS;
NO ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT -- ------------ ------------------ --------------- ---------- -----------------1 SLEEPWELL DOUBLE BED 23-FEB-02 32000 15 2 SHISHI BABY COT 20-JAN-02 9000 10 3 PRINCESS BABY COT 19-FEB-02 8500 10

SQL> CREATE TABLE NEWONES 2 (NO INTEGER,


189 | P a g e

3 4 5 6 7

ITEMNAME CHAR(15), TYPE CHAR(15), DATEOFSTOCK DATE, PRICE INTEGER, DISCOUNT INTEGER);

Table created. SQL> INSERT INTO NEWONES VALUES(11,'KING SIZE','DOUBLE BED','23-MAR-03', 1 row created. SQL> INSERT INTO NEWONES VALUES(12,'RECLINER','SOFA','20-FEB-03',15000,15 1 row created. SQL> INSERT INTO NEWONES VALUES(13,'JINGLE','BABY COT','21-FEB-03',7000, 1 row created. SQL> SELECT*FROM NEWONES;
NO ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT --------- --------------- --------------- --------- --------- ------------------11 KING SIZE DOUBLE BED 23-MAR-03 20000 20 12 RECLINER SOFA 20-FEB-03 15000 15 13 JINGLE BABY COT 21-FEB-03 7000 10
190 | P a g e

SQL> SELECT*FROM INTERIORS WHERE TYPE='SOFA'; no rows selected SQL> SELECT ITEMNAME FROM INTERIORS WHERE PRICE>10000; ITEMNAME --------------SLEEPWELL SQL> SELECT ITEMNAME FROM INTERIORS WHERE DATEOFSTOCK<'22-JAN-02'ORDER BY ITEMNAME DESC; ITEMNAME --------------SHISHI SQL> SELECT COUNT(*)FROM INTERIORS WHERE TYPE='DOUBLE BED'; COUNT(*) --------1 SQL> INSERT INTO NEWONES VALUES(14,'INDIA TEAK','OFFICE TABLE','28-MAR-03',15000,20); 1 row created.
191 | P a g e

192 | P a g e