Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
:
Q: To create table staff and salary & design the given constraints?
A: Input
SQL> create table staff_table 2 ( 3 id number(3) primary key, 4 name char(30) not null, 5 department char(15) check(department in('sales','finance','research')), 6 gender char(1) check(gender in('M','F')), 7 expirience number(2) not null 8 );
Table created.
SQL> create table salary 2 ( 3 id number(3) references staff_table(id), 4 basic number(4) check(basic>1000), 5 allowence number(4) check(allowence>500), 6 commision number(2) check(commision in(5,10,15,20)) 7 );
1 row created.
1 row created.
1 row created.
2 values(103,4546,655,5);
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
A: Output
SQL> describe staff_table Name Null? Type
----------------------------------------- -------- ---------------------------ID NAME DEPARTMENT GENDER EXPIRIENCE NOT NULL NOT NULL NOT NULL NUMBER(3) CHAR(30) CHAR(15) CHAR(1) NUMBER(2)
---------- ------------------------------ --------------- - ------------------------101 Mayank 102 sdfgjh 103 dhsgfh 104 jhdgfj research sales finance sales M F M F 13 4 8 10
---------- ---------- ---------- ---------101 102 103 104 9999 6567 4546 3657 8765 5470 655 654 20 5 5 10 6
SQL> select id,name from staff_table where expirience>5; ID NAME ---------- -----------------------------101 Mayank 103 dhsgfh
104 jhdgfj
Q: To create table items & trans & design the given constraints?
A: Input
SQL> create table items 2 ( 3 itemno number(3) primary key, 4 name char(15) not null, 5 Qoh number(5) not null, 6 price number(7) check(price>1000) 7 );
Table created.
SQL> create table trans 2 ( 3 itemno number(3) references items(itemno), 4 transtype char(1) check(transtype in('p','s')), 5 tqty number(3) not null, 6 tdate date not null 7 );
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
A: Output
SQL> set linesize 120; SQL> select * from items,trans 2 ;
ITEMNO NAME
QOH
---------- --------------- ---------- ---------- ------------- - ---------- --------100 shoes 100 shoes 100 shoes 101 101 101 pen drive pen drive pen drive 2500 2500 2500 1334 1334 1334 1000 1000 1000 3400 3400 3400 1001 1001 1001 4500 4500 4500 100 101 102 100 101 102 100 101 102 s p s s p s s p s 2 5 6 2 5 6 2 5 6 24-MAR-12 02-FEB-12 19-APR-12 24-MAR-12 02-FEB-12 19-APR-12 24-MAR-12 02-FEB-12 19-APR-12
9 rows selected.
10
Q: To create table sender & recipient & design the given constraints?
A: Input
SQL> create table sender 2 ( 3 senderid char(4) primary key, 4 sname char(30) not null, 5 saddr char(30) not null, 6 scity char(10) check(scity in('new delhi','mumbai')) 7 );
Table created.
SQL> create table recipient 2 ( 3 recid char(4) primary key, 4 senderid char(4) references sender(senderid), 5 recname char(30) not null, 6 recaddr char(30) not null, 7 reccity char(10) check(reccity in('kolkata','new delhi','mumbai')) 8 );
Table created.
11
1 row created.
1 row created.
1 row created.
1 row created.
12
1 row created.
1 row created.
1 row created.
1 row created .
A: Output
SNAME 13
SEND SNAME
SADDR
SCITY
---- ------------------------------ ------------------------------ ---------nd01 R jain mu02 H sinha mu15 S haj nd50 T prasad 2,abc appts 12,newton 27/a,park street 122-k,sda new delhi mumbai new delhi mumbai
RECADDR
RECCITY
---- ---- ------------------------------ ------------------------------ ---------ko05 nd01 R bajpayee nd08 mu02 S mahajan mu19 nd01 H sing mu32 mu15 P K swami nd48 nd50 S tirpathi 5,central avenue 116, A vihar 2A andheru west B5,CS terminus 13,B1 D,mayur vihar kolkata new delhi mumbai mumbai new delhi
14
RECI SNAME
SADDR
RECNAME
RECADDR
---- ------------------------------ ------------------------------ ------------------------------ -ko05 R jain nd08 R jain mu19 R jain mu32 R jain nd48 R jain ko05 H sinha nd08 H sinha mu19 H sinha mu32 H sinha nd48 H sinha ko05 S haj 2,abc appts 2,abc appts 2,abc appts 2,abc appts 2,abc appts 12,newton 12,newton 12,newton 12,newton 12,newton 27/a,park street R bajpayee S mahajan H sing P K swami S tirpathi R bajpayee S mahajan H sing P K swami S tirpathi R bajpayee 5,central avenue 116, A vihar 2A andheru west B5,CS terminus 13,B1 D,mayur vihar 5,central avenue 116, A vihar 2A andheru west B5,CS terminus 13,B1 D,mayur vihar 5,central avenue
RECI SNAME
SADDR
RECNAME
RECADDR
---- ------------------------------ ------------------------------ ------------------------------ -nd08 S haj mu19 S haj mu32 S haj nd48 S haj ko05 T prasad 27/a,park street 27/a,park street 27/a,park street 27/a,park street 122-k,sda S mahajan H sing P K swami S tirpathi R bajpayee 116, A vihar 2A andheru west B5,CS terminus 13,B1 D,mayur vihar 5,central avenue
15
20 rows selected
SQL> set linesize 205; SQL> select recid,sname,saddr,recname,recaddr from sender,recipient where sender.senderid=recipient. senderid;
RECI SNAME
SADDR
RECNAME
RECADDR
---- ------------------------------ ------------------------------ ------------------------------ -ko05 R jain nd08 H sinha mu19 R jain mu32 S haj nd48 T prasad 2,abc appts 12,newton 2,abc appts 27/a,park street 122-k,sda R bajpayee S mahajan H sing P K swami S tirpathi 5,central avenue 116, A vihar 2A andheru west B5,CS terminus 13,B1 D,mayur vihar
SEND SNAME
SADDR
SCITY
16
COUNT(*) ---------1 2 2
SQL> select sname,recname from sender,recipient where sender.senderid=recipient.senderid and reccity ='mumbai'; SNAME RECNAME
17
S haj
P K swami
CLASSES:
Q:1) Define a class flight with following description;
int - flightno string dest float dof, fuel. A function feed info to allow users to enter value for all data members & a function to show delayed flights?
#include<iostream.h> #include<string.h> #include<conio.h> #include<stdio.h> class competition{ int eventno,score; char qual,desc[30]; public: competition() { eventno=101; strcpy(desc,"state level"); score=50; qual='n'; }
18
void input() { cout<<"enter event number: "; cin>>eventno; cout<<"enter score: "; cin>>score; cout<<"enter description: "; gets(desc); } void award(int score) { if(score>50) qual='y'; else if(score<50) qual='N'; } void show() { award(score); cout<<endl<<endl<<eventno<<endl<<desc<<endl<<score<<endl<<qual; } };
void main() {
19
20
gets(dest); cout<<"enter distance of flight: "; cin>>dof; cout<<"enter fuel: "; cin>>fuel; } void delayedflights() { cout<<"delayed flights going to respective destinations are:"; cout<<flightno<<dest; } void showdata() { cout<<flightno<<endl<<dof<<endl<<dest<<endl<<fuel; } };
22
23
FILES:
#include<iostream.h> #include<fstream.h> #include<conio.h> #include<string.h> #include<stdio.h> #include<stdlib.h> class IPL { int team_no; char team_name[30]; char coach_name[20]; int team_points; public: void getdata(); void displaydata(); char * returnteamname() { return team_name; } int returnteamno() { return team_no; } };
24
void IPL::getdata() { clrscr(); cout<<"\n Team Number:";cin>>team_no; cout<<"\n Team name:";gets(team_name); cout<<"\n Coach name:";gets(coach_name); cout<<"\n Team points:";cin>>team_points; } void IPL::displaydata() { cout<<team_no<<"\t\t"<<team_name<<"\t\t"<<coach_name<<"\t\t"<<team_points<<"\n"; }
//independent functions to work with file void write_file() { fstream fl("ipl.dat",ios::app,ios::binary); IPL ip; ip.getdata(); fl.write((char *)&ip,sizeof(ip)); fl.close(); } void read_file() { fstream fl("ipl.dat",ios::in,ios::binary); IPL ip;
25
clrscr(); cout<<"Team No \t Team name \t Coach Name \t Team points\n"; while(!fl.eof()) { fl.read((char*)&ip,sizeof(ip)); if(fl.eof()) break; ip.displaydata(); } fl.close(); getch(); } void search_file() { fstream fl("ipl.dat",ios::in,ios::binary); IPL ip; char nm[30]; cout<<"\n Enter Team Name \n"; gets(nm); while(!fl.eof()) { fl.read((char *)&ip,sizeof(ip)); if(fl.eof()) break; if (strcmpi(nm,ip.returnteamname())==0) { ip.displaydata();
26
break; } } getch(); fl.close(); } void delete_file() { fstream fl1("ipl.dat",ios::in,ios::binary); fstream fl2("temp.dat",ios::out,ios::binary); IPL ip; int tno; cout<<"\n Enter Team No."; cin>>tno; while(!fl1.eof()) { fl1.read((char *)&ip,sizeof(ip)); if(fl1.eof()) break; if(ip.returnteamno()!=tno) { fl2.write((char *)&ip,sizeof(ip)); } } fl1.close(); fl2.close(); remove("ipl.dat");
27
rename("temp.dat","ipl.dat"); } void update_file() { fstream fl("ipl.dat",ios::in|ios::out,ios::binary); IPL ip; int tno; long x; cout<<"Enter Team Number"; cin>>tno; while(!fl.eof()) { x=fl.tellg(); fl.read((char *)&ip,sizeof(ip)); if (fl.eof()) break; if (tno==ip.returnteamno()) { fl.seekp(x,ios::beg); ip.getdata(); fl.write((char *)&ip,sizeof(ip)); break; } } fl.close(); } void box()
28
{ clrscr(); int i=0; int j=0; textcolor(CYAN); for(i=0;i<50;i++) { for(j=0;j<80;j++) { gotoxy(j,i); cprintf(""); } } } void main() { clrscr(); int ch=0; while(ch!=6) { clrscr(); box(); gotoxy(25,5); cout<<"IPL Information System"; gotoxy(10,10); cout<<"1. Insert Record"; gotoxy(10,11);
29
cout<<"2. Read Record"; gotoxy(10,12); cout<<"3. Modify Record"; gotoxy(10,13); cout<<"4. Delete Record"; gotoxy(10,14); cout<<"5. Search Record"; gotoxy(10,15); cout<<"6. EXIT"; gotoxy(10,18); cout<<"Your Ch.........(1-5)"; cin>>ch; switch(ch) { case 1: write_file();break; case 2: read_file();break; case 3: update_file();break; case 4: delete_file();break; case 5: search_file();break; } } }
30
Main Screen
Entering Record
31
Reading Record
Modifying Record
32
Modifying Final
Deleting Record
33
Deleting Final
Searching Record
34
POINTERS:
Q: Program to find the occurrence of character in the string
#include<iostream.h> #include<string.h> #include<conio.h> # include <stdio.h> class strn { char *a; char ch; int i; public: void read(); void find(); }; //END OF CLASS void strn::read() { cout << "\n\tThe number of times "<< ch << " occur in " << a << " is " << count; } void main() { clrscr(); strn x; cout << "\n\n\n\t "; x.read(); x.find(); getch(); };
35
cout << "\n\t"; cout << "\n\tEnter the first string "; gets(a); } void strn::find() { i = 0; int count = 0; cout << "\n\t Enter the character "; cin >> ch; while (*(a+i) != '\0') { if (*(a + i) == ch) count++; i++; }
Output
36
#include<iostream.h> #include<string.h> #include<conio.h> #include <stdio.h> //CLASS DECLARATION class strn { char *a, *b, flag; int i, j, k; public: void read(); //MEMBER FUNCTIONS void compare(); strn() //USE OF CONSTRUCTOR { flag = 'y'; } }; //END OF CLASS void strn::read() { cout << "\n\t"; cout << "\n\tEnter the first string "; gets(a); //TO READ THE STRING cout << "\n\tEnter the second string "; gets(b); //TO READ THE STRING } void strn::compare() { i = 0; j = 0; while (*(a+i) != '\0') i++; while(*(b+j) != '\0') j++; if (i != j) { cout << "\n\t Strings are not equal ";
return; } i = 0; while ((*(a+i) != '\0') && (*(b+i) != '\0')) { if(*(a + i) != *( b + i)) { flag = 'n'; break; } i++; } if(flag == 'n') cout << "\n\tStrings are not equal "; else cout << "\n\tStrings are equal "; } //M A I N P R O G R A M void main() { strn x; //DECLARATION OF OBJECT clrscr(); cout << "\n\n\n\t "; x.read(); //CALLING MEMBER FUNCTIONS x.compare(); cout << "\n\n\t\t bye!"; getch(); }
Output
38
#include<conio.h> #include <stdio.h> //CLASS DECLARATION class strn { char *a; int i; public: void read(); void calculate(); }; //END OF CLASS void strn::read() { cout << "\n\t"; cout << "\n\tEnter your name "; gets(a); } void strn::calculate() { i = 0; while (*(a+i) != '\0') i++; cout << "\n\tThe length of your name is : " << i;;
Output
ARRAYS:
40
Output:
41
Output:
42
Output
43
Q:Deletion
#include<iostream.h> #include<conio.h> #define len 50 int i,n,arr[len],a,pos=-1; void main() { clrscr(); void del(int); cout<<"Enter the no. of entries to be done : "; cin>>n; cout<<"\n\n"; for(i=0;i<n;i++) { cout<<"\nEnter No. "<<i+1<<" : "; cin>>arr[i]; } cout<<"\n\nThe Entered No.s are :"; for(i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\nEnter the no. to be deleted :"; cin>>a; del(a); cout<<"\n\nNow The Array is: "; if(pos!=-1) {for(i=0;i<n-1;i++) cout<<arr[i]<<" "; } else {for(i=0;i<n;i++) cout<<arr[i]<<" "; } getch();} void del(int) { for(i=0;i<n;i++) { if(a==arr[i]) pos=i; } if( pos==-1) cout<<"\n\nNot Found"; else {for(i=pos;i<n;i++) { arr[i]=arr[i+1]; }}}
Output
44
Q: Traversal in an array
#include<iostream.h> #include<conio.h> #define len 50 void main() { clrscr(); int arr[len]; int n,i; cout<<"How many elemnts do you want to insert in the array :"; cin>>n; cout<<"\n\nEnter array elements :"; for(i=0;i<n;i++) {cout<<"Enter element "<<i+1<<": "; cin>>arr[i]; cout<<endl; } cout<<"\n\nDoubling the Elements.......\n"; cout<<"\nNow the array is :\n\n"; for(i=0;i<n;i++) { arr[i]=arr[i]*2; cout<<"Element "<<i+1<<"= "; cout<<arr[i]; cout<<"\n\n"; } getch(); }
Output
45
Q: Insertion
#include<iostream.h> #include<conio.h> #define len 50 int n; void main() { clrscr(); int i,arr[len],a,pos; cout<<"Enter the no. of entries to be done : "; cin>>n; cout<<"\n\n"; for(i=0;i<n;i++) { cout<<"\nEnter No. "<<i+1<<" : "; cin>>arr[i]; } cout<<"\n\nThe Entered No.s are :"; for(i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n\nEnter the new no. to be inserted :"; cin>>a; cout<<"\nEnter Its Position : "; cin>>pos; pos--; for(i=n;i>pos;i--) { arr[i]=arr[i-1]; } arr[pos]=a; cout<<"\n\nNow The Array is: "; for(i=0;i<n+1;i++) cout<<arr[i]<<" "; getch(); }
Output
46
Q: Updation
#include<iostream.h> #include<conio.h> #define len 50 int i,n,arr[len],a,nval,pos=-1; void main() { void update(int); clrscr(); cout<<"Enter the no. of entries to be done : "; cin>>n; cout<<"\n\n"; for(i=0;i<n;i++) { cout<<"\nEnter No. "<<i+1<<" : "; cin>>arr[i]; } cout<<"\n\nThe Entered No.s are :"; for(i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\nEnter the no. to be Updated :"; cin>>a; update(a); cout<<"\n\nNow The Array is: "; for(i=0;i<n;i++) cout<<arr[i]<<" "; getch();} void update(int) { for(i=0;i<n;i++) { if(a==arr[i]) pos=i; } if( pos==-1) cout<<"\n\nNot Found"; else { cout<<"\nEnter the new Value :"; cin>>nval; arr[pos]=nval; } }
Output
47
STACKS:
Q: Write a program to demonstrate array based stack?
#include<iostream.h> #include<conio.h> #include<process.h> class stack { int arr[20]; int top, max; public: stack ( ) { top = -1; max=19; } void push(); void pop( ); void display( ); }; void stack : : push() { if(top= =max) cout<< \n Overflow; else { int d; cout <<enter element to be pushed \n; cin >> d; top++; arr[top]=d; cout << d << PUSHED INTO STACK.; } } int elt=arr[top]; top - -; cout << elt << POPPED FROM STACK.; } } void stack: : display( ) { for (int i = top; i >= 0; i--) cout << \n << arr[i]; } void main( ) { int ch; char c; stack ob; int n; do { clrscr( ); cout<<\n #######MENU#######; cout << \n1. PUSH INTO STACK.; cout << \n 2. POP INTO STACK.; cout << \n 3. DISPLAY THE STACK.; cout << \n 4. EXIT.; cout << \n ENTER YOUR CHOICE?: cin >> ch; switch(ch) { case 1 : cout << \n Enter a number?; cin>>n; ob.push(n); break; case 2: ob.pop( );break;
48
case 3: ob.display( ) break; } cout << \ndo you want to continue?; cin >> c; }while((c= =y) || (c = = Y )); getch( );}
Output: Push:
Pop:
49
Display:
50
51
{ NODE *Temp; Temp=new NODE; if (!Temp) cout <<Overflow\n; else { cout << Data:; cin >> Temp Data; Temp Next = Top; Top=Temp; } } void Stack: :Pop( ) { if (Top != NULL) { NODE *Temp = Top; cout << TopData << Deleted..\n; Top = Top Next; delete Temp; } else cout << Underflow\n;
52
} void Stack : : Disp( ) { if (Top==NULL) cout <<Stack is empty\n; else { NODE *Temp = Top; while (Temp != NULL) { cout<<Temp Data<<endl; Temp=Temp Next; } } } Stack: : ~Stack( ) { while (Top!=NULL) {NODE *Temp=Top; Top=Top Next; delete Temp; } } void main( ) //Destructor Function
53
{ int ch; char c; stack ob; int n; do{ clrscr( ); cout<<\n #######MENU#######; cout << \n1. PUSH INTO STACK.; cout << \n 2. POP INTO STACK.; cout << \n 3. DISPLAY THE STACK.; cout << \n 4. EXIT.; cout << \n ENTER YOUR CHOICE?: cin >> ch; switch(ch) { case 1 : cout << \n Enter a number?; ob.Push(); break; case 2: case 3: ob.Pop( );break; ob.Display()break;
default: cout<<Wrong choice; } cout << \ndo you want to continue?; cin >> c;
54
Output: Push:
Pop:
55
Display:
56
QUEUES:
Q: Write a program to demonstrate array based queue?
# include<iostream.h> # include <conio.h> # include<process.h> class queue{ int q[20]; int front, rear, max; public: queue( ) { front = rear = -1; max = 29; void qinsert( ); void qdelete( ); void display( ); int isfull( ) { return (max = = rear); } int isempty( ) { return (front = = -1); } } void queue : : qinsert( ) { if (isfull ( ) ) cout << \nQUEUE OVERFLOW; else { int elt; if (isempty( ) ) cout << \nQUEUE UNDERFLOW; else { int elt = q[front]; cout << \n << elt << REMOVED FROM QUEUE; if (front = = rear) front = rear = -1; else front ++; } } void queue : : display( ) {for (int i = front; i < = rear; i++) cout << \n << q[i];} void main( ) {int ch;char c;queue ob; do{ clrscr( ); cout << \n#########MENU########; cout << \n1. ADD ELEMENT TO QUEUE; cout << \n 2. REMOVE ELEMENT FROM QUEUE; cout << \n 3. DISPLAY THE QUEUE; cout << \n 4. EXIT; cout << \n ENTER YOUR CHOICE? ; cin >> ch; switch(ch){ case 1 : ob.qinsert( );break;
57
cout << \n ENTER NUMBER: ; cin >> elt; if ( isempty ( ) ) front = rear = 0; else rear ++; q[rear] = elt; }} void queue : : qdelete ( ){
A case 2 : ob.qdelete( );break; case 3 : ob.display( );break; default : cout << \n WRONG CHOICE ! ! ! ; } cout << \n \n DO YOU WANT TO CONTINUE?; cin >> c; } while ( ( c = = y ) | | ( c = = Y ) ); getch ( );}
Output: Insert:
Delete:
58
Display:
59
cout<<Queue Empty..; } void Queue : :Qdisplay( ) { NODE *Temp=Front; While (Temp!=NULL) { cout<<TempData<<endl; Temp=TempNext; } } Queue: : ~Queue (){ while (Front!=NULL) { NODE *Temp= Front; Front = FrontNext; delete Temp; } } void main( ) { Queue ob; char Ch;
cin>>Temp->Data; Temp->Next=NULL; If (Rear ==NULL) {Rear=Temp; Front=Temp; } else { Rear->Next = Temp; Rear=Temp; } } void Queue: : Qdelete( ) { if (Front!=NULL) { NODE *Temp=Front; cout<<Front->Data<<Deleted\n; Front=Front->Next; Delete Temp; If (Front ==NULL) Real=NULL; } else
do { clrscr( ); cout << \n#########MENU########; cout << \n1. ADD ELEMENT; cout << \n 2. REMOVE ELEMENT ; cout << \n 3. DISPLAY THE QUEUE; cout << \n 4. EXIT; cout << \n ENTER YOUR CHOICE? ; cin >> ch; switch(ch) {case 1 : ob.qinsert( );break; case 2 : ob.qdelete( );break; case 3 : ob.display( );break; default : cout << \n WRONG CHOICE ! ! ! ; } cout<<\n\nDO YOU WANT TO CONTINUE?; cin >> ch; } while ( ( c = = y ) | | ( c = = Y ) ); }while (ch!=Q); }
Output: Insert:
61
Delete:
Display:
62
{cout<<\n\NEMPLOYEE NO:<<s.emp_no; cout<<\nEMPLOYEE NAME:; puts(s.emp_name); cout<<SALARY:<<s.salary; } class queue { employee a[20]; int front, rear, max; public: queue( ) { front=rear=-1; max=19; } void add( ); void del( ); void display( ); int isfull( ); int isempty( ); }; int queue: :isfull( ) { if((front= =rear+1) | | (front= =0) &&(rear= =max))) return 1; else return 0; } void queue: :add( ) { if(isfull( )) cout<<\n queue overflow! !; else { employee temp; read(temp); if(isempty( )) front = rear = 0; else if(rear= =max) rear=0; else rear++;
64
a[rear]=temp; } } void queue: :del( ) { if(isempty( )) cout<<\n Queue underflow! !; else { employee temp; temp=a[front]; cout<<\nEmployee number<<temp.emp_no<<remove from queue\n; if(front= = rear) front=rear=-1; else if(front= = max) front=0; else front++; } } void queue : :display( ) { if(isempty( )) cout<<\n Queue underflow!! else { if(front<=rear) { for(int i = front; i<= rear;i++) disp(a[i]); } else { for(int i=front;i<=max;i++) disp(a[i]); for(i=0;i<=rear;i++) disp(a[i]); } } } void main( ) {int ch;
65
char c; queue ob; do { clrscr( ); cout << \n#######MENU######; cout << \n1.ADD A RECORD IN QUEUE.; cout << \n2.REMOVE A RECORD FROM QUEUE.; cout << \n3.DISPLAY THE QUEUE.; cout << \n4.QUIT.; cout << \n ENTER YOUR CHOICE : :; cin >> ch; switch (ch) { case 1 : ob.add( );break; case 2 : ob.del( );break; case 3 :ob.display( );break; default : cout << \n\n WRONG CHOICE !!!; } cout << \n\n\n DO YOU WANT TO CONTINUE?; cin >> c; } while ( ( c = = y ) | | ( c = = Y ) ); getch( ); }
Output: Insert:
66
Delete:
Display:
67