>p; binary_search(A,n,p); break; default: cout<<"\n\nPlease enter desired keyword."; goto l; } break; case 2 : k: cout<<"\n\n\t1. Selection Sort "; cout<<"\n\n\t2. Bubble Sort "; cout<<"\n\n\t3. Insertion sort "; U) {cout<<"\n\nUnsuccessful search."; cout<<"\n\n\n\nWant to search again. : "; cin>>ch; if(ch=='y'||ch=='Y') {cout<<"\n\n\n\nEnter the element to be searched : "; cin>>p; goto lb;} =0; i--) { cout< >b[i][j]; for(i=0; i<80; i++) cout<<"-"; cout<<"\n\nMatrix 1 is : \n\n"; for(i=0; i >ch; switch(ch) { case 1 : if(m==p) if(n==q) add(a,b); else { cout<<"\n\nNumber of columns of matrices are not same. \nEnter the matrices again."; goto l; } else { cout<<"\n\nNumber of rows of matrices are not same. \nEnter the matrices again."; goto l; } break; case 2 : if(m==p) if(n==q) { kk: cout<<"\n\n\t1. Subtract Matrix 2 from Matrix 1 "; cout<<"\n\n\t1. Subtract Matrix 1 from Matrix 2 "; cout<<"\n\n\tEnter your choice : ";cin>>mc; switch(mc) { case 1 : subtract(a,b);break;
cout<<"\n\n\t4. Merge Sort "; cout<<"\n\n\tEnter your choice : "; cin>>ch; switch(ch) { case 1 : if(o==1) cout<<"\n\nArray already sorted using Selection sort "; else {if(h==0&&t==0) { selection_sort(A,n); cout<<"\n\n\n\nSorted array is : \n\n"; for(k=0; k
case 3: if(t==1) cout<<"\n\nArray already sorted using Insertion sort "; else { if(h==0&&o==0) { insertion_sort(A,n);
t=1; } else if(h==1&&o==0) cout<<"\n\nArray already sorted using Bubble sort "; else cout<<"\n\nArray already sorted using selection sort "; } break; case 4 : merge_sort(0,n); cout<<"\n\nArray after merge sort : \n\n"; for(int z=1; z<=n; z++) cout<>m; for(i=0; i
case 6: exit(0); break; default : cout<<"\n\nPlease enter desired keyword : "; goto lm; } cout<<"\n\nWant to choose from menu again : "; cin>>choice; }while(choice=='y'||choice=='Y'); getch(); } // end of main
/*----------------------------------------------------------- Function Definitions -------------------------------------------------------------*/ int linear_search(int A[], int n, int p) //function definition {for(int i=0; i
else exit(1); } } void selection_sort(int A[], int n) {int small; int k,count=0; for(int i=0; i
void bubble_sort (int A[], int n) { int temp; int count=0; for(int i=0; i
void insertion_sort(int A[], int n) {int j,t; A[n]=0; for(int i=n; i>=0; i--) //shifting each element to its succesive position A[i]=A[i-1]; A[0]=INT_MIN; // INT_MIN= -32768 for(i=1; i<=n; i++) { t=A[i]; j=i-1; while(t \n\n"; for(int k=1; k<=n; k++) cout<
void merge_sort(int low,int high) { int mid; if(low
if(A[h]<=A[j]) { b[i]=A[h]; h++; } else { b[i]=A[j]; j++; } i++; } if(h>mid) { for(k=j;k<=high;k++) { b[i]=A[k]; i++; } } else { for(k=h;k<=mid;k++) { b[i]=A[k]; i++; } } for(k=low;k<=high;k++) A[k]=b[k]; } void merging(int A[],int B[],int n,int m, char cha) {mg=1; int c[80]; for(int i=0; i
switch(cha)
{ case 'a' : cout<<"\n\nArray formed after merging in ascending order : \n\n"; selection_sort(c,p); for(int i=0; i
cin>>pos; if(pos-1>n-1) { cout<<"\n\nInvalid "; goto l; } else for(int i=0; i
// 2-D matrices // Matrix 1 : m= no. of Rows , n=no. of Columns // Matrix 2 : p= no. of Rows , q=no. of Columns
int mc, oc, sum=0; // Function Declarations void add(int a[80][80],int b[80][80]);
void subtract(int a[80][80],int b[80][80]); void multiply(int a[80][80],int b[80][80]); void multiply1(int b[80][80],int a[80][80]); void equivalency ( int a[80][80],int b[80][80]); void upper_tri(int a[80][80]); void lower_tri(int a[80][80]); void diagonal_1_a(int a[80][80]); void row_sum_a(int a[80][80]); void column_sum_a(int a[80][80]);
void main() // main body {clrscr(); int ch,op; char choice; l: cout<<"\n\nDescribe the Size of matrix 1 : "; cout<<"\n\n\n\tEnter the number of rows : "; cin>>m; cout<<"\n\n\tEnter the number of columns : "; cin>>n; cout<<"\n\nEnter the elements of matrix 1 : \n\n"; for(i=0; i
for(i=0; i
case 2 : subtract(b,a);break; default: cout<<"\n\nPlease enter desired keyword. ";goto kk; } } else { cout<<"\n\nNumber of columns of matrices are not same. \nEnter the matrices again."; goto l; } else { cout<<"\n\nNumber of rows of matrices are not same. \nEnter the matrices again."; goto l; } break; case 3 : cout<<"\n\n\t(i). Multiply matrix 1 with matrix 2 "; cout<<"\n\n\t(ii). Multiply matrix 2 with matrix 1 "; cout<<"\n\n\tEnter your choice : "; cin>>op; switch(op) { case 1 : if(n==p) multiply(a,b); else { cout<<"\n\nMultiplicaion not possible, as no. of columns of first matrix != no. of rows of second matrix. \nEnter the matrices again."; goto l; } break; case 2 : if(m==q) multiply1(b,a); else { cout<<"\n\nMultiplicaion not possible, as no. of columns of first matrix != no. of rows of second matrix. \nEnter the matrices again."; goto l; } break; } break; case 4: if(m==p) if(n==q) equivalency(a,b); else
cout<<"\n\nMatrices are not equivalent."; else cout<<"\n\nMatrices are not equivalent."; break; case 5: cout<<"\n\n\t(i). Display Upper triangular of matrix 1 "; cout<<"\n\n\t(ii).Display Upper triangular of matrix 2 "; cout<<"\n\n\tPlease enter your choice : "; cin>>mc; switch(mc) { case 1 : if(m==n) upper_tri(a); else cout<<"\n\nUpper Triangle cannot be displayed. Matrix should be square. "; break; case 2 : if(p==q) upper_tri(b); else cout<<"\n\nUpper Triangle cannot be displayed. Matrix should be square. "; break; } break; case 6: cout<<"\n\n\t(i). Display Lower triangular matrix 1 "; cout<<"\n\n\t(ii).Display Lower triangular matrix 2 "; cout<<"\n\n\tEnter your choice : "; cin>>mc; switch(mc) { case 1 : if(m==n) lower_tri(a); else cout<<"\n\nLower Triangle cannot be displayed. Matrix should be square. "; break; case 2 : if(p==q) lower_tri(b); else cout<<"\n\nLower Triangle cannot be displayed. Matrix should be square. "; break; } break; case 7: cout<<"\n\n\t(i). Diagonals of matrix 1 "; cout<<"\n\n\t(ii).Diagonals of matrix 2 "; cout<<"\n\n\tEnter your choice : "; cin>>oc; switch(oc) {
case 1 : cout<<"\n\n\t\t1. Find sum of diagonal (top-left to bottom-right) "; cout<<"\n\n\t\t2. Find sum of diagonal (bottom-left to top-right) "; cout<<"\n\n\t\tEnter your choice : "; cin>>mc; diagonal_1_a(a); break; case 2 : cout<<"\n\n\t\t1. Find sum of diagonal (top-left to bottom-right) "; cout<<"\n\n\t\t2. Find sum of diagonal (bottom-left to top-right) "; cout<<"\n\n\t\tEnter your choice : "; cin>>mc; diagonal_1_a(b); break; } break; case 8: cout<<"\n\n\t1. Display and find row wise sum of a matrix 1 : "; cout<<"\n\n\t2. Display and find row wise sum of a matrix 2 : "; cout<<"\n\n\tEnter your choice : "; cin>>oc; switch(oc) { case 1 : row_sum_a(a); break; case 2 : row_sum_a(b); break; } break; case 9: cout<<"\n\n\t1. Display and find column wise sum of a matrix 1 : "; cout<<"\n\n\t2. Display and find column wise sum of a matrix 2 : "; cout<<"\n\n\tEnter your choice : "; cin>>oc; switch(oc) { case 1 : column_sum_a(a); break; case 2 : column_sum_a(b); break; } break; case 10 : exit(10); } cout<<"\n\n\nWant to choose again => "; cin>>choice; }while(choice=='y'||choice=='Y');
getch(); }
//----------------------------------------------------------- Function Definitions -------------------------------------------------------void add(int a[80][80],int b[80][80]) { int c[80][80]; for(i=0; i
void multiply(int a[80][80],int b[80][80]) { int c[80][80]; j=0; int k=0; cout<<”\n\nResultant of Matrix Multiplication : “; for(i=0; i
void multiply1(int b[80][80],int a[80][80]) { int c[80][80]; j=0; int k=0; int sum=0; for(i=0; i
} void equivalency ( int a[80][80],int b[80][80]) {int count=0; for(i=0; i
void upper_tri(int a[80][80]) {int s; if(mc==1) s=m; else s=p; cout<<”\n\nUpper triangle of matrix is : “; for(i=0; i
void lower_tri(int a[80][80]) {int z; if(mc==1) z=m; else z=p; cout<<”\n\nLower triangle of matrix is : “;
for(i=0; i
void diagonal_1_a(int a[80][80]) {int ui; if(oc==1) ui=m; else ui=p; if(mc==2) { sum=0; cout<<"\n\nDiagonal Elements are : \n\ n"; for(i=0; i
void row_sum_a(int a[80][80]) {int v,u; if(oc==1)
{ v=m; u=m; } else { v=p; u=q; } for(i=0; i
class bank { char name[80]; int acc_no; enum acctype{S,C}; void account_type(int n); float balance; public: float add_bal(float n); float withdrawl (float k); void initial(); void display(); }acc; float bank:: add_bal(float n) { cout<<"\n\nYour balance is : "<
cout<<"\n\nInitial balance cannot be less than 1000.\n\n"; goto m; } } void bank :: account_type(int n) { switch(n) { case S+1 : cout<<" Saving account."; break; case C+1 : cout<<" Current account."; break; } } void bank::display() { cout<<"\n\nName of the account holder => "<
case 4: for(int i=0; i<500; i++); exit(0); break; default : cout<<"\n\nPlease enter desired keyword . "; goto lb; } cout<<"\n\n\n\n\nWant to chose again : "; cin>>choice; } while(choice=='y'||choice=='Y'); getch(); }//end of main CREATE A BINARY FILE AND WRITE OBJECTS OF CLASS BOOK TO IT AND DISPLAY THEM ON SCREEN AFTER READING FROM THE FILE #include
{ cout<<"\n\nBook title is : "<
bo.read((char *)&p[i], sizeof(p[i])); // It is not mandatory to have different objects of a class bo.close(); } cout<<"\n\n--------------------------------------------------- Book Details ----------------------------------------------------------------“;
for(i=0; i<3; i++) { p[i].display(); }
getch(); }
PROGRAM TO DEFINE THE CLASSES PERSON, GAME AND STUDENT & TO ACCESS THE ESSENTIAL DATA USING MULTIPLE INHERITANCES. #include
class person{ char name[21]; int age; public: void indata() {cout<<"\n\nEnter the name of Student: " ; gets(name); cout<<"\n\nEnter the age : "; cin>>age; } void outdata(); }; void person::outdata() // since the function contains loop so it is not made inline { cout<<"\n\n"; for(int i=0; i<79; i++) cout<<"-"; cout<<"\n\nName of the student is: "<
{if(Tmarks>90) return 'A'; else if(Tmarks>80&&Tmarks<=90) return 'B'; else if(Tmarks>70&&Tmarks<=80) return 'C'; else if(Tmarks>60&&Tmarks<=70) return 'D'; else return 'E'; } void enter() { indata(); // indata() of class person called here cout<<"\n\nEnter the roll number: "; cin>>rollno; input(); // input() of class game called here cout<<"\n\nEnter total marks (out of 100) : "; cin>>Tmarks; } void display() { outdata(); cout<<"\n\nRoll number : "<
int pop(int[],int&);
int push(int[],int&,int); void display(int[],int);
const int size=50;
void main() { clrscr(); char m,ch; int k,stack[size],item,top=-1,res; do {
cout<<"\nChoose from the following : \n\n" <<"\n 1. Push" <<"\n 2. Pop" <<"\n 3. Display" <<"\n 4. Exit" <<"\n\nEnter your choice : "; cin>>k;
switch(k) { case 1: ch='y'; while(ch=='y'||ch=='Y') {
cout<<"\nEnter the element : "; cin>>item; res=push(stack,top,item); if(res==-1) {cout<<"\nOverflow !!!!"; exit(1); } cout<<"\nThe stack formed is : \n\n"; display(stack,top); cout<<"\n\n\nWant to enter again ?: "; cin>>ch;
} break;
case 2: ch='y'; while(ch=='y'||ch=='Y') { res=pop(stack,top); if(res==-1) { cout<<"\nUnderflow !!!!"; exit(1); } else { cout<<"\nThe deleted Element is : "<
case 3: cout<<"\nThe resultant stack is : "; display(stack,top); break;
case 4: exit(0); break;
default: cout<<"\nPlease enter desired keyword : "; }
// end of switch
cout<<"\n\nChoose from the menu again ? : ";
cin>>m;
}while(m=='y'||m=='Y');
// end of do-while loop
getch(); }
// end of main()
int push(int stack[],int &top,int el) { if(top==size-1) return -1; else { top++; stack[top]=el; 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)
{ cout<
const int size=50; int q[size],rear=-1,front=-1; int insert(int q[],int ele) { if(rear==size-1) return(-1); else if(rear==-1) { front=rear=0; q[rear]=ele; } else { rear++; q[rear]=ele; } return(0); } int delet(int q[]) { int r ; if(front==-1) return(-1); else { r=q[front]; if(rear==front) front=rear=-1; else front++; }
return r; } void display(int q[],int front,int rear) { if(front==-1) return; else { for(int i=front;i<=rear;i++) cout<>n; switch(n) { case 1: ans='y'; while(ans=='y'||ans=='Y') { cout<<"\n Enter element to be inserted :"; cin>>m; k=insert(q,m); if(k==-1) cout<<"\n Overflow !!!!"; cout<<"\n The resultant Queue is : "; display(q,front,rear); cout<<"\n\n Want to enter again ?: "; cin>>ans; } break;
case 2: ans='y'; while(ans=='y'||ans=='Y') { u=delet(q); if(u==-1) { cout<<"\n Underflow !!!!"; break; } else { cout<<"\n The deleted element is "<>ans; } break; case 3: cout<<"\n The Queue is : \ n\n"; display(q,front,rear); break; default: cout<<"\n Please enter desired keyword : "; } cout<<"\n Choose from the menu again ? : ";cin>>ch; }while(ch=='y'||ch=='Y'); getch(); } PROGRAM IN C++ TO READ FILE “SPORTS.DAT” AND COPY ONLY THOSE RECORDS WHERE EVENT
NAME IS ATHLETIC USING THE CONCEPT OF DATA FILE HANDLING #include
#include
struct sports {
char event[20]; char participants[10][30]; int no_of_participants; } s[20], s2[20];
void copy(fstream &ob);
int i=0;
void main() { clrscr(); char choice; fstream ob("sports.dat",ios::binary|ios::in|ios::out); do { if(i>0) cin.get();
cout<<"\n\nEnter the name of Event : "; cin.getline(s[i].event,20);
cout<<"\n\nEnter the total number of participants in Event "<>s[i].no_of_participants;
cout<<"\n\nEnter the name of Praticipants : \n"; cin.get();
for(int j=0; j
cout<<"\n\n\nWant to Enter Details of Another Event (Y/N) : "; cin>>choice; i++; } while(choice=='y'||choice=='Y');
cout<<"\n\n\n\n\n********************************************************************* ***************************************\n\n";
copy(ob);
cout<<"\n\n*************************************************************************** **************************************\n\n\n"; getch(); }
void copy(fstream &o) { sports s[20]; o.seekg(0);
ofstream file; file.open("athletic.dat",ios::binary); file.seekp(0);
int j,n=0; int c=0;
while(o) { o.read((char*)&s[c], sizeof(sports));
if(strcmp("athletic",s[c].event)==0)
{ file.write((char*)&s[c], sizeof(sports)); n=1; break; } c++; }
if(n==0) { cout<<"\n\nUnsuccessful Search."; getch(); exit(0); }
o.close(); file.close();
sports sp;
ifstream oo; oo.open("athletic.dat",ios::binary);
while(oo) { oo.read((char*)&sp, sizeof(sports));
}
cout<<"\n\nThe Records of file are : \ n\n";
cout<<"\n\nEvent = "<
cout<<"\n\n\n\nThe Participants are : \n\n"; for(int i=0; i
oo.close();
remove("athletic.dat"); remove("sports.dat");
} PROGRAM TO PRINT AND FIND THE SUM OF FIBONACCI SERIES USING RECURSION
#include
int fibonacci(int n);
void main() { clrscr(); int n; cout<<"\n\n Enter the number of terms upto which you want the sum of fibonnaci series : "; cin>>n;
cout<<"\n\nThe fibonacci series generated is : \n\n"; cout<<"1 1 ";
int s=fibonacci(n);
cout<<"\n\nThe sum of fibonacci series for "<
if(front==NULL) { front=temp; rear=temp; } else { rear->next=temp; rear=temp; }
} void queue::deletion() { node *temp; if(front==NULL) { cout<<"EMPTY!!!" ; exit(0); } else { temp=front; front=front->next; cout<<"Deleted items\n"; cout<
cout<<"2 for deletion\n"; cout<<"3 for display\n"; cout<<"4 for exit\n"; cin>>n; switch(n) { case 1: case 2: case 3: case 4: default:
q.insertion(); break; q.deletion(); break; q.display(); break; exit(0); cout<<"Wrong Choice";
} cout<<"Want more??(y/n)..."; cin>>ch; if(ch=='y'||ch=='Y') goto a; getch(); } PROGRAM FOR INSERTION IN LINKED LIST #include
int roll; char name[20]; node *next;
}; class queue {
node *rear,*front; public: queue() {
front=NULL; rear=NULL;
} void insertion(); void display();
}; void queue::insertion() {
node *temp; temp= new node; cout<<"Enter roll no. and name\n"; cout<<"Roll No.: " ; cin>>temp->roll; cout<<"Name: "; gets(temp->name); temp->next=NULL; if(front==NULL) {
front=temp; rear=temp;
} else {
rear->next=temp; rear=temp;
} } void queue::display() {
node *temp; if(front==NULL) {
cout<<"EMPTY!!!"; exit(0);
} else {
temp=front; while(temp!=NULL) {
cout<
} } } void main() {
clrscr(); char ch; int n;
queue q; a:cout<<"Enter your choice\n"; cout<<"1 for insertion\n"; cout<<"2 for display\n"; cout<<"3 for exit\n"; cin>>n; switch(n) {
case 1:
q.insertion(); break;
case 2:
q.display(); break;
case 3:
exit(0);
default:
cout<<"Wrong Choice";
} cout<<"Want more??(y/n)..."; cin>>ch; if(ch=='y'||ch=='Y') goto a; getch(); }
Structured Query Language Q)Consider the following table GAMES and PLAYERS and answer the questions given below. Table: GAMES GCODE
GNAME
TYPE
NUMBER
PRICE
101 102 103 105 108
Carom board Badminton Table tennis Chess Lawn tennis
Indoor Outdoor Indoor Indoor Outdoor
2 2 4 2 4
5000 12000 8000 9000 25000
Table: PLAYERS NO.
NAME
PCODE
SCHEDULED DATE 20-1-2002 12-12-2003 24-2-2002 1-1-2004 19-3-2004
1 2 3 4
(1) (2) (3) (4)
Nabi Ahmed Ravi Sahini Jatin Nazneen
101 108 101 103
To display the names of all games with their GCODE. To display details of those games which are having price money more than 7000. To display the content of GAMES table in ascending order of scheduled date. To display sum of price money for each type of games.
Give the output of the following SQL queries. (5) Select count(distinct number) from GAMES; (6) Select max (scheduled date) ,min (scheduled date) from GAMES; (7) Select GNAME from GAMES and names from PLAYERS where GCODE=PCODE and PRICE> 10000;
(1) Select gname,gcode from games; GCODE 101 102 103 105 108
GNAME Carom board Badminton Table tennis Chess Lawn tennis
(2) Select * from games where price>7000; GCODE
GNAME
TYPE
NUMBER
PRICE
102 103 105 108
Badminton Table tennis Chess Lawn tennis
Outdoor Indoor Indoor Outdoor
2 4 2 4
12000 8000 9000 25000
TYPE
NUMBER
PRICE
SCHEDULED DATE 12-12-2003 24-2-2002 1-1-2004 19-3-2004
(3) Select * from games order by scheduled date;
GCODE
GNAME
SCHEDULED DATE
101 103 102 105 108
Carom board Table tennis Badminton Chess Lawn tennis
Indoor Indoor Outdoor Indoor Outdoor
2 4 2 2 4
5000 8000 12000 9000 25000
20-1-2002 24-2-2002 12-12-2003 1-1-2004 19-3-2004
(4) select sum(price) from games group by type; TYPE Indoor Outdoor
PRICE 22000 37000
(5)2 (6)19-3-2004, 20-1-2002 (7)Lawn tennis, Ravi sahini.
Consider the following table Table: STUDENT AND ANSWER THE FOLLOWING QUESTIONS:NO. 1 2 3 4 5
NAME Neha Damini Gaurav Anu Vikas
STIPENED 450.00 400.00 250.00 300.00 500.00
6
Rubina
450.00
STREAM AVGMARK Medical 89.2 Commerce 78.5 Humanities 64.4 Commerce 67.5 Non92.0 medical Non88.5 medical
GRADE A B C C A
CLASS 11C 12B 11A 12B 12A
A
12A
Write SQL command for the following statements. (1) To display the names of all students who are in medical stream. (2) To display the NAME and AVGMARK of all the students having AVGMARK less than 70.0. (3)To display the list of all the students with STIPENED >350.00 in ascending order of NAME. (4)To display a report with NAME ,marks for each student in the table. Marks are calculated as AVGMARK*5.
Give the output of the following SQL queries. (5)Select min (AVGMARK) from STUDENT; (6) Select sum (STIPENED) from STUDENT where GRADE=’A’; (7)Select Avg(STIPENED) from STUDENT where stream =”commerce”; (8) Select count(distinct STREAM) from STUDENT;
(1) Select name from student where stream=”medical”;
NAME Neha
(2) Select name,avgmark from student where avgmark<70.0; NAME Gaurav Anu
AVGMARK 64.4 67.5
(3) Select * from student where stipened>350.00 and order by name; NO. 2 1 6
NAME Damini Neha Rubina
STIPENED 400.00 450.00 450.00
STREAM Commerce Medical Nonmedical 5 Vikas 500.00 Nonmedical (4) Select name, marks=avgmark*5 from student; NAME Neha Damini Gaurav Anu Vikas Rubina (4) (5) (6) (7)
64.4 1400 350.00 4
AVGMARK 78.5 89.2 88.5
GRADE B A A
CLASS 12B 11C 12A
92.0
A
12A
MARKS 446 392.5 322 337.5 460 442.5