You are on page 1of 53

WAP to create an array and arrange in ascending order using Insertion Sort.

#include <iostream.h> #include<conio.h> void insertion_sort(int x[],int length) { int key,i; for(int j=1;j<length;j++) { key=x[j]; i=j-1; while(x[i]>key && i>=0) { x[i+1]=x[i]; i--; } x[i+1]=key; } } int main() { clrscr(); int A[25]; int size,i; int x; cout<<"Enter size of array: "; cin>>size; cout<<"Enter numbers: "; for(x=0;x<size;x++) { cin>>A[x]; } cout<<"NON SORTED LIST: "<<endl; for(x=0;x<size;x++) { cout<<A[x]<<endl; }

insertion_sort(A,size); cout<<endl<<"SORTED LIST: "<<endl; for(x=0;x<size;x++) { cout<<A[x]<<endl; } getch(); return 0; }

OUTPUT:Enter size of array: 5 Enter numbers: 9 2 6 4 1 NON SORTED LIST: 9 2 6 4 1 SORTED LIST: 1 2 4 6 9

WAP to create an array of strings and sort them in ascending order using Bubble Sort.
#include<iostream.h> #include<conio.h> #include<string.h> main() { clrscr(); char *c,*st[]={"Pink","Orange","Black"}; cout<<"\n Original string: "; for(int i=0;i<3;i++) { cout<<"\n"<<st[i]<<"\n"; } for(int j=0;j<3;j++) { for(int i=0;i<2;i++) { if(strcmp(st[i],st[i+1])>0) { cout<<"\n\n\n"; cout<<st[i]<<" is greater than "<<st[i+1]<<"\n"; c=st[i]; cout<<"\n c= "<<c<<"\n"; st[i]=st[i+1]; cout<<"\n After copying: "; st[i+1]=c; cout<<st[i]<<" "<<st[i+1]<<"\n"; } } cout<<"\n Sorted array: \n"; for(i=0;i<3;i++) {cout<<st[i]<<endl;} } getch(); }

OUTPUT:Original string: Pink Orange Black Pink is greater than Orange c= Pink After copying: Orange Pink Pink is greater than Black c= Pink After copying: Black Pink Sorted array: Orange Black Pink Orange is greater than Black c=Orange After copying: Black Orange Sorted array: Black Orange Pink

WAP to create an array of numbers and search for a number using Linear Search.
#include<iostream.h> #include<conio.h> int Lsearch(int[],int,int); void main() { clrscr(); int ar[10],item,n,index; cout<<"\n Enter desired array size(max.10): "; cin>>n; cout<<"\n Enter array elements: \n"; for(int i=0;i<n;i++) { cin>>ar[i]; } cout<<"\n Enter element to be searched for: "; cin>>item; index=Lsearch(ar,n,item); if(index==-1) cout<<"\n SORRY given element could not be found; else cout<<"\n Element found at"<<"\n Index:"<<index <<"\n Position:"<<index+1; getch(); } 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.10): 5 Enter array elements: 1 2 3 4 5 Enter element to be searched for: 3 Element found at Index:2 Position:3

WAP to create an array of numbers and search for a number using Binary Search.
#include<iostream.h> #include<conio.h> main() { clrscr(); int x[10],item,top=0,bot=9,mid,f=0; cout<<"\n Enter the array: "; for(int i=0;i<10;i++) { cin>>x[i]; } cout<<"\n Enter the number to be searched: "; cin>>item; while((top<=bot)&&(f==0)) { mid=(top+bot)/2; if(x[mid]==item) f=1; else if(x[mid]<item) bot=mid-1; else if(x[mid]>item) top=mid+1; } if(f==1) cout<<"\n <<item<< is found in the array "; else if(f==0) cout<<"\n <<item<< is not found in the array "; }

OUTPUT 1:Enter the array: 1 2

3 4 5 6 7 8 9 10 Enter the number to be searched: 2 2 is found in the array

OUTPUT 2:Enter the array: 1 2 3 4 5 6 7 8 9 10 Enter the number to be searched: 11 11 is not found in the array

WAP to merge two sorted arrays into third.


#include<iostream.h> #include<conio.h> main() { clrscr(); cout<<"\t\t\t\t MERGE SORT"; int a[5]={10,9,8,7,6}, b[5]={5,4,3,2,1}; int c[10]; int a1=4,b1=4,c1=0; while((a1>=0) && (b1>=0)) { if(a[a1]<b[b1]) { c[c1]=a[a1]; a1--; c1++; } else { c[c1]=b[b1]; b1--; c1++; } } if(b1<0) { while(a1>=0) { c[c1]=a[a1]; a1--; c1++; } } else

if(a1<0) { while(b1>=0) { c[c1]=b[b1]; b1--; c1++; } } cout<<"\n\n\n\t THE SORTED ARRAY: "; for(int i=0;i<10;i++) { cout<<endl<<"\t"<<c[i]; } getch(); }

OUTPUT:MERGE SORT THE SORTED ARRAY: 1 2 3 4 5 6 7 8 9 10

WAP to create a text file life.txt and count the number of vowels in it.
#include<fstream.h> #include<conio.h> #include<stdio.h> #include<string.h> main() { clrscr(); char to[10]; ofstream ofile("life.txt"); cout<<"\n Enter you name: "; cin.getline(to,10,'.'); ofile<<to; ofile.close(); ifstream ifile("life.txt"); int ct=0; char c; while(!ifile.eof()) { c=ifile.get(); if((c=='a') || (c=='e') || (c=='i') || (c=='o') || (c=='u') || (c=='A') || (c=='E') || (c=='I') || (c=='O') || (c=='U')) { ct++; } } cout<<"\n No. of vowels: "<<ct; ifile.close(); getch(); }

OUTPUT:Enter you name: sugAndha. No. of vowels: 3

WAP to check whether a string is a palindrome or not using pointers.


#include<iostream.h> #include<conio.h> #include<string.h> main() { clrscr(); char ch[20],cha; int x,j; cout<<"\t\t\t CHECK FOR PALINDROME"; k: cout<<"\n\n\n\t\t\t Enter the word: "; cin>>ch; x=strlen(ch); int y=x,i=1; char *c=ch; for(x,j=0;x>=0;x--,i++,c++) { if(*c==*(c+x-i)) { j++; } } if(j==y) { cout<<"\n\n\n\n\t\t It is a palindrome"; } else { cout<<"\n\n\n\n\t\t It is not a palindrome"; } cout<<"\n\n\t\t Check more...(y/n)? "; cin>>cha; if((cha=='y') || (cha=='Y')) { goto k; } getch(); }

OUTPUT:CHECK FOR PALINDROME

Enter the word: madam

It is a palindrome Check more...(y/n)? y

Enter the word: sugandha

It is not a palindrome Check more...(y/n)? n

WAP to insert an item at a particular position.


#include<iostream.h> #include<conio.h> main() { clrscr(); int x[5],k,j,m; cout<<"\n\n Enter the 'k'th position where a no. has to be inserted: "; cin>>k; cout<<"\n\n Enter the no. to be inserted: "; cin>>m; cout<<"\n\n Enter the array in which no. has to be inserted: "; for(int i=0;i<5;i++) { cin>>x[i]; } for(i=0;i<5;i++) { if(i>=(k-2)) { j=m; m=x[i+1]; x[i+1]=j; } } cout<<"\n The new array after insertion of no. is: for(i=0;i<6;i++) { cout<<x[i]; } getch(); }

";

OUTPUT 1 :-

Enter the 'k'th position where a no. has to be inserted: 3 Enter the no. to be inserted: 2 Enter the array in which no. has to be inserted: 1 2 3 4 5 The new array after insertion of no. is: 122345

OUTPUT 2 :Enter the 'k'th position where a no. has to be inserted: 5 Enter the no. to be inserted: 1 Enter the array in which no. has to be inserted: 1 2 3 4 5 The new array after insertion of no. is: 123415

WAP to delete an item from a particular position.


#include<iostream.h> #include<conio.h> main() {

clrscr(); int x[5],k,j; cout<<"\n\n Enter 'k'th position from where a no. is to be deleted: "; cin>>k; cout<<"\n\n Enter the array from which no. has to be deleted: "; for(int i=0;i<5;i++) { cin>>x[i]; } for(i=0;i<5;i++) { if(i>=(k-1)) { j=x[i+1]; x[i]=j; } } cout<<"\n The new array after deletion of no. is: "; for(i=0;i<4;i++) { cout<<x[i]; getch(); } }

OUTPUT 1:-

Enter 'k'th position from where a no. is to be deleted: 3 Enter the array from which no. has to be deleted: 1 2 3 4 5 The new array after deletion of no. is: 1245

OUTPUT 2:-

Enter 'k'th position from where a no. is to be deleted: 2 Enter the array from which no. has to be deleted: 1 2 3 4 5 The new array after deletion of no. is: 1345

WAP to show all types of constructors.


#include<iostream.h> #include<conio.h> #include<stdio.h> class try1 { int x; public: try1() { x=0; cout<<"\n Default constructor invoked"; } try1(int y) { x=y; cout<<"\n Parameterised constructor invoked"; } try1(try1 &t) { x=t.x; cout<<"\n Copy constructor invoked"; } void show() { cout<<"\n Value of x: "<<x; } }; main() { clrscr(); try1 t1,t2(15); try1 t3=t2; t1.show(); t2.show(); t3.show(); getch(); }

OUTPUT:-

Default constructor invoked Parameterised constructor invoked Copy constructor invoked Value of x: 0 Value of x: 15 Value of x: 15

WAP to implement stacks using arrays.


#include<iostream.h> #include<conio.h> #include<process.h> const int size=5; int push(int stack[],int&top,int ele) { if(top==size-1) return -1; else { top++; stack[top]=ele; } return 0; } int pop(int stack[],int &top) { int ret; if(top==-1) return -1; else { ret=stack[top]; top--; } return ret; } void display(int stack[],int top) { if(top==-1) return; cout<<stack[top]<<"<--"; for(int i=top-1;i>=0;i--) cout<<stack[i];

} void main() { clrscr(); int stack[size],item,top=-1,res; char ch='y'; while(ch=='y') { cout<<"\n Enter item for insertion: "; cin>>item; res=push(stack,top,item); if(res==-1) { cout<<"\n Overflow!!!"; exit(1); } cout<<"\n The stack is: "; display(stack,top); cout<<"\n Want to insert more elements? "; cin>>ch; } cout<<"\n Now deletion..\n"; ch='y'; while(ch=='y') { res=pop(stack,top); if(res==-1) { cout<<"\n Underflow"; exit(1); } else { cout<<"\n Element deleted is: "<<res; cout<<"\n The stack is now: \n"; display(stack,top); } cout<<"\n Want to delete more: "; cin>>ch; } }

OUTPUT:Enter item for insertion: 1 The stack is: 1<--

Want to insert more elements? y Enter item for insertion: 2 The stack is: 2<--1 Want to insert more elements? n Now deletion... Element deleted is: 2 The stack is now: 1<-Want to delete more: y Element deleted is: 1 The stack is now: Want to delete more: n

WAP to implement stacks using linked list.


#include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> #include<ctype.h> struct cust { int cno; char cname[20]; cust*next; }*top;*p; void push() { cust *p; p=new cust; cout<<"\n Enter roll no.: ; cin>>p->cno; cout<<"\n Enter name: "; gets(p->cname); p->next=NULL; if(top==NULL) { top=p; } else { p->next=top; top=p; } }

void pop() { if(top==NULL) { cout<<"\n Underflow"; } else { cust *p=top; top=top->next; cout<<"\n Item to be deleted: "; cout<<(p->cno); delete p; } } void disp() { cust *p=top; while(p!=NULL) { cout<<"\n Roll No.: "<<p->cno; cout<<"\n Name: "<<p->cname; p=p->next; } } main() { clrscr(); char h; do{ cout<<"\n 1. Push item in stacks"; cout<<"\n 2. Pop item from stacks"; cout<<"\n 3. Display item from stacks \n; int ch; cin>>ch;

switch(ch) { case 1: cout<<"\n Push function is called"; push(); break; case 2: cout<<"\n Pop function is called"; pop(); break; case 3: cout<<"\n Display function is called"; disp(); break; } cout<<"\n Do you want to continue?"; cin>>h; }while(toupper(h)=='Y'); getch(); }

OUTPUT:1. Push item in stacks 2. Pop item from stacks 3. Display item from stacks 1 Push function is called Enter roll no.: 1 Enter name: anushka

Do you want to continue?y 1. Push item in stacks 2. Pop item from stacks 3. Display item from stacks 1 Push function is called Enter roll no.: 2 Enter name: sugandha Do you want to continue?y 1. Push item in stacks 2. Pop item from stacks 3. Display item from stacks 2 Pop function is called Item to be deleted:2 Do you want to continue?y 1. Push item in stacks 2. Pop item from stacks 3. Display item from stacks 3 Display function is called Roll No.: 1 Name: anushka Do you want to continue?y 1. Push item in stacks 2. Pop item from stacks 3. Display item from stacks 2 Pop function is called Item to be deleted: 1 Do you want to continue?y 1. Push item in stacks 2. Pop item from stacks

3. Display item from stacks 3 Display function is called Do you want to continue?y 1. Push item in stacks 2. Pop item from stacks 3. Display item from stacks 2 Pop function is called Underflow Do you want to continue?y 1. Push item in stacks 2. Pop item from stacks 3. Display item from stacks 1 Push function is called Enter roll no.: 1 Enter name: anushka Do you want to continue?y 1. Push item in stacks 2. Pop item from stacks 3. Display item from stacks 3 Display function is called Roll No.: 1 Name: anushka Do you want to continue?t

WAP to implement queues using arrays.


#include<iostream.h> #include<conio.h> #include<math.h> #include<process.h> const int size=50; int queue[size],front=-1,rear=-1; int insert(int queue[],int ele) { if(rear==size-1) return -1; else if(rear==-1) { front=rear=0; queue[rear]=ele; } else { rear++; queue[rear]=ele; } return 0; } int remove(int queue[]) { int ret; if(front==-1) return -1; else { ret=queue[front];

if(front==rear) front=rear=-1; else front++; } return ret; } void display(int queue[],int front,int rear) { if(front==-1)return; for(int i=front;i<rear;i++) cout<<queue[i]<<"<-\t"; cout<<queue[rear]; } void main() { int item,res; char ch='y'; clrscr(); while(ch=='y'||ch=='Y') { cout<<"\n Enter item for insertion: "; cin>>item; res=insert(queue,item); if(res==-1) { cout<<"Overflow"; exit(1); } cout<<"\n Now the queue( front to rear) is: \n"; display(queue,front,rear); cout<<"\n Want to insert more(y/n): "; cin>>ch; } cout<<"\n Deletion of item..."; ch='y'; while(ch=='y') {

res=remove(queue); if(res==-1) { cout<<"\n Underflow"; } else { cout<<"\n Element deleted is: "<<res; cout<<"\n Now the queue(front...to...rear)is: \n"; display(queue,front,rear); } cout<<"\n Want to delete more?"; cin>>ch; } }

OUTPUT:Enter item for insertion: 1 Now the queue( front to rear) is: 1 Want to insert more(y/n): Y Enter item for insertion: 2 Now the queue( front to rear) is: 1<- 2 Want to insert more(y/n): N Deletion of item... Element deleted is: 1 Now the queue(front...to...rear)is: 2 Want to delete more?N

WAP to implement queues using linked list.


#include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> #include<ctype.h> struct stu { int rno; stu *next; }*front=NULL,*rear=NULL,*p=NULL; void insert() { p=new stu; cout<<"\n Enter roll no. "; cin>>p->rno; p->next=NULL; if((front==NULL) && (rear==NULL)) { front=p; rear=p; } else { rear->next=p; rear=p; } } void del() { if((front==NULL) && (rear==NULL))

{ cout<<"\n Underflow"; } else if(rear==front) { delete front; front=rear=NULL; } else { p=front; front=front->next; delete p; } } void disp() { stu *p=front; while(p!=NULL) { cout<<"\n Roll No.: "<<p->rno; p=p->next; } } main() { clrscr(); front=NULL; char c,h; do{ cout<<"\n 1. Enter item in queues"; cout<<"\n 2. Delete item from queues"; cout<<"\n 3. Display item from queues \n"; int ch;

cin>>ch; switch(ch) { case 1: cout<<"\n Insert function is called"; push(); break; case 2: cout<<"\n Del function is called"; pop(); break; case 3: cout<<"\n Display function is called"; disp(); break; } cout<<"\n Do you want to continue?"; cin>>h; }while(toupper(h)=='Y'); getch(); }

OUTPUT:1. Enter item in queues 2. Delete item from queues 3. Display item from queues 1 Insert function is called Enter roll no. 1 Do you want to continue?y 1. Enter item in queues

2. Delete item from queues 3. Display item from queues 1 Insert function is called Enter roll no. 2 Do you want to continue?y 1. Enter item in queues 2. Delete item from queues 3. Display item from queues 2 Del function is called Do you want to continue?y 1. Enter item in queues 2. Delete item from queues 3. Display item from queues 3 Display function is called Roll No.: 2 Do you want to continue?y 1. Enter item in queues 2. Delete item from queues 3. Display item from queues 2 Del function is called Do you want to continue?y 1. Enter item in queues 2. Delete item from queues 3. Display item from queues 2 Del function is called Underflow Do you want to continue?y 1. Enter item in queues 2. Delete item from queues

3. Display item from queues 1 Insert function is called Enter roll no. 1 Do you want to continue?y 1. Enter item in queues 2. Delete item from queues 3. Display item from queues 1 Insert function is called Enter roll no. 2 Do you want to continue?y 1. Enter item in queues 2. Delete item from queues 3. Display item from queues 3 Display function is called Roll No.: 1 Roll No.: 2 Do you want to continue?t

WAP to implement circular queues using arrays.


#include<iostream.h> #include<conio.h> #include<stdlib.h> class cqueue { int q[5],front,rare; public: cqueue() { front=-1; rare=-1; } void push(int x) { if(front ==-1 && rare == -1) { q[++rare]=x; front=rare; return; } else if(front == (rare+1)%5 ) { cout <<" Circular Queue over flow"; return; } rare= (rare+1)%5; q[rare]=x; } void pop() { if(front==-1 && rare==-1) { cout <<"under flow";

return; } else if( front== rare ) { front=rare=-1; return; } front= (front+1)%5; } void display() { int i; if( front <= rare) { for(i=front; i<=rare;i++) cout << q[i]<<" "; } else { for(i=front;i<=4;i++) { cout <<q[i] << " "; } for(i=0;i<=rare;i++) { cout << q[i]<< " "; } } } };

main() { int ch; cqueue q1; while( 1) {

cout<<"\n 1.INSERT; cout<<\n 2.DELETE; cout<<\n 3.DISPLAY; cout<<\n 4.EXIT; cout<<\n Enter ur choice: "; cin >> ch; switch(ch) { case 1: cout<<"\n Enter element: "; cin>>ch; q1.push(ch); break; case 2: q1.pop(); break; case 3: q1.display(); break; case 4: exit(0); } } }

OUTPUT:1.INSERT 2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 1 Enter element: 1 1.INSERT

2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 1 Enter element: 2 1.INSERT 2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 1 Enter element: 3 1.INSERT 2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 1 Enter element: 4 1.INSERT 2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 1 Enter element: 5 1.INSERT 2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 1 Enter element: 6 Circular Queue over flow 1.INSERT 2.DELETE 3.DISPLAY

4.EXIT Enter ur choice: 3 12345 1.INSERT 2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 2 1.INSERT 2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 3 2345 1.INSERT 2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 2 1.INSERT 2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 3 345 1.INSERT 2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 1 Enter element: 6 1.INSERT 2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 1 Enter element: 7

1.INSERT 2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 3 34567 1.INSERT 2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 2 1.INSERT 2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 2 1.INSERT 2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 3 567 1.INSERT 2.DELETE 3.DISPLAY 4.EXIT Enter ur choice: 4

WAP to read and write using files.


#include<fstream.h> #include<conio.h> #include<string.h> struct customer { char name[20]; float balance; }; main() { clrscr(); customer savac; strcpy(savac.name,"Sugandha Priya"); savac.balance=20000; ofstream fout; fout.open("Saving",ios::out|ios::binary); if(!fout) { cout<<"\n File cant be opened"; 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<<" has balance amount: "<<savac.balance; fin.close(); getch(); }

OUTPUT:-

Sugandha Priya has balance amount: 20000

WAP to create pattern of stars as shown:* *** ***** *** * #include<iostream.h> #include<conio.h> main() { clrscr(); for(int i=0;i<5;i++) { for(int j=0;j<i;j++) { cout<<"*"; } cout<<"*"<<endl; } }

OUTPUT:* *** ***** *** *

WAP to append data in a file.


#include<fstream.h> #include<conio.h> #include<stdio.h> class stu { int rollno; char name[25]; char cls[4]; float marks; char grade; public: void getdata() { clrscr(); cout<<"\n Enter your rollno:"; cin>>rollno; cout<<"\n Enter your name:"; gets(name); cout<<"\n Enter your class:"; cin>>cls; cout<<"\n Enter your marks:"; cin>>marks; }

void putdata() { clrscr(); cout<<"\n Name: "<<name<<"\n Rollno: "<<rollno<<"\n Class: "<<cls <<"\n Marks in comp. sci.: "<<marks;

} int getrno() { return rollno; } }s1; void main() { clrscr(); ofstream fo("stu.dat",ios::app); char ans='y'; while(ans=='y') { s1.getdata(); fo.write((char*)&s1,sizeof(s1)); cout<<"\n Record added to file."; cout<<"\n Want to enter more records?(y/n).."; cin>>ans; s1.putdata(); } fo.close(); getch(); }

OUTPUT:Enter your rollno:1 Enter your name: SUGANDHA Enter your class: 12

Enter your marks: 70 Record added to file. Want to enter more records?(y/n).. n Name: SUGANDHA Rollno: 1 Class: 12 Marks in comp. sci.: 70

WAP to implement multilevel inheritance.


#include<iostream.h> #include<conio.h> #include<string.h> #include<stdio.h> class salary { float basic,hra,da,cca,tax,netsalary; void entsal() { cout<<"\n Enter the basic salary: "; cin>>basic; cout<<"\n Enter the hra: "; cin>>hra; cout<<"\n Enter The da: "; cin>>da; cout<<"\n Enter the cca: "; cin>>cca; cout<<"\n Enter the tax: "; cin>>tax; } public: int calcsal() { netsalary=(basic+hra+da+cca-tax); } void showsal() {

entsal(); calcsal(); cout<<"\n Basic salary: "<<basic; cout<<"\n HRA value: "<<hra; cout<<"\n DA value: "<<da; cout<<"\n CCA value: "<<cca; cout<<"\n Tax: "<<tax; cout<<"\n Net salary: "<<netsalary; } }; class employee:protected salary { int eno; char ename[20]; char designation[20]; public: void entemp() { cout<<"\n Enter employee no.: "; cin>>eno; cout<<"\n Enter employee name: "; gets(ename); cout<<"\n Enter the designation of the employee: "; gets(designation); } void showemp() { cout<<"\n Employee no.: "<<eno; cout<<"\n Employee name: "; puts(ename);

cout<<"\n Employee designation: "; puts(designation); showsal(); } }; main() { clrscr(); employee e1; e1.entemp(); e1.showemp(); getch(); }

OUTPUT:Enter employee name: sugandha Enter the designation of the employee: manager Employee no.: 1 Employee name: sugandha Employee designation: manager Enter the basic salary: 30000 Enter the hra: 1500 Enter The da: 250 Enter the cca: 350 Enter the tax: 2300

Basic salary: 30000 HRA value: 1500 DA value: 250 CCA value: 350 Tax: 2300 Net salary: 29800

15 SQL commands.
CREATING TABLE:create table student (adno integer primary key, sname varchar(20) not null, class number, rollno number unique, fees integer check fees<11000 and fees>8000, city varchar(20));

INSERTING VALUES:insert into student values(1,Anil,10,1,10500,Mumbai); insert into student values(2,Ashish,10,2,9800,Delhi); insert into student values(3,Ashwini,10,3,9900,Kolkata); insert into student values(8,Jia,11,5,10800,Mumbai); insert into student values(9,Khushboo,12,6,9200,Delhi); insert into student values(23,Sugandha,12,17,8100,Delhi);

VIEWING FULL TABLE:select * from student;

VIEWING SELECTED TABLE :select * from student where fees>=9500;

GROUP BY CLAUSE:select * from student group by city;

LIKE CLAUSE:select fees from student where sname like As%;

ORDER BY CLAUSE:select * from student

order by sname desc;

MAX() FUNCTION:select max(fees) from student;

SUM() FUNCTION:select sum(fees) from student;

AVG() FUNCTION:select avg(fees) from student;

ADDING NEW FIELD:alter table student add school varchar(20) not null;

UPDATING FIELD VALUE:update class set class=class+1 where name like An%;

MODIFYING RECORD:update table student set city=mumbai where(class=12 or class=10);

COUNT() FUNCTION & GROUP BY CLAUSE:select city,count(city) from student group by city;

CREATING VIEW OF TABLE:create view stu

select * from student;

UPDATING VIEW:update stu set fees=fees+200;

COUNT() FUNCTION:select count(sname) from student;

You might also like