Date post: | 10-Apr-2015 |
Category: |
Documents |
Upload: | paresh-pandit |
View: | 367 times |
Download: | 5 times |
DOCUMENTATION
1. NAME OF THE SOURCE FILE:- Paresh1.cpp
2. PURPOSE OF FILE:-To invoke a function returning an object
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-905 Bytes
5. FUNCTION USED:-getdata( ),printit( )
6. BRIEF DESCRIPTION OF EACH FUNCTION:- getdata( )-input values, printit( )-print values
7. DATA FILES USED:-
8. SAMPLE INPUT:-Feet, Inches
9. SAMPLE OUTPUT:-Total Length
10. APPLICATION OF THE PROGRAM:-Return an object/*Program to illustrate the Working of a Function Returning an Object*/
total=sum(Length1,Length2); cout<<"Length1 :"; Length1.printit(); cout<<"Length2 :"; #include<iostream.h>#include<conio.h> class Distance{ int feet,inches; public: void getdata(int f,float i) { feet=f;
inches=i; } void printit(void) { cout<<feet<<"feet"<<inches<<"inches"<<"\n"; } friend Distance sum(Distance d1,Distance d2); }; Distance sum(Distance d1,Distance d2) { Distance d3; d3.feet=d1.feet+d2.feet+ (d1.inches+d2.inches)/12; d3.inches= (d1.inches+d2.inches) %12; return(d3); }int main(){ clrscr(); Distance Length1,Length2,total; Length1.getdata(17,6); Length2.getdata(13,8);
Length2.printit(); cout<<"Total Length :"; total.printit(); return 0;}
OUTPUT:-Length1:17feet6inchesLength2:13feet8inchesTotal length31feet2inches
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program2.cpp
2. PURPOSE OF FILE:-Sort an array using insertion sort.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-731 Bytes
5. FUNCTION USED:- Inssort
6. BRIEF DESCRIPTION OF EACH FUNCTION:- Sort the given array
7. DATA FILES USED:-
8. SAMPLE INPUT:-Elements of the array
9. SAMPLE OUTPUT:-Sorted array
10. APPLICATION OF THE PROGRAM:-Elements of the array were to be arranged in ascending order.
ALGORITHM FOR INSERTION SORT
//To make A[0] the sentinel elements by sorting minimum possible intigervalue//
1. A[0]=minimum integer value /*Now start sorting the */
2. Repeat steps 3 through 8 for k=1, 2, 3.....N-1 {
3. temp=A[k]
4.ptr=k-1
5. Repeat steps 6 to n7 while temp<A[ptr]
6. A[ptr+1]=A[ptr] //Moves element forward
7. [ptr=ptr-1]
} //end of inner repeat –step 5, s loop 8. A [ptr+1] =temp } //End of outer repeat-2' s loop9.END
//Program for Insertion Sort in Array
#include<iostream.h>#include<conio.h>#include<limits.h> void InsSort(int[],int); void main(){ int AR[50],N; clrscr(); cout<<"How many element do you want in array ?"; cin>>N; cout<<"\nEnter array elements...\n"; for(int i=1;i<=N;i++) { cin>>AR[i]; } InsSort(AR,N); cout<<"\n\nThe Sorted array is as shown below...\n"; for(i=0;i<N;i++) cout<<AR[i]<<" "; cout<<endl;} void InsSort(int AR[],int size) { int tmp,j; AR[0]=INT_MIN; for(int i=1;i<=size;i++) { tmp=AR[i]; j=i-1; while(tmp<AR[j]) { AR[j+1]=AR[j]; j--; } AR[j+1]=tmp; cout<<"Array after pass -"<<i<<"- is:\n"; for(int k=0;k<=size;k++)
cout<<AR[k]<<" "; cout<<endl; } }
OUTPUT:
How many elements do you want in array?7Enter array elements...9 6 1 3 4 2 7 Array after pass-1-is-32768 9 6 1 3 4 2 7 Array after pass-2-is-32768 6 9 1 3 4 2 7 Array after pass-3-is-32768 1 6 9 3 4 2 7 Array after pass-4-is-32768 1 3 6 9 4 2 7 Array after pass-5-is-32768 1 3 4 6 9 2 7 Array after pass-6-is-32768 1 2 3 4 6 9 7 Array after pass-7-is-32768 1 2 3 4 6 7 9 The sorted array is as shown bellow...-32768 1 2 3 4 6 7
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program3.cpp
2. PURPOSE OF FILE:-To searches an element in an array.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-1kB
5. FUNCTION USED:-Linear Search
6. BRIEF DESCRIPTION OF EACH FUNCTION: - Checks each element of an array with the item to be searched.
7. DATA FILES USED:-
8. SAMPLE INPUT:-Array elements, elements to be searched.
9. SAMPLE OUTPUT:-Element found at position.
10. APPLICATION OF THE PROGRAM:-Searching a particular element and finding its position in the array.
ALORITHM FOR LINER SEARCH /*initialize counter by assigning lower bound value of the array*/ 1. Set ctr=1 //in c++, 1=0(zero) /*Search for the ITEM*/ 2. Repeat step 3 trough 4 until ctr>u //u=size-1
3. if AR{ctr}==ITEM then { print “Search Successful” print ctr,”is the location of",ITEM break } 4. ctr=ctr+1 /*End of repeat */ 5. if ctr>u then print “Search Successful!” 6. END
/* Program for Linear Search in Array */
#include<iostream.h>#include<conio.h> int Lsearch(int[],int,int); void main(){ int AR[50],ITEM,N,index; clrscr(); cout<<"Enter desired array size(max. 50)..."; cin>>N; cout<<"\nEnter array elements\n"; for(int i=0;i<N;i++) { cin>>AR[i]; } cout<<"\nEnter element to be searched for..."; cin>>ITEM; index=Lsearch(AR,N,ITEM); if(index==-1) cout<<"\nSorry!! Given element could not found\n"; else cout<<"\nElement found at index :"<<index<<",Position :"<<index+1<<endl;} int Lsearch(int AR[],int size,int item) { for(int i=0;i<=size;i++) { if(AR[i]==item) return i;
} return -1; }
OUTPUT:-
Enter desired array size(max.50)...10Enter array elements0 1 2 3 4 5 6 7 8 9 Enter element to be searched for...6Element found at index: 6, Position: 7
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program4.cpp
2. PURPOSE OF FILE:-To push an element in linked stack.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-1.18kB
5. FUNCTION USED:-Push, Display
6. BRIEF DESCRIPTION OF EACH FUNCTION: - Pushes the element in linked stack and display the stack.
7. DATA FILES USED:-
8. SAMPLE INPUT:-Enter information for new node.
9. SAMPLE OUTPUT:-Linked stack after pushing.
10. APPLICATION OF THE PROGRAM:-Where an element has to be pushed in linked stack.
ALGORITHIM FOR PUSHING OF AN ELEMENT /*Get new node for the ITEM to be pushed*/
1. NEWPTR = new Node
2.NEWPTR -> INFO = ITEM ; NEWPTR >LINK= NULL
/*ADD new node at the top* 3. If Top = NULL then /*stack is empty*/
4. TOP = NEWPTR
5. else {
6. NEWPTR-> LINK = TOP 7. TOP = NEWPT
} // of step 3 8. END
//Program for Pushing in Linked - Stack
#include<iostream.h>#include<conio.h>#include<process.h> struct Node{ int info; Node*next;} *top,*newptr,*save,*ptr; Node*Create_New_Node(int); void Push(Node*); void Display(Node*); void main() { int inf; char ch='y'; top=NULL; clrscr(); while(ch=='y'||ch=='Y') { cout<<"\nEnter INFORMATION for the new node..."; cin>>inf; newptr=Create_New_Node(inf); if(newptr==NULL) {
cout<<"]nCannot create new node!!! Aborting!!\n"; exit(1); } Push(newptr); cout<<"\nNow the linked-stack is :\n"; Display(top); cout<<"\nPress Y to enter more nodes,N to exit..."; cin>>ch; } } Node*Create_New_Node(int n) { ptr=new Node; ptr->info=n; ptr->next=NULL; return ptr; } void Push(Node*np) { if(top==NULL) top=np; else { save=top; top=np; np->next=save; } } void Display(Node*np){ while(np!=NULL) { cout<<np->info<<"->"; np=np->next; } cout<<"!!!\n";}
OUTPUT:-
Enter INFORMATION for the new node5Now the linked stack is:5->!!!Press Y to enter more nodes, N to exit...
YEnter INFORMATION for the new node6Now the linked stack is:6->5->!!!Press Y to enter more nodes, N to exit...N
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program5.cpp
2. PURPOSE OF FILE:-To read and write a structure using binary file.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-634Bytes
5. FUNCTION USED:-
6. BRIEF DESCRIPTION OF EACH FUNCTION: -
7. DATA FILES USED:-Saving(Binary file)
8. SAMPLE INPUT:-Enter information for new node.
9. SAMPLE OUTPUT:-Balance
10. APPLICATION OF THE PROGRAM:-Where Binary file has to be used.
/*Program to Write and Read a Structure using write() & read() function using a Binary File*/
#include<fstream.h>#include<string.h>#include<conio.h> struct customer { char name[51]; float balance; }; int main() { clrscr(); customer savac; strcpy(savac.name,"Sandeep Arora"); savac.balance=21310.75; ofstream fout; fout.open("Saving",ios::out | ios::binary); if(!fout) { cout<<"File can't be opened\n"; return 1; } fout.write((char*)&savac,sizeof(customer)); fout.close(); ifstream fin; fin.open("Saving",ios::in | ios::binary); fin.read((char*)&savac,sizeof(customer)); cout<<savac.name; cout<<" has the balance Rs."<<savac.balance<<"\n"; fin.close(); return 0;}
OUTPUT:-
Sandeep Arora has the balance Rs.21310.75
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program6.cpp
2. PURPOSE OF FILE:-To show transversal in linked list.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-1.11kb
5. FUNCTION USED:-Insert, Transverse
6. BRIEF DESCRIPTION OF EACH FUNCTION: -Inserts elements in linked list ,performs transversal
7. DATA FILES USED:-
8. SAMPLE INPUT:-Information for new node
9. SAMPLE OUTPUT: - List after transversal.
10. APPLICATION OF THE PROGRAM:-Performing transversal in linked List.
ALGORITHM FOR TRNSVERSAL
/*Initialise counters*/1. ptr = start
2. Repeat step 3 and 4 until ptr = NULL
3. print ptr-> INFO
4. ptr = ptr ->LINK
5. END
//Program for Transversal in a List
#include<iostream.h>#include<conio.h>#include<process.h>
struct Node{ int info; Node*next;}*start,*newptr,save,*ptr,*rear;Node*Create_New_Node(int); void Insert(Node*); void Traverse(Node*); void main(){ start=rear=NULL; int inf; char ch='y'; clrscr(); while(ch=='y'||ch=='Y') { cout<<"\n Enter information for the new node..."; cin>>inf; newptr=Create_New_Node(inf); if(newptr==NULL) { cout<<"\nCannot create new node!!!Aborting!!\n"; getch(); exit(1); } Insert(newptr); cout<<"\nPress Y to enter more nodes, N to exit...\n"; cin>>ch; } cout<<"\n The List now is :\n"; Traverse(start); getch();}Node*Create_New_Node(int n){
ptr=new Node; ptr->info=n; ptr->next=NULL; return ptr;}void Insert(Node*np){ if(start==NULL) { start=np; rear=np; } else { rear->next=np; rear=np; }}void Traverse(Node*np){ while(np!=NULL) { cout<<np->info<<"->"; np=np->next; } cout<<"!!!\n";} OUTPUT:-
Enter information for new node...5Press Y to enter more nods, N to exitYEnter information for new node...7Press Y to enter new nodes, N to exitNThe list now is:5->7->!!!
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program7.cpp
2. PURPOSES OF FILE:-To invoke a function.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-1.15kb
5. FUNCTION USED:-Display ,Increase
6. BRIEF DESCRIPTION OF EACH FUNCTION: -Display-print the output. Increase- calculates
7. DATA FILES USED:-Increase in salary.
8. SAMPLE INPUT:-Employee number, name, basic pay, experience.
9. SAMPLE OUTPUT: - Basic pay before increase,Basic pay after increase.
10. APPLICATION OF THE PROGRAM:-Calling data members of a function.
/*Program to invoke a function to increase the basic salary of an employee. If the employee has experience of ten or more years*/
#include<iostream.h>#include<conio.h>#include<string.h>#include<stdio.h>struct employee{ int empno; char name[26];
float basic; float experience;};void display(employee *emp);
void increase(employee *emp);int main(){ clrscr(); employee mgr,*eptr; cout<<"enter employee number :"; cin>>mgr.empno; cout<<"enter name : "; gets(mgr.name); cout<<"enter basic pay::"; cin>>mgr.basic; cout<<"enter experience(in years): "; cin>>mgr.experience; eptr=&mgr; cout<<"employee details before increase()"; display(eptr); increase(eptr); cout<<"\n employee details after increase()"; display(eptr); return 0;}void display(employee *emp) { int len=strlen(emp->name); cout<<"employee no.:"<<emp->empno; cout<<"\n name :"; cout.write(emp->name,len); cout<<"\t basic :"<<emp->basic;cout<<"\t experience:"<<emp->experience<<"years\n"; return; } void increase(employee *emp) { if(emp->experience>=10) emp->basic+=200; return; } OUTPUT:-
Enter employee number:Enter name: ssEnter basic pay: 8000Enter experience (in years):12Employee Details before increase ()
Employee number: 101Name: ss Basic: 8000 experience:12 years
Employee details after increase ()Employee number: 101Name: ss Basic: 8200 experience: 12 years.
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program8.cpp
2. PURPOSES OF FILE:-To find difference between two matrices.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-1.28kb
5. FUNCTION USED:-
6. BRIEF DESCRIPTION OF EACH FUNCTION: -
7. DATA FILES USED:-
8. SAMPLE INPUT:-Elements of two matrices
9. SAMPLE OUTPUT: - New matrix after subtraction.
10. APPLICATION OF THE PROGRAM:-Where subtraction has to be performed between the elements of two matrices.
ALGORITHM FOR DIFFERENCE OF MATRIX
/*check whether two matrices are identical or not*/
1. if(m<>p)or(n<>q)then
2. print" subtraction not possible"
3. else
4. {for I=1 to m perform steps 5 through 7 5. {for j=1 to n perform steps 6 through 7
6. {Read A[i,j]
7. Read B[i,j] } (inner loop) } {(outer loop)
/*calculate the difference and store it in a new matrix*/
8. for i=1 to m perform steps 9 through 11
9. { for j=1 to n perform steps 10 through 11 {10. C[i,j]=0
11. C[i,j]=A[i,j]-B[i,j] } } }
12. END
//Program to calculate Difference of Matrices
#include<iostream.h>#include<conio.h>#include<process.h>int main(){ clrscr(); int a[10][10],b[10][10],c[10][10];
int i,j,m,n,p,q; cout<<"\nInput row & column of matrix-A\n"; cin>>m>>n; cout<<"\nInput row & column of matrix-B\n"; cin>>p>>q; if((m==p)&&(n==q)) cout<<"Matrices can be subtracted\n"; else { cout<<"Matrices cannot be subtracted\n"; exit(0); } cout<<"\nInput matrix - A\n"; for(i=0;i<m;i++) { for(j=0;j<n;j++)
cin>>a[i][j]; } cout<<"\nInput matrix - B\n"; for(i=0;i<p;i++) { for(j=0;j<q;j++)
cin>>b[i][j]; } cout<<"\nMATRIX - A :"; for(i=0;i<m;i++) { cout<<"\n"; for(j=0;j<n;j++) cout<<" "<<a[i][j]; } cout<<"\nMATRIX - B :"; for(i=0;i<p;i++) { cout<<"\n"; for(j=0;j<q;j++) cout<<" "<<b[i][j]; } for(i=0;i<m;i++) { for(j=0;j<n;j++)
c[i][j]=a[i][j]-b[i][j]; } cout<<"\nThe difference of the two matrices is :\n"; for(i=0;i<m;i++)
{ cout<<"\n"; for(j=0;j<n;j++)
cout<<" "<<c[i][j]; } return 0;}
OUTPUT:-
Input row and column of matrix-A2 2Input row and column of matrix-B2 2Input matrix-A6 4 2 7Input matrix-B1 20 0The difference of two matrices is:5 22 7
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program9.cpp
2. PURPOSES OF FILE:-To insert in a file and display.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-1.18kb
5. FUNCTION USED:-
6. BRIEF DESCRIPTION OF EACH FUNCTION: -
7. DATA FILES USED:-Text files
8. SAMPLE INPUT:-Student1, name and Marks
9. SAMPLE OUTPUT: - Students name, Marks.
10. APPLICATION OF THE PROGRAM:-Insert data into file.
//Program to create a single file and display its contents
#include<fstream.h>#include<conio.h>int main(){ clrscr(); ofstream fout("Student"); char name[30],ch; float marks=0.0; for(int i=0;i<5;i++) { cout<<"Student"<<(i+1)<<":\tName :"; cin.get(name,30); cout<<"\t\tMarks :"; cin>>marks; cin.get(ch); fout<<name<<'\n'<<marks<<'\n'; } fout.close(); ifstream fin("Student"); fin.seekg(0); cout<<"\n"; for(i=0;i<5;i++) { fin.get(name,30); fin.get(ch); fin>>marks; fin.get(ch);
cout<<"Student Name :"<<name; cout<<"\tMarks :"<<marks<<"\n"; } fin.close(); return 0;}
INPUT:
Student 1: Name: Kshitij Patel Marks: 79Student 2: Name: Sourabh Sinha Marks: 89Student 3: Name: Pushkar Shukla Marks: 80Student 4: Name: Nimeash Singhal Marks: 94Student 5: Name: Praggya Gupta Marks: 77
OUTPUT:Student Name: Kshitij Patel Marks: 79 Student Name: Saurabh Sinha Marks: 89 Student Name: Pushkar Shukla Marks: 80 Student Name: Sanjeev Singhal Marks: 94 Student Name: Praggya Gupta Marks: 77
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program10.cpp
2. PURPOSES OF FILE:-To insert element in an Array Queue.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-1.18kb
5. FUNCTION USED:-Insert-in-q, Display
6. BRIEF DESCRIPTION OF EACH FUNCTION: -Insert element in queue, display the new queue.
7. DATA FILES USED:-
8. SAMPLE INPUT:-Items for insertion.
9. SAMPLE OUTPUT: -The queue with the inserted element.
10. APPLICATION OF THE PROGRAM:-Where an element has to be inserted in an array queue.
ALGORITHM FOR INSERTION IN ARRAY QUEUE
1. if real=Null then
{2. rear=front=0
3. QUEUE[0]=ITEM }
4. else if rear =N-1 then
5. Print "QUEUE FULL,OVERFLOW!!"
6. else
{7. QUEUE[REAR +1]=ITEM
8. REAR=REAR +1 }
9. END
//Program for Insertion in Array - Queue
#include<constream.h>#include<process.h>int Insert_in_Q(int[],int);void Display(int [],int,int);const int size=50;int Queue[size],front=-1,rear=-1;void main(){ int Item,res; char ch='y'; clrscr(); while(ch=='y'||ch=='Y') { cout<<"\nEnter item for insertion :"; cin>>Item; res=Insert_in_Q(Queue,Item); if(res==-1) { cout<<"OVERFLOW!!! Aborting!!\n"; exit(1); } cout<<"\nNow the Queue(Front...to..rear)is :\n"; Display(Queue,front,rear); cout<<"\nwant to Insre more elements?(y/n).."; cin>>ch; }}int Insert_in_Q(int Queue[],int ele) { if(rear==size-1) return-1; else if(rear==-1) { front=rear=0;
Queue[rear]=ele; } else
{rear++;
Queue[rear]=ele; }
void Display(int Queue[],int front,int rear) {
if (front==-1)return;for(int i=front;i<rear;i++)cout<Queue[i]<<"<-\t";cout<<Queue[rear]<<endl;
} }
OUTPUT:-
Enter item for insertion: 5Now the queueis5What to insert more elements? (y/n)...yEnter item for insertion: 6Now the queue is5 <- 6 Want to insert more elements? (y/n)...yEnter item for insertion: 10Now the queue is5<-6<-10Want to insert more elements? (y/n)...n
DOCUMENTATION
1. NAME OF THE SOURCE FILE:- program11.cpp
2. PURPOSES OF FILE:-To delete an element from a linked queue.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-1.22kb
5. FUNCTION USED:-Insert , Display ,delnode-q.
6. BRIEF DESCRIPTION OF EACH FUNCTION: -Insert element in linked queue, deletes element from queue.
7. DATA FILES USED:-
8. SAMPLE INPUT:-Enter information for new node.
9. SAMPLE OUTPUT: -Queue after deletion.
10. APPLICATION OF THE PROGRAM:-Where an element from a linked queue has to be deleted.
ALGORITHM FOR DELETION FROM A LINKED QUEUE
1. if front=null then
2. Print "Queue Empty"
3. else
{4. ITEM=front ->INFO
5. if front = rear then {
6. front=rear=Null }
7. else
8. front=front->LINK
}9. END
//Program for Deletion from a Linked Queue
#include<constream.h>#include<process.h>struct Node{ int info; Node*next;} *front,*newptr,*save,*ptr,*rear; Node*Create_New_Node(int); void Insert(Node*); void Display(Node*); void DelNode_Q(); void main(){ front=rear=NULL; int inf; char ch='y'; while(ch=='y'||ch=='Y') {
clrscr();cout<<"\nEnter information for the new node..";cin>>inf;newptr=Create_New_Node(inf);if(newptr==NULL){ cout<<"\nCannot create new node!! Aborting!!\n";
exit(1); }
Insert(newptr);cout<<"\nPress Y to enter more nodes,N to exit..\n";cin>>ch;
} clrscr(); 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'); } void DelNode_Q() {
if(front==NULL)cout<<"UNDERFLOW !!!\n";else{ ptr=front;
front=front->next;delete ptr;
} } void Display(Node*np) { while(np!=NULL) {
cout<<np->info<<"->";np=np->next;
} cout<<"!!!\n";} Node*Create_New_Node(int n){
ptr=new Node;ptr->info=n;ptr->next=NULL;return ptr;
}void Insert(Node*np){
if(front==NULL){
front=rear=np;}else{
rear->next=np;rear=np;
} }
OUTPUT:-
Enter information for the new node...6Press Y to enter more nodes, N to exit... YEnter information for the new node...7 Press Y to enter more nodes, N to exit... YEnter information for the new node...15Press Y to enter more nodes, N to exit... NThe linked queue now is:6->7->15->!!!Want to delete first node? (Y/N)... YThe linked queue now is:7->15->!!!Want to delete first node? (Y/N)...N
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program12.cpp
2. PURPOSES OF FILE:-To merge two arrays.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-1.37kb
5. FUNCTION USED:-Merge
6. BRIEF DESCRIPTION OF EACH FUNCTION: -Two merge two arrays in ascending order.
7. DATA FILES USED:-
8. SAMPLE INPUT:-Array size array elements.
9. SAMPLE OUTPUT: -Sorted and Merged array.
10. APPLICATION OF THE PROGRAM:-Where two array have to be merged.
ALGORITHM FOR MERGING IN ARRAYS
1. ctrA=L1;ctrB=L2;ctrC=L32. WHILE ctrA<=U1 and ctrB<=U2 perform steps 3 through 103. { ifC[ctrA]<=B[ctrA]4. C[ctrC]=A[ctrA]5. ctrC=ctrC+16. ctrA=ctrA+1}7. else8. { C[ctrC]=B[ctrB]9. ctrC=ctrC+110.ctrB=ctrB+1 } }/*End of while loop*/11. if ctrA>U1 then12. { while ctrB<=U2 perform steps 13 through 1513. {C[ctrC]=B[ctrB]14. ctrC=ctrC+115. ctrB=ctrB+1 } }16. if ctrB>U2 then17. { While ctrA<=U1 performs steps 18 through 2018. {C[ctrC]=A[ctrA]19. ctrC=ctrC+120.ctrA=ctrA+1 } }
//Program to illustrate Merging in Array
#include<iostream.h>#include<conio.h>void Merge(int[],int,int[],int,int[]);void main(){ int A[50],B[50],C[50],MN=0,M,N; clrscr();
cout<<"How many elements do you want to create first array with?(max.50)...";
cin>>M; cout<<"\nEnter First Array's elements [ascending]...\n"; for(int i=0;i<M;i++) {
cin>>A[i]; } cout<<"\nHow many elements do you want to create second array with?(max.50)..."; cin>>N; MN=M+N; cout<<"\nEnter Second Array's elements [descending]...\n"; for(i=0;i<N;i++) {
cin>>B[i]; } Merge(A,M,B,N,C); cout<<"\n\nThe Sorted Array is shown as below...\n"; for(i=0;i<MN;i++) cout<<C[i]<<" "; cout<<endl; } void Merge(int A[],int M,int B[],int N,int C[]) {
int a,b,c;for(a=0,b=N-1,c=0;a<M&&b>=0;){
if(A[a]<=B[b])C[c++]=A[a++];elseC[c++]=B[b--];
}if(a<M){
while(a<M)C[c++]=A[a++];
}else{
while(b>=0)C[c++]=B[b--];
} }
OUTPUT:-
How many elements do you want to create first with? (max. 50) 5Enter First Array's elements [ascending]...2 5 8 9 13How many elements do you want to create second array with? (max. 50)7Enter Second Array's [descending]16 12 10 4 7 3 1 The sorted array is as shown below...1 2 3 4 5 7 8 9 10 12 13 16
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program13.cpp
2. PURPOSES OF FILE:-To read value in a nested structure.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-1.08kb
5. FUNCTION USED:-
6. BRIEF DESCRIPTION OF EACH FUNCTION: -
7. DATA FILES USED:-
8. SAMPLE INPUT:-Employee no., Name, Designation, Address, Area, City ,State, Basic Pay .
9. SAMPLE OUTPUT: -
10. APPLICATION OF THE PROGRAM:-Where array within structures has to be used.
//Program to read values in a nested structure
#include<iostream.h>#include<conio.h>#include<stdio.h> struct addr {
int houseno;char area[26];char city[26];char state[26];
};struct emp {
int empno;char name[26];char desig[16];addr address;float basic;
} worker; int main() {
clrscr();cout<<"\n"<<"Enter employee no :"<<"\n";cin>>worker.empno;cout<<"\n"<<"Name :";gets(worker.name);cout<<"\n"<<"Designation :"<<"\n";
gets(worker.desig);cout<<"\n"<<"Enter address :\n";cout<<"House no :";cin>>worker.address.houseno;cout<<"\n"<<"City :";gets(worker.address.city);cout<<"\n"<<"State :";gets(worker.address.state);cout<<"\n"<<"Basic Pay :"<<"\n";cin>>worker.basic;return 0;
}
OUTPUT:-
Enter employee no:11Name :Kushwant SinghDesignation:ManagerEnter address:Vasant ViharArea:Lal BaghCity:MumbaiState:MaharashtraBasic Pay:1680 DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program14.cpp
2. PURPOSES OF FILE:-To insert, delete and display in circular queue.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-2.40kb
5. FUNCTION USED:-Insert-in-cq , display, del-in queue.
6. BRIEF DESCRIPTION OF EACH FUNCTION: -Insert element in circular queue, display the queue, deletes element from circular queue.
7. DATA FILES USED:-
8. SAMPLE INPUT:-Item to insert, item to be deleted.
9. SAMPLE OUTPUT: -Queue after insertion or deletion.
10. APPLICATION OF THE PROGRAM:-Inserting new elements in queue.
//Program for Insertion and Deletion in a Circular Queue
#include<iostream.h>#include<conio.h>#include<process.h> int Insert_in_CQ(int Cqueue[],int); void Display(int[],int,int); int Del_in_CQ(int CQueue[]); const int size=7; int CQueue[size],front=-1,rear=-1; void main() {
int Item,res;int ch;do{clrscr();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 (1-4)...";cin>>ch;
switch(ch){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_(CQueue)is :\n"; Display(CQueue,front,rear);
} getch(); break;
case 2 : Item=Del_in_CQ(CQueue); cout<<"Element deleted is"<<Item<<endl;Display(CQueue,front,rear);getch();
break; case 3 : Display(CQueue,front,rear);
getch(); break;
case 4 : break; default : cout<<"Valid choices are 1...4 only\n";
getch();break;
}}while(ch!=4);
} 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<=0;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<<"\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;elsefront++;
}return ret;
}
OUTPUT:-
Circular queue menu
1. insert2. delete3. display4. exit
Enter your choice (1-4)1Enter item for insertion:34Now the Cir_(CQueue) is :circuler queue is( front shown as >>>>,rear shown as <<<<and free space as-)>>>>34<<<<
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program15.cpp
2. PURPOSES OF FILE:-To find factorial of a number.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-246 bytes.
5. FUNCTION USED:-
6. BRIEF DESCRIPTION OF EACH FUNCTION: -
7. DATA FILES USED:-
8. SAMPLE INPUT:-Enter a number.
9. SAMPLE OUTPUT: -Factorial of the number.
10. APPLICATION OF THE PROGRAM:-When a loop has to be used.
ALGORITHM FOR FACTORIAL OF A NUMBER
1. Read the value of N
2. If N<0 perform step 9
3. If N=0, fct =1 perform step 8
4. Initialize fct to 1
5. Compare fct*N, store multiplication in fct
6. compute N =N-1
7. If N>=1 repeat steps 5 and 6
8. Print fct
9. End
//Program to find factorial of a number
#include<iostream.h>#include<conio.h> int main() {
clrscr();int i,num,fact=1;cout<<"\nEnter Integer :";cin>>num;i=num;while(num)
{fact*=num;--num;
}cout<<"The factorial of "<<i<<" is "<<fact<<"\n";return 0;
}
OUTPUT:-
Enter Integer:5The factorial of 5 is 120
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program16.cpp
2. PURPOSES OF FILE:-To sort an array using selection sort.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-780 bytes.
5. FUNCTION USED:-Selsort
6. BRIEF DESCRIPTION OF EACH FUNCTION: -Sort the array in ascending order.
7. DATA FILES USED:-
8. SAMPLE INPUT:-Array elements.
9. SAMPLE OUTPUT: -Sorted array.
10. APPLICATION OF THE PROGRAM:-Where elements of an array to be arranged in ascending order..
ALGORITHM OF EXCHANGE SORT IN ARRAY
1. SMALL=ar[l] 2. FOR I=L TO U do{ 3. small=AR[i] /*Loop to find smallest element and its position*/ 4. for J=I to Udo 5. IFAR[J]<small then 6. { small=AR[J] 7. pos=J 8. temp=AR[I] 9. AR[I]=small 10. AR[pos]=temp } 11. end.
//Program for Exchange Selection Sort in Array
#include<iostream.h>#include<conio.h>void SelSort(int[],int);void main(){
int AR[50],N;clrscr();cout<<"How many elements do you want to create array with?(max.50)...";cin>>N;cout<<"\nEnter Array elements...\n";for(int i=0;i<N;i++){
cin>>AR[i];}SelSort(AR,N);
cout<<"\n\nThe Sorted array is as shown below...\n";for(i=0;i<N;i++)cout<<AR[i]<<" ";cout<<endl;
}void SelSort(int AR[],int size){
int small,pos,tmp,j;for(int i=0;i<size;i++){
small=AR[i];pos=i;for(j=i+1;j<size;j++){
if(AR[j]<small){
small=AR[j];pos=j;
}}tmp=AR[i];AR[i]=AR[pos];AR[pos]=tmp;cout<<"\nArray after pass -"<<i+1<<"- is :\n";for(j=0;j<size;j++)cout<<AR[j]<<" ";
}}
OUTPUT:
How many elements you want to create an array with?(max .50)...Enter Array elements...6 8 2 5 1 3 4 Array after pass-11 8 2 5 6 3 4Array after pass-21 2 8 5 6 3 4 Array after pass-31 2 3 5 6 8 4Array after pass-41 2 3 4 5 8 6Array after pass-51 2 3 4 5 8 6
Array after pass- 61 2 3 4 5 6 8The Sorted array is as shown below...1 2 3 4 5 6 8
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program17.cpp
2. PURPOSES OF FILE:-To search an element in an array.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-1.09 k bytes.
5. FUNCTION USED:-Bsearch
6. BRIEF DESCRIPTION OF EACH FUNCTION: -Searches the element in an array.
7. DATA FILES USED:-
8. SAMPLE INPUT:-Array elements, Element to be searched.
9. SAMPLE OUTPUT: -Position of the element.
10. APPLICATION OF THE PROGRAM:-Where an element has to be searched in an array.
ALGORITHM OF BINARY SEARCH IN ARRAY
Case I: array AR[L:U] is stored in ascending order
/*initialize segment variable*/1. set bag=1,last=u2. repeat step 3 through 6 until beg>last3. mid=INT((beg+last)/2)4. if Ar[mid]<ITEM then{ print" Search, Successful" print ITEM, "found at', mid break}5. if AR[mid]<ITEm then beg=mid+16. if AR[mid]<ITEM then
last=mid-1/*end of repeat*/7. if beg!=last
print "unsuccessful Search"8. end
Case II: Array AR[L:U] is stored in descending order/*Initialize*/if AR[mid]==ITEM then{}if AR[mid]==ITEM thenlast =mid-1if AR[mid]>ITEM thenbeg=mid+1/*End of repeat*/if beg!=lastprint "Unsuccessful search"END
//Program for Binary Search in Array
#include<iostream.h>#include<conio.h>int bsearch(int[],int,int);void main(){
int ar[50],item,n,index;clrscr();cout<<"Enter desired array size(max. 50)...";cin>>n;
cout<<"\nEnter array elements(must be sorted in asc. order)\n";
for(int i=0;i<n;i++){
cin>>ar[i];}cout<<"\nEnter element to be searched for...";cin>>item;index=bsearch(ar,n,item);if(index==-1)cout<<"\nSorry!! given element could not be founnd.\n";else
cout<<"\nElement found at index:"<<index<<",position : " << index + 1<<"\n"; }int bsearch(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;elseif(item>ar[mid])beg=mid+1;elselast=mid-1;
}return 1;
}
OUTPUT:
Enter desired array size(max.50)...7Enter array elements (must be sorted in asc order )2 5 7 8 9 1 0 1 5Enter elements to be searched for ...8Element found at index:3,position: 4
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program18.cpp
2. PURPOSES OF FILE:-To sort an array using bubble sort method.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-750 bytes.
5. FUNCTION USED:-Bubblesort
6. BRIEF DESCRIPTION OF EACH FUNCTION: -Sort an arrayin ascending order.
7. DATA FILES USED:-
8. SAMPLE INPUT:-Array elements.
9. SAMPLE OUTPUT: -Sorted array.
10. APPLICATION OF THE PROGRAM:-Where element of an array are to be arranged in ascending order..
ALGORITHM OF BUBBLE SORT
1. for I=1 to u2. {for j=1 to [(u-1)-I] //need not consider already settled heavy elements, that is why (u-1)-I //3. {if AR[j]>AR[j+1] then
{ /*swap the values*/
4. temp=AR[j]5. AR[j]=AR[j+1]6. AR[j+1]=temp
} /*end of if*/} /*end of inner loop*/
} /*end of outer loop*/
7. END
//Program for Bubble Sort in Array
#include<constream.h>void bubblesort(int[],int);void main(){
int ar[50],n;clrscr();cout<<"How many elements do you want to create array
with? (max.50)...";cin>>n;cout<<"\nEnter array elements...\n";for(int i=0;i<n;i++){
cin>>ar[i];}bubblesort(ar,n);cout<<"\n\nThe sorted array is shown below...";for(i=0;i<=n;i++)cout<<ar[i]<<" ";cout<<endl;
}void bubblesort(int ar[],int size) //function to perform bubble sort{
int temp,ctr=0;for(int i=0;i<=size;i++){
for(int j=0;j<(size-1)-1;j++){
if(ar[j]>ar[j+1]){
temp=ar[j];ar[j]=ar[j+1];
ar[j+1]=temp;}cout<<"Array after interation-"<<++ctr<<"-
is:\n";for(int k=0;k<size;k++)cout<<ar[k]<<" ";cout<<endl;
} }
}
OUTPUT:
How many elements do you want to create array with?(max.50)...4Enter array elements...7 3 8 2 Array after ineration- 1-is3 7 8 2 Array after ineration- 2-is3 7 2 8Array after ineration- 3-is3 2 7 8 Array after ineration- 4-is2 3 7 8 The sorted array is shown below...2 3 7 8
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program19.cpp
2. PURPOSES OF FILE:-To delete an element in an array.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-1.24 k bytes.
5. FUNCTION USED:-Lsearch
6. BRIEF DESCRIPTION OF EACH FUNCTION: -Checks the element of an array with the element to be deleted.
7. DATA FILES USED:-
8. SAMPLE INPUT:-Array elements, Elements to be deleted.
9. SAMPLE OUTPUT: -The array after deletion.
10. APPLICATION OF THE PROGRAM:-To delete an unwanted element in an array.
ALGORITHM OF DELETION IN AN ARRAY
/*considering that ITEM's search in an array AR is successful at located pos*/
Case I: Shifting upwards (or in left side)/*Initialise counter*/
1. ctr=pos/*Shifting the elements leftwards or upwards*/
2. Repeat steps 3 and 4 until ctr>=u
3. AR[ctr]=AR[ctr+1]
4. ctr=ctr+1
/*End of Repeat*/
Case II: Shifting downwards (or in right side)/* for shifting towards right side or downwards*/
1. ctr=pos
2. Repeat steps 3 and 4 until ctr<=1
3. AR[ctr]=AR[ctr+1]
4. ctr=ctr-1
/*End of Repeat*/
//Program for Deletion in Array
#include<iostream.h>#include<conio.h>#include<process.h> int Lsearch(int[],int,int);void main(){
int AR[50],ITEM,N,index;clrscr();cout<<"How many elements do you want to create
array with? (max.50) ...";cin>>N;cout<<"\nEnter array elements (must be sorted in
ascending order)...\n";for(int i=0;i<N;i++){
cin>>AR[i];}char ch='y';while(ch=='y'||ch=='Y'){
cout<<"\nEnter elements to be deleted...";cin>>ITEM;if(N==0){
cout<<"Underflow!!\n";exit(1);
}index=Lsearch(AR,N,ITEM);if(index!=-1)AR[index]=0;else{
cout<<"\nSorry!! No such element in the array\n";
exit(1);}cout<<"\nThe array now is as shown below...\
n";cout<<"Zero (0) signifies deleted element\n";for(i=0;i<N;i++)cout<<AR[i]<<" ";cout<<endl;
cout<<"After this emptied space will be shifted to the end of array\n";
for(i=index;i<N;i++){
AR[i]=AR[i+1];}N-=1;cout<<"\n Want to delete more
elements?(y/n)...";cin>>ch;
}cout<<"The array after shifting ALL emptied spaces
towards right is...\n";for(i=0;i<N;i++)cout<<AR[i]<<" ";cout<<endl;
}
int Lsearch(int AR[],int size,int item){
for(int i=0;i<size;i++){
if(AR[i]==item)return i;
}return -1 ;
}
OUTPUT:
How many elements do you want to create array with?(max.50)...4Enter array elements (must be sorted in ascending order)...4 5 6 8 Enter elements to be deleted...
5The array is now shown belowZero (0) indicates deleted elementsAfter this emptied space will be shifted to the end of array4 0 6 7 Want to delete more elements?(y/n)...n
DOCUMENTATION
1. NAME OF THE SOURCE FILE:-program20.cpp
2. PURPOSES OF FILE:-To show insertion in the beginning of a list.
3. OPERATING SUSTEM USED:-xp
4. SIZE OF PROGRAM:-2.04 k bytes.
5. FUNCTION USED:-Insert-beg, display
6. BRIEF DESCRIPTION OF EACH FUNCTION: -Inserts element, display's the list.
7. DATA FILES USED:-
8. SAMPLE INPUT:-Enter information for new node.
9. SAMPLE OUTPUT: -The list after insertion.
10. APPLICATION OF THE PROGRAM:-To insert element in a list
11. ALGORITHM TO SHOW INSERTION IN BEGINNING OF A LIST
/*Initialize the pointer*/
1. ptr =Start //allocate memory for the new node
2. NEWPTR=new node
3. if NEWPTR=NULL //if sufficient memory is not available
4. print "No Space Available ! Aborting!!"
5. else
{6. NEWPTR->INFO=ITEM
7. NEWPTR->LINK=NULL
8. if START =NEWPTR
9. START = NEWPTR
10.else{
11. Save=START /*Save Start's value-Save is also a pointer*/
12. START = NEWPTR /*Assign NEWPTR to START*/
13. NEWPTR->LINK=Save /*Make NEWPTR point to previous Start*/
}}
14. END
//Program to insert a node in the beginning of a list.
#include<iostream.h>#include<conio.h>#include<process.h>struct Node{
int info;Node*next;
}*top,*newptr,*save,*ptr;Node*Create_New_Node(int);void Push(Node*);void Display(Node*);void main(){
int inf;char ch='y';top=NULL;clrscr();while(ch=='y'||ch=='Y'){
cout<<"\nEnter information for the new node...";
cin>>inf;cout<<"Creating new node !! Press enter to
continue";getch( );newptr=Create_New_Node(inf);if(newptr!=NULL){
cout<<"New node created successfully. press enter to continue"; getch( ); else
{ cout<<"\nCannot create new node!!!
Aborting!!\n"; getch( ); exit(1);
} cout<<"\n Now inserting this nobe in the
beginning of list"; cout<<"Press enter to continue"; getch(); Push(newptr); cout<<"\nNow the linked-stack is : :\n";
Display(top); cout<<"\nPress Y to enter more nodes,N to
exit..."; cin>>ch;}
}Node*Create_New_Node(int n){
ptr=new Node;ptr->info=n;ptr->next=NULL;return ptr;
}void Push(Node*np){
if(top==NULL)top=np;else{
save=top;top=np;np->next=save;
}}void Display(Node*np){
while(np!=NULL){
cout<<np->info<<"->";np=np->next;
}cout<<"!!!\n";
}
OUTPUT:-
Enter information for new node...Creating new node!! Press enter to continue.New node created successfully .press enter to continueNow inserting this node in the beginning of the list Press enter to continueNow the list ::5->!!!Press Y to enter more nodes, N to existN
SQL COMMANDS
COMMAND TO CREATE A TABLE Emp13 WITH 4 FIELDSEmpNo, EmpName, Job, Salary
SQL>CREATE TABLE Emp132 (EmpNo Number(4) NOT NULL PRIMARY KEY,3 EmpName Char(10),4 Job Char(10),5 Salary Number(7,2);
Table created.
COMMAND TO INSERT VALUES INTO THE TABLE Emp13
SQL>INSERT INTO Emp132 VALUES (&EmpNo,'&EmpName','&Job',&Salary);Enter value for EmpNo: 11Enter value for EmpName: AlokEnter value for Job: PresidentEnter value for Salary: 16000old 2: VALUES (&EmpNo,'&EmpName','&Job',&Salary);new 2: VALUES(11,'Alok','President',16000)
1 row created
SQL>INSERT INTO Emp132 VALUES (&EmpNo,'&EmpName','&Job',&Salary);Enter value for EmpNo: 22Enter value for EmpName: AmitEnter value for Job: ManagerEnter value for Salary: 12000old 2: VALUES (&EmpNo,'&EmpName','&Job',&Salary);new 2: VALUES(22,'Amit','Manager',12000)
1 row created
SQL>INSERT INTO Emp133 VALUES (&EmpNo,'&EmpName','&Job',&Salary);Enter value for EmpNo: 33Enter value for EmpName: BhanuEnter value for Job: Manager
Enter value for Salary: 12000old 2: VALUES (&EmpNo,'&EmpName','&Job',&Salary);new 2: VALUES(33,'Bhanu','Manager',12000)
1 row created
SQL>INSERT INTO Emp134 VALUES (&EmpNo,'&EmpName','&Job',&Salary);Enter value for EmpNo: 44Enter value for EmpName: NitinEnter value for Job: SalesmanEnter value for Salary: 10000old 2: VALUES (&EmpNo,'&EmpName','&Job',&Salary);new 2: VALUES(44,'Nitin','Salesman',10000)
1 row created
SQL>INSERT INTO Emp135 VALUES (&EmpNo,'&EmpName','&Job',&Salary);Enter value for EmpNo: 55Enter value for EmpName: NiteshEnter value for Job: SalesmanEnter value for Salary: 10000old 2: VALUES (&EmpNo,'&EmpName','&Job',&Salary);new 2: VALUES(55,'Nitesh','Salesman',10000)
1 row created
SQL>INSERT INTO Emp136 VALUES (&EmpNo,'&EmpName','&Job',&Salary);Enter value for EmpNo: 66Enter value for EmpName: VedEnter value for Job: AnalystEnter value for Salary: 14000old 2: VALUES (&EmpNo,'&EmpName','&Job',&Salary);new 2: VALUES(66,'Ved','Analyst',14000)
1 row created
SQL>INSERT INTO Emp137 VALUES (&EmpNo,'&EmpName','&Job',&Salary);Enter value for EmpNo: 77Enter value for EmpName: SagarEnter value for Job: Analyst
Enter value for Salary: 13000old 2: VALUES (&EmpNo,'&EmpName','&Job',&Salary);new 2: VALUES(77,'Sagar','Analyst',13000)
1 row created
QUERY1: To display the name of the employee whose salary is more than or equal to 14000.
SQL>SELECT EmpName2 FROM Emp133 WHERE Salary>=14000;OUTPUT:-
EMPNAME----------------AlokVed
QUERY2 : To display the name of the employee whose salary is more than or equal to 15000.
SQL>SELECT EmpName2 FROM Emp133 WHERE Salary>=15000;
OUTPUT:-
EMPNAME----------------Alok
QUERY 3: To display all the columns of Emp13
SQL>Select*FROM Emp13;
OUTPUT:-
EmpNo EmpName Job Salary---------- ---------------- -------- ------------
11 Alok President 1600022 Amit Manager 1200033 Bhanu Manager 1200044 Nitin Salesman 10000
55 Nitesh Salesman 1000066 Ved Analyst 1400077 Sagar Analyst 13000
7 rows selected.
Query 4: To display EmpNo,Job,EmpName in reverse order of Salary From Emp13
SQL>SELECT EmpNo,Job,EmpName 2 From Emp133 ORDER BY Salary DESC;
OUTPUT:-
EMPNO JOB EMPNAME----------- ----------------- ----------------
11 President Alok66 Analyst Ved77 Analyst Sagar22 Manager Amit33 Manager Bhanu44 Salesman Nitin55 Salesman Nitesh
7 rows selected.
QUERY 5: To find out the minimum salary from Emp13
SQL>SELECT MIN (Salary) FROM Emp13;
OUTPUT:-
MIN(SALARY)-----------------10000
QUERY 6: To find out the minimum and maximum salary from Emp13
SQL>SELECT MIN(Salary),MAX(Salary) FROM Emp13;
OUTPUT:-
MIN(SALARY) MAX(SALARY)----------------- -------------------
10000 16000
QUERY 7: Display all the EmpNo
SQL>SELECT EmpNo FROM Emp13;
OUTPUT:-
EMPNO--------------
11223344556677
8 rows selected.
QUERY 8: To change the salary of employee whose salary is more than or equal to 16000.
SQL>UPDATE Emp132 SET Salary=180003 WHERE Salary>=16000;
1 row updated.
QUERY 9: To display the name of the employee whose salary is more than 17000
SQL>SELECT EmpName2 FROM Emp133 Where Salary>17000l;
OUTPUT:EMPNAME-----------------Alok
QUERY 10: To insert a new row in Emp13 with the following data:
88,'Archana','Analyst',14500
SQL>INSERT INTO Emp132 VALUES (88,'Archana','Analyst',14500);
1 row created.
QUERY 11: To display EmpNo and EmpName whose salary is more than 12000 in descending order of EmpNo.
SQL>SELECT EmpNo,EmpName2 FROM Emp133 WHERE Salary>120004 ORDER BY EmpNo DESC;
OUTPUT:-
EMPNO EMPNAME------------ ----------------88 Archana77 Sagar66 Ved11 Alok
QUERY 12: To select Distinct salary from Emp13
SQL>SELECT DISTINCT Salary2 FROM Emp13;
OUTPUT:-
SALARY--------------
100001200013000140001450018000
6 rows selected.
QUERY 13: To delete a row having EmpNo=55.
SQL>DELETE FROM Emp13 WHERE EmpNo=55;
1 row deleted.
QUERY 14: To find the total of all the salary in Emp13
SQL>SELECT SUM(Salary) FROM Emp13;
OUTPUT:-
SUM(Salary)----------------
93500
QUERY 15: To display the name and EmpNo of Employee whose EmpNo>44.
SQL>SELECT EmpName,EmpNo2 FROM Emp133 WHERE EmpNo>44;
OUTPUT:-
EMPNAME EMPNO--------------- -----------
Ved 66Sagar 77Archana 88
BIBLIOGRAPHY
Book's name Author's nameComputer science with
C++ Sumita Arora
Turbo C++ Robert LaforeComputer science with
C++ Charu Gupta
Computer science with C++
Dr. P. B. Mahapatra