kendriya vidyalaya sangathan regional office bhopal ... · constructor normal function 1....

38
1 KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL CHAPTER-WISE ASSIGNMENT WHERE IS WHAT? Chap 1. Programming in C++ Structure OOP’s Concepts Pointers ( 2 4 ) Chap 2. Class and Objects, Constructor And Destructor And Inheritance ( 5 10 ) Chap 3 Arrays Linked List & Stack Queues ( 11 22 ) Chap 4 DATA FILE HANDLING IN C++ ( 23 25 ) Chap 5 DATABASE CONCEPTS & SQL ( 26 30 ) Chap 6 BOOLEAN ALGEBRA ( 31 33 ) Chap 7 COMMUNICATION & COMPUTER NETWORKS (34 36 )

Upload: others

Post on 12-Mar-2021

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

1

KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE – BHOPAL CHAPTER-WISE ASSIGNMENT

WHERE IS WHAT?

Chap 1. Programming in C++ Structure OOP’s Concepts Pointers ( 2 – 4 )

Chap 2. Class and Objects, Constructor And Destructor And Inheritance ( 5 – 10 )

Chap 3 Arrays Linked List & Stack Queues ( 11 – 22 )

Chap 4 DATA FILE HANDLING IN C++ ( 23 – 25 )

Chap 5 DATABASE CONCEPTS & SQL ( 26 – 30 )

Chap 6 BOOLEAN ALGEBRA ( 31 – 33 )

Chap 7 COMMUNICATION & COMPUTER NETWORKS (34 – 36 )

Page 2: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 2 -

CHAPTER - 1 REVISION TOUR C++, OOPs Concepts & POINTERS Q 1 WHAT WIIL BE OUTPUT OF FOLLOWING PROGRAM? 1 #include<iostream.h> # include <conio.h> void main() { clrscr(); int sum(int(*)(int),int); int square(int); int cube(int); cout<<sum(square,4)<<endl; cout<<sum(cube,4)<<endl; getch(); } int sum(int(*ptr)(int k),int n) { int s=0; for(int i=1;i<=n;i++) { s+=(*ptr)(i); } return s; } int square(int k) { int sq; sq=k*k; return k*k; } int cube(int k) { return k*k*k; } ANS 1> OUTPUT WILL BE

30 100

Q2>How many times will the following program will print “examination”? 1

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

while(1) { cout<<”examination”

} } ANS 2>Unless ^C is pressed ,program will print “examination” infinitely. Q 3> Will the following programs produce same output? 2

Page 3: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 3 -

Program 1 # include<iostream.h> # include<conio.h> void main() { int x,y=1; if((x=y)!=0) cout<<x<<" "<<y; getch(); } Program 2 # include<iostream.h> # include <conio.h> void main() { int x,y=0; if((x=y=1)==1) cout<<x<<" "<<y; getch(); } Q4>What woulg\d be contents of following after array initialization? 1

int A[5]={3,8 ,9} Ans 4>

A

3 8 9 0 0

Q5>Suggest storage class for following variables ½ each

1. a normal variable. 2. very heavily used variable. 3. a variable that should retain its value after function is over. 4. a variable that spanes multiple files. 5. a variable global in one & not available in another file.

Ans 5>

1. auto 2. register 3. static 4. extern 5. static global

Q 6> “Pointers always contain integers “ Comment. 1 Ans 6>

Pointer variable always store address of a variable which is always an integer. So pointers always store integers.

Page 4: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 4 -

CHAPTER – 2 CLASSES & OBJECTS, CONSTRUCTOR AND DESTRUCTOR, INHERITANCE

Q.1 What is the difference between the constructor and normal function? Ans.

Constructor Normal Function

1. Constructor has same name as class name.

1. A normal function can have any legal name but not class name.

2. Constructor can not have any return type value not even void.

2. A function should have any return type value.

3. Constructor is automatically called. 3. A function is explicitly called.

4. Constructor can not be static. 4. A Function can be static.

Q.2 What is the similarity between class and the constructor? (HOTS)/Bright Student Ans.: The only similarity between constructor and is that constructor has same name as class name. Q.3 Find the output of the following program? #include<iostream.h> #include<conio.h> #include<string.h> class state { char *statename; int size; public: state(){size=0;statename=new char[size+1];} state (char *s) { size=strlen(s);statename=new char[size+1]; strcpy(statename,s); } void display() { cout<<statename<<endl;} void replace(state&a, state &b) {size=a.size+b.size; delete statename; statename=new char[size+1]; strcpy(statename, a.statename); strcat(statename,b.statename); } }; void main() { clrscr(); char *temp="Delhi"; state state1(temp), state2("Mumbai"), state3("Nagpur"), s1,s2; s1.replace(state1,state2); s2.replace(s1,state3); s1.display(); s2.display(); getch(); } Ans.: DelhiMumbai DelhiMumbaiNagpur Q.3 Find out errors in the following program:-

class number

Page 5: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 5 -

{ int x=10; float y; number(){ x=y=10;}

public: number(number t) {

x=t.x; y=t.y; }

~ (){ cout<<"Object destroyed ";} } main() {

number a1, a2(a1); }

Ans.: error: int x=10; // class member can not be initialized in the class. Constructor should be declared in public section of class. Reference operator is missing in the definition of copy constructor In destructor class name is missing. Semicolon is missed after the definition of class.

Q.4 What is the difference between nesting or containership and inheritance? Explain with example? Ans.: Containership or Nesting: When a class contains object of other class type as its data member is known as containership or nesting.

Inheritance: Inheritance is the process of creating new class by reusing the properties of an existing class by accessing them depending on different visibility mode. The new class is called derived and existing class is called base class. Q.5 What will be the output of the program? #include<iostream.h> class base { public: void display() {

cout<<"It is a base class "<<endl; }

}; class derived: public base {

public: void display() { cout<<"It is a derived class "<<endl;} };

main() {

derived ob1; ob1.display();

} Ans:- The output will be: It is a derived class. Q.6 Define a class named Tour in C++ with following description? 4 Private members: tcode integer (Ranges 6 - 10) adults, children, distance integer

Page 6: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 6 -

totalfare float AssignFare( ) A function which calculates and assign the value to data member totalfare as follows:- - For adults Fare Distance

Rs. 500 >=1500 And fare get reduced by 25% if distance is < 1500. - For Children

For every child a fixed Rs. 50 is charged as fare. Public members:

A constructor which initialized initialize all data members with 0

Function EnterTour() to input the values of the data members tcode, adults, children and call to AssignFare function.

Function ShowTour() to print all the details of object of Travel type. Ans. class tour {

int tcode,adults,children,distance; float totalfare; void assignfare() { float cfare=50, afare=1500;

if(distance<1500) afare=afare-(afare*25/100); totalfare=(children*cfare)+(adults*afare); } public: travel() { tcode=adults=children=distance=totalfare=0; }

void entertour() {

do { cout<<"Enter tcode between 6-10 ";

cin>>tcode; if (tcode<6 || tcode>10) cout<<"Invalid tcode "<<endl;

}while(tcode<6 || tcode>10); cout<<"Enter children, adults, distance"; cin>>children>>adults>>distance;

assignfare(); } void showtour() { cout<<"tcode:"<<tcode<<endl;

cout<<"children:"<<children<<endl; cout<<"adults :"<<adults<<endl; cout<<"distance:"<<distance<<endl; cout<<"total fare:"<<totalfare<<endl; } }; Q.7. Define a class named Admission in C++ with following description? 4 Private members: admno integer (Ranges 10-1500) name string of 20 characters cls integer fees float Public members:

Page 7: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 7 -

A constructor which initialized admno with 10, name with “NULL”, cls with 0 & fees with 0 Function getdata() to read the object of Admission type. Function putdata() to print the details of object of admission type. Function draw_nos() to generate the admission no. randomly to match with admno and display the detail of object. Ans.: class admission

{ int admno; char name[20];

int cls; float fees;

public: admission()

{ admno=10; strcpy(name,"NULL");

cls=0; fees=0;

} void getdata() {

do { cout<<"Enter admno between 10-1500 ";

cin>>admn if (admno<10 || admno>1500)

cout<<"Invalid admission no !"<<endl; }while(admno<10 ||admno>1500);

cout<<"Enter name "; gets(name);

cout<<"Enter class and fees "; cin>>cls>>fees; } void putdata() { cout<<"Admno :"<<admno<<endl; cout<<"Name :"<<name<<endl; cout<<"Class :"<<cls<<endl; cout<<"Fees :"<<fees<<endl; } void draw_nos() { int num;

randomize(); num=random(1491)+10; if (num==admno) putdata(); } }; Q.8 Class testmeout { int rollno;

public: ~testmeout() //Function 1 { cout<<rollno<<” is Leaving examination hall”<<endl;

} testmeout() //Function 2

{ rollno=1; cout<<rollno<<” is appearing for examination “<<endl;

}

Page 8: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 8 -

testmeout(int n, char name[]) //Function 3 { rollno=n;

cout<<name<<” is in examination hall”<<endl; } testmeout(testmeout & t);//function 4

void mywork() //Function 5 { cout<<rollno<<” is attempting questions “<<endl; }

}; i) In object oriented programming, what is Function 1 referred as and when does it get invoked? ii) In object oriented programming, what is Function 2 referred as and when does it get invoked? iii) In object oriented programming, what is Function 3 referred as and when does it get invoked? iv) Write a statement so that function 3 gets executed? Complete the definition of function 4 v) What will be the output of the above code if its main function definition is as given below (assumed the definition of Function 4 is completed ) : main() {testmeout ob1; ob1.mywork(); } vi) Which feature of object oriented programming is demonstrated using Function 2, Function 3 and Function 4 in the above class testmeout? vii) What is the scope of data member (rollno) of class testmeout? What does the scope of data members depend upon? Ans:- i) It is referred as destructor. It is automatically invoked when an object of concerned class goes out of scope. ii) It is referred as constructor. It is automatically invoked when an object of concerned class is declared / created. iii) It is parameterized constructor and gets invoked when an object of concerned class is created / declared with the matched parameters. iv) testmeout ob1(15, “Vicky”); testmeout (testmeout & t) { rollno=t.rollno;} v) output will be : 1 is appearing for examination 1 is attempting questions 1 is Leaving examination hall vi) It is constructor overloading. It shows Polymorphism feature of the OOP. vii) The rollno member of object can only be used by the concerned object where that object is declared. Its scope basically depends upon the concerned object.

Page 9: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 9 -

CHAPTER – 3 DATA STRUCTURE – ARRAY, LINK LIST, STACK & QUEUE Q. 1 Given two arrays of integers A and B of sizes M and N respectively. Write a function named MIX() which will produce a third array named C, such that the following sequence is followed :

All even numbers of A from left to right are copied into C from left to right. All odd numbers of A from left to right are copied into C from right to left All even numbers of B from left to right are copied into C from left to right. All odd numbers of B from left to right are copied into C from right to left

A, B and C are passed as arguments to MIX(). e.g. : A is {3,2,1,7,6,3} and B is {9,3,5,6,2,8,10}, the resultant array C is {2,6,6,2,8,10,5,3,9,3,7,1,3} Solution : void mix (int A[], int B[], int n, int m) { int c[20],i=0,j=0,k=0,l; L=m+n-1; while (i<n && k<20) { if (A[i]%2==0) C[k++] = A[i++]; else C[l--] = A[i++]; } While (j<m && k<20) { if (B[j]%2==0) C[k++]=B[j++]; else C[l--]=B[j++]; } cout<<” \nThe elements of an array C is :”; for (i=0;i<m+n;i++) cout<<”\n”<<C[i]; } void main() { int A[j= { 3,2,1,7,6,3}, B[]= {9,3,5,6,2,8,10}; Mix(A,B,6,7); } Q. 2. Suppose an array P containing float is arranged in ascending order. Write a user defined function in C++ to search for one float from P with the help of binary search method. The function should return an integer 0 to show absence of the number and integer 1 ti show presence of the number in the array. The function should have the parameters as (1) an array (2) the number DATA to be searched (3) number of element N. Solution : int bsearch (float P[10], float DATA, int N)

{ int beg =0, end = N-1,mid, pos = -1; while(beg<=end) { mid = ( beg+ end )/2;

if (P[mid] == DATA) { pos =mid +1;

Break; } else if (item > AE[mid] )

beg = mid +1; else

end = mid-1; } return ((pos==-1)? 0:1);

}

Page 10: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 10 -

Q. 3 Write a function in C++ which accepts an integer array and its size as arguments / parameters and assign the elements into a two dimensional array of integers in the following format : If the array is 1, 2,3,4,5,6 If the array is 1,2,3 The resultant 2D array is given below The resultant 2D array is 1 2 3 4 5 6 given below 1 2 3 4 5 0 1 2 3 1 2 3 4 0 0 1 2 0 1 2 3 0 0 0 1 0 0 1 2 0 0 0 0 1 0 0 0 0 0 Solution : void func(int arr[], int size) { int a2[20][20], i, j; for (i=0;i<size; i++) { for (j=0;j<size;j++) { if ((i+j) >=size) a2[i][j]=0; else a2[i][j]= arr[j]; cout<<a2[i][j]<<” “; } Cout<<”\n”;

} }

Q-4 Write a function in C++ to perform a PUSH operations on a dynamically allocated stack containing real number? Ans-

struct Node { float data; Node * next; }; Void push (Node*Top, float num) { Node*nptr = new Node; nptr -> data = num; nptr -> next = NULL; if(Top == NULL) Top = nptr; else { nptr -> next = Top;

Top = nptr; }

} Q-5 Each node of a STACK containing the following information, in addition to required pointer field: Roll no. of the student

Page 11: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 11 -

Age of the student. Gve the structure of node for the linked stack in question. TOP is a pointer to the topmost node of the STACK. Write the following function: PUSH() – TO push a node in to the stack which is allocated dynamically. POP() – Te remove a node from the stack and to release the memory. Ans- struct STACK { int rollno, age; STACK*next; } *top, *nptr, *ptr; void pop() { if (!pop) { cout << ”\nUnderflow!!” ; exit(1); } else { cout << ’\n’ << top -> rollno << ’\t’ << top -> age; ptr = top; top = top -> next; delete ptr; } } Void push() { nptr = new stack; //allocate memory

cout << “\n Enter roll number and age to be inserted : “ ; cin >> nptr-> rollno >> nptr->age ; nptr -> next = NULL; if (!top) top = nptr; else

{ ptr -> next = top; top = nptr } } Q.6 Write a function MAX in C++ which will return the Largest number stored in a two dimensional array of Integers. Ans #include <iostream.h> #include <conio.h> const r = 100, c = 100; // Function to find the largest integer in a two-dimensional array int MAX(int a[r][c], int m, int n) { int max = 0; for(int i= 0;i<m;i++) for(int j= 0;j<n;j++) { if (a[i][j] >max) max = a[i][j]; } return max; } void main()

Page 12: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 12 -

{ clrscr(); int ar[r][c]; int rr, cc, mx = 0; int i, j; cout << "Enter no. of row : "; cin >> rr; cout << "Enter no. of column : "; cin >> cc; cout << "Enter the array elements : "; for (i=0; i<rr; i++) for (j = 0; j<cc; j++) cin >> ar[i][j]; mx = MAX(ar, rr, cc); cout << "Largest element is : " << max; } Q.7 Write a function in c++ which accepts a 2D array of integers and its size as arguments and displays the elements which lies on diagonals. [ Assuming the2D array to be a square matrix with odd dimensions , i.e 3x3, 5x5,7x7, etc ] Example if the array content is 5 4 3 6 7 8 1 2 9 Output through the function should be Diagonal one : 5 7 9 Diagonal two : 3 7 1 . Ans // Function to display the elements which lie on diagonals #include <stdio.h> #include <iostream.h> #include <conio.h> const M = 10; const N = 10; void display_diagonals(int MATRIX[M][N], int r, int c) { clrscr(); // Finding the diagonal from left index to right cout << "Diagonal One : "; for(int i=0; i<r; i++) for(int j=0; j<c; j++) { cout << MATRIX[i][j] << " "; i++; } cout << endl; // Finding the diagonal from right index to left cout << "Diagonal Two : "; for(i=0; i<=r; i++) { for(int j=c-1; j>=0; j--)

Page 13: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 13 -

{ cout << MATRIX[i][j] << " "; i++; } } getch(); } void main() { int MATRIX[M][N]; int i, j; int r, c; cout << "Enter total no. of rows: "; cin >> r; cout << "Enter total no. of columns: "; cin >> c; if ((r == c) && ((r%2==1) && (c%2==1))) { cout << "Input steps"; cout << "\n\Enter the element in the array\n"; for(i=0; i<r; i++) for(j=0; j<c; j++) { cin >> MATRIX[i][j]; } } else return; display_diagonals(MATRIX, r, c); } Q.8 Write a function in C++ which accepts a 2D array of integers and its size as arguments and displays the elements of the middle row and the elements of middle column.

Example if the array content is 3 5 4 7 6 9 2 1 8

Output through the function should be: Middle row: 769 Middle column: 5 6 1

Ans // Function to display the elements which lie on middle of row and column #include <stdio.h> #include <iostream.h> #include <conio.h> const M = 10; const N = 10; void display_RowCol(int Array[M][N], int r, int c) { int row = r / 2; int col = c / 2; // Finding the middle row cout << "Middle Row : "; for(int j=0; j<c; j++) cout << Array[row][j] << " "; cout << endl;

Page 14: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 14 -

// Finding the middle column cout << "Middle Column : "; for(j=0; j<c; j++) cout << Array[j][col] << " "; getch(); } void main() { int Array[M][N]; int i, j; int r, c; cout << "Enter total no. of rows: "; cin >> r; cout << "Enter total no. of columns: "; cin >> c; if ((r == c) && ((r%2==1) && (c%2==1))) { cout << "Input steps"; cout << "\n\Enter the element in the array\n"; for(i=0; i<r; i++) for(j=0; j<c; j++) { cin >> Array[i][j]; } } else { cout << "Input row and column not valid"; getch(); return; } display_RowCol(Array, r, c); } Q. 9. Declare a stack using array that contains int type numbers and define pop and push function using C++ Syntax. Ans #include <iostream.h> #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <ctype.h> #define MAX 100 // Shows maximum array length int stack[MAX]; // Declares array global variable int top; // Declares integer top // Function prototypes of add stack, delete stack, and // show stack in array implementation void push(int stack[], int val, int &top); // Add stack int pop(int stack[], int &top); // Delete stack void show_Stack(int stack[], int top); // Show stack void main() { int choice, val; char opt = 'Y'; // To continue the do loop in case top = -1; // Initialization of Queue clrscr(); do { cout << "\n\t\t Main Menu"; cout << "\n\t1. Addition of Stack"; cout << "\n\t2. Deletion from Stack";

Page 15: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 15 -

cout << "\n\t3. Traverse of Stack"; cout << "\n\t4. Exit from Menu"; cout << "\n\nEnter your choice from above -> "; cin >> choice; switch (choice) { case 1: do { cout << "Enter the value to be added in the stack "; cin >> val; push(stack, val, top); cout <<"\nDo you want to add more elements <Y/N> ? "; cin >> opt; } while (toupper(opt) == 'Y'); break; case 2: opt = 'Y'; // Initialize for the second loop do { val = pop(stack, top); if (val != -1) cout << "Value deleted from statck is " << val; cout <<"\nDo you want to delete more elements<Y/N>?"; cin >> opt; } while (toupper(opt) == 'Y'); break; case 3: show_Stack(stack, top); break; case 4: exit(0); } } while (choice != 4); } // Function body for add stack with array void push(int stack[], int val, int &top) { if (top == MAX - 1) { cout << "Stack Full "; } else { top = top + 1; stack[top] = val; } } // Function body for delete stack with array int pop(int stack[], int &top) { int value; if (top < 0) { cout << "Stack Empty "; value = -1; } else { value = stack[top];

Page 16: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 16 -

top = top - 1; } return (value); } // Function body for show stack with array void show_Stack(int stack[], int top) { int i; if (top < 0) { cout << "Stack Empty"; return; } i = top; clrscr(); cout << "The values are "; do { cout << "\n" << stack[i]; i = i - 1; }while(i >= 0); } Q.10. Define functionstackpush( ) to insert nodes and stack pops ( ) to delete nodes . for a linked list implemented stack having the following structure for each node struct Node { Char name [ 20 ] Int age ; Node * link ; }; Class stuck { Node * top ; Public Stack ( ) { top = null ;} ; Void stackpush ( ); Void stack pop ( ) ; } Ans #include <iostream.h> #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <ctype.h> // Declares a stack structure struct node { char name[20]; int age; node *link; }; class stack { node *top; public : stack() { top = NULL; } void stackpush(); // Add stack

Page 17: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 17 -

void stackpop(); // Delete stack void show_Stack(); // Show stack }; // Function body for adds stack elements void stack::stackpush() { int val; node *temp; temp = new node; cout << "Enter name : "; gets(temp->name); cout << "Enter age : "; cin >> temp->age; temp->link = NULL; if(top ==NULL) top = temp; else { temp->link = top; top = temp; } } // Function body for delete stack elements void stack::stackpop() { node *temp; if (top == NULL) { cout << "Stack Empty "; } else { temp = top; top = top->link; temp->link = NULL; delete temp; } } // Function body for show stack elements void stack :: show_Stack() { node *temp; temp = top; clrscr(); cout << "The values are \n"; while (temp != NULL) { cout << "\n" << temp->name << "\t" << temp->age; temp = temp->link; } } // Main programming logic void main() {

Page 18: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 18 -

int choice; stack STACK; char opt = 'Y'; // To continue the do loop in case clrscr(); do { cout << "\n\t\t Main Menu"; cout << "\n\t1. Addition of Stack"; cout << "\n\t2. Deletion from Stack"; cout << "\n\t3. Traverse of Stack"; cout << "\n\t4. Exit from Menu"; cout << "\n\nEnter your choice from above "; cin >> choice; switch (choice) { case 1: do { STACK.stackpush(); cout<<"Do you want to add more elements<Y/N>?"; cin >> opt; } while (toupper(opt) == 'Y'); break; case 2: opt = 'Y'; // Initialize for the second loop do { STACK.stackpop(); cout<<"Do you want to delete more element<Y/N>?"; cin >> opt; } while (toupper(opt) == 'Y'); break; case 3: STACK.show_Stack(); break; case 4: exit(0); } } while (choice != 4); }

KENDRIYA VIDYALAYA SANGHATHAN Monthly Test Class: XII (Computer Science)

MM: 40 TIME: 01:30hrs Note: All questions are compulsory. Each question carrying 5 marks

Question No 1 Write a function in C++ which accepts an integer array and its size as arguments and change all the even number with twice and odd with thrice. Example: if an array of five elements initially contains the element as 2,4,1,5,7 then the function should rearrange the array as 4,8,3,15,21 Question No 2

Page 19: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 19 -

Write a function in C++ to return the element which is present maximum number of times in an array . the function prototype is given below.

Int MAX(int arr[], int size) e.g : If the array is 2 4 2 4 2 4 2 4 2 4 2 2 4 then the function will return a vale 2

Question no 3 An array A[40][10] is stored in the memory along the column with each element occupying 4 bytes. Find out the Base address and address of the element A[3][6] if the element A[30][10] is stored at the address 9000. Question no 4 Given two dimensional array A[10][20], base address of A being 100 and width of each element is 4 bytes, find the location of A[8][15] when the array is stored as a) column wise b) Row wise. Question No 5 An array M[-3…18][-8….37] is stored in the memory along the column with each of its elements occupying 8 bytes. Find out the base address and the address of an element M[2][5], if the element M[5][10] is stored at address 4000. Question No 6 Write a function in C++ to delete a node containing names of student, from a dynamically allocated stack of names implemented with the help of following structure : struct student { char name[20]; student *next; }; Question no 7 Write a user defined function in C++ to insert an element from a dynamically allocated Queue where each node contains the long integer (schoolno) as data. Assume the following definition of SCHOOL for the same.

struct SCHOOL {

long scno; SCHOOL * link;

}; Question no 8 Write a function in C++ to perform insert operation on a dynamically allocated Queue. 4

struct Node { Int Code; char Description[10]; Node * link; }

KENDRIYA VIDYALAYA SANGATHAN UNIT TEST NO : 1

MM : 40 TIME: 01:30hrs

Page 20: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 20 -

Note: All the questions are compulsory. Q No 1: Differentiate between an identifier and keywords. 1 Q No 2: Write the name of the header file to which the following belongs. 2

(i) abs() (ii) isalpha () (iii) puts() (iv) setw()

Q No 3: Write the name of the header file to which the following belongs. 2 (i) random() (ii) rand () (iii) getw() (iv) setw()

Q no 4: Write the name of the header files, which is/are essentially required to run/execute the following C++ code. 2 void main() { char CH ,Text[]=“ +ve Attitude”; for(int i=0;Text[ip!=’\0’,i++) if(text[i]==’ ‘) cout<<endl; else

{ CH= toupper(text[i]); cout<<CH; }

} Q No 5: What will be the output of the following code fragment produce ?

i)

2

int val, res, n=1000;

cin>>val;

res = n +val >1750 > 400:200; cout<< res;

ii)

1

int ch=20; cout<<ch<<++ch;

iii)

2

#include<iostream.h> int main()

{ int f=1,i=2; Do { f *=I; }while( ++I <5); cout<<f; return 0;

} Q No 6: Define a class Serial in C++ with the following specifications: 4 Private members of class serial Serialcode integer Title 20 characters Duration float Noofepisodes integer Public members of the class Serial

(i) A constructor function to initialize Duration as 30 and noofepisodes as 10.

(ii) Newserial () function to accept values for Serialcode and Title

Page 21: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 21 -

(iii) Otherentries () function to assign the values of Duration and Noofepisodes with

the help of cin statement.

(iv) Dispdata () function to display all the data members on the screen.

Q No 7: Answer the questions (i) to (iv) based on the following : 4 class WORLD { private : float A; protected :

char B[20]; int C; public: void READ( ); void WRITE( ); }; class COUNTRY: public WORLD { long double D; protected: long E; public: void INPUT( ); void OUTPUT( ); }; class STATE : private COUNTRY { private: short F; public: void INSTATE( ); void OUTSTATE( ); };

i) Which type of inheritance has been illustrated in the above code. ii) Name the data members which can be accessed by the objects of STATE class. iii) Name the member functions that can be accessed by the objects of STATE class. iv) How many bytes will be occupied by an object of class STATE?

Q No 8: What is the difference between constructor and destructor ? Give example of both. 4 Q No 9: Rewrite the following program after removing the systactical error(s) if any. 4 include <iostream.h> Vid main() { float p1,p2,num; p1=p2=0; for(int x=0;x<11;x++) { cin<<num;

if(num>0) p1 += num; else

p2 /= num; } cout<<p1>>p2; } Q No 6: Explain the following terms briefly. 2 * 4 = 8;

(i) Abstract class (ii) Concrete class (iii) Polymorphism (iv) Encapsulation

Q No 7: What is the difference between Type casting and automatic type conversion? Also give a

suitable C++ code to illustrate both. 4

Page 22: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 22 -

KENDRIYA VIDYALAYA SANGATHAN UNIT TEST NO : II

CLASS : XII (Computer Science) MM : 40 TIME: 01:30hrs

Note: All the questions are compulsory. 1 (a) Find the output of the following program. Assume that all required headers files have been included. (4) int funs (int &x, int y=10) { if (x%y == 10) return ++x; else return y-- ; } void main( ) { int p=20, q=23; q = funs(p,q); cout <<p<<”;”<<q<< endl; q = funs(p); cout <<p<<”;”<<q<<endl; } 1. (b) Name the header file to which the following belongs: (1)

(i)random() (ii)abs()

(c) Differentiate between run-time error and syntax error. (2)

(d) Rewrite the following code fragment after removing the syntactical error(s), if any.

Underline each correction (2)

class calc

{

int x=10;

float y;

calc()

{

y=5;

}

~calc { }

};

2. (a) Explain the role of access specifiers? (2)

(b) Given a class as follows:

class Student

{

int sno;

public:

Page 23: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 23 -

Student(int y) { sno=y; } //Constructor 1

Student(Student& s) { sno=s.sno} ; //Constructor 2

};

(i) Create an object such that it invokes Constructor 1. (1)

(ii) Create an object such that it invokes Constructor 2. (1)

(c) Define a class named “MyFolder” with the following specifications: (4)

Private members of the class

Filenames - an array of strings of size[10][25]

Availspace - long

Usedspace - long

Public members of class

Newfileentry() - a function to accept values of Filenames,

Availspace and Usedspace from user.

Retavailspace() - A function that returns the value of total

Kilobytes available.

(1 Kilobyte=1024 bytes)

Showfiles() - A function that displays the names of all

the files in MyFolder.

(d) Given the following class definitions. Answer the questions given

below: (4)

class Book

{

char Title[20];

char Author[20];

int No_Of_Pages;

public:

void read();

void display();

};

class TextBook : private Book

{

int no_of_chapters,no_of_assignments;

protected:

int standard;

public:

Page 24: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 24 -

void readtextbook();

void displaytextbook();

};

class ComputerBook : public TextBook

{

char Topic[20];

public:

readcomputerbook();

displaycomputerbook();

};

(i) Name the members which are accessed from the member functions of class

ComputerBook.

(ii) Name the members which are accessed by an object of class TextBook.

(iii) Name the members which are accessed by an object of class ComputerBook.

(iv) What will be the size of an object (in bytes) of class ComputerBook?

2. (a) Reusability of classes is one of the major properties of OOP. How it is implemented in C++? 2 (b) Answer the following questions (i) and (ii) after going through the following class : 2 class Employee { int Time; public: Seminar ( ) //Function 1 { Time = 30; cout<<”Seminar starts now “ <<endl; } void Lecture ( ) //Function 2 { cout<<”Lecturer in the seminar is on “<<endl; Seminar (int duration ) // Function 3 { Time = Duration; cout<<”Seminar starts now << endl; } ~seminar ( ) // Function 4 { cout << “Vote of thanks” <<endl; }

(i) In the object oriented programming, what is function 4 referred as and when does it get invoked?

(ii) In the object oriented programming, which concept is illustrated by function 1 and function 3 together?

(c) Define a class play in c++ which includes : 4 Private members Playcode integer Playtitle Char[25] Duration float

Page 25: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 25 -

Noofscenes integer Public members

A constructor to initialize duration 45 and noofscenes as 5

New_play( ) A function to accept code & title

More_info( ) A function to accept duration and no of scenes using arguments

Show_play( ) to display all data members on screen (d) Answer the questions (i) to (iv) based on the following: 4 class NATION { int H; protected: int S; public: void INPUT(int); void OUTPUT(); }; class WORLD: private NATION

{ int T; protected: int U; public: void INDATA(int,int); void OUTDATA(); }; class STATE: public WORLD { int M; public: void DISPLAY(void); };

i) Name the base class and derived class of WORLD ii) Name the data member(s) that can be accessed from function DISPLAY( ) iii) Name the member function(s), which can be accessed from the objects of class

STATE iv) Is the member function OUTPUT( ) accessible by the objects of class WORLD?

2. (a) What do you understand by DOMAIN and TUPLE of a RELATION? 2

(b) Write a SQL commands for (i) to (iv) and write the output for (v) on the basis of table FURNITURE. 7

Table : FURNITURE

NO ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT

1 White lotus Double Bed 23/02/02 30000 25

2 Pink feather Baby cot 20/01/02 7000 20

3 Dolphin Baby cot 19/02/02 9500 20

4 Decent Office Table 01/01/02 25000 30

5 Comfort Zone Double Bed 12/01/02 25000 25

6 Donald Baby cot 24/02/02 6500 15

7 Royal Finish Office Table 20/02/02 18000 30

8 Royal tiger Sofa 22/02/02 31000 30

9 Econo sitting Sofa 13/12/01 9500 25

10 Eating Paradise Dining table 19/02/02 11500 25

(i) To list the ITEMNAME which are priced at more than 15000 from the

FURNITURE table. (ii) To list ITEMANME and TYPE of those items, in which DATEOFSOTCK is

before 22/01/02 from FURNITURE table in descending order of ITEMNAME.

Page 26: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 26 -

(iii) To display ITEMANME and DATEOFSTOCK of those items, in which the discount percentage is more than 25 from FURNITURE table.

(iv) To count the number of items, whose TYPE is “sofa” from FURNITURE table. (v) Give the output of the following SQL statement.

(a) SELECT AVG(DISCOUNT) from FURNITURE where GROUP BY ITEMNAME

(b) Select SUM(PRICE) FROM FURNITURE WHERE DATEOFSTOCK<{12/02/02};

(VI) To display ITEMNAME whose name start with the letter ‘D’.

Page 27: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 27 -

CHAPTER – 4 DATA FILE HANDLING Q1, Assuming the class Vehicle as follows: Class vehicle { char vehicletype[10]; int no_of wheels; public: void getdetials() { gets(vehicletype); cin>>no_of_wheels; } void showdetails()] { cout<<”Vehicle Type”<<vehicletype; cout<<”Number of Wheels=”<<no_of_wheels; } } Write a function showfile() to read all the records present in an already exiting binary file SPEED.DAT and display them on the screen ,also count the number of records present in the file. Answer: Void showfile() { ifstream fin; fin.open(“SPEED.DAT”,ios::in|ios::binary); vehicle v1; int count=0; while (!fin.eof())

{ fin.read((char *)&v1,sizeof(v1)); count++; v1.showdetails();

} cout<<”Total number of records are “<<count; } Q2. Write a program that prints a text file on the printer. Answer:- #include<iostream.h> #include<fstream.h> #include<process.h> int main() { char filename[13], ch;

cout<<”enter the text file name :”; cin.getline(filename,13); ifstream fin; fin.open(filename); if(!fin) {cerr<<”\nFile can’t be opened !\n”; exit(-1); } ofstream fout; fout.open(“PRN”); while(fin.get(ch)!=0) fout.put(ch); return 0;

}

Page 28: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 28 -

Q3. Write a c++ program ,which initializes a string variable to the content.”Time is a grat teacher but unfortunately it kills all its pupils.Berlioz”and output the string one character at a time to the disk file OUT.TXT .You have to include all the header files required. Answer: #include<fstream.h> Int main() {

ofstream fout(“OUT.TXT”); Char*str=” Time is a grat teacher but unfortunately it kills all its pupils.Berlioz”; Int i=0; If(!fout) {

cout<<”File cannot be opened “; return 0;

} While (str[i]!=’\0’) {

fout<<str[i]; i++;

} fout.close(); } Q4. Write a program that display the size of a file in bytes. Answer: #include<iostream.h> #include<fstream.h> #include<process.h> #include<conio.h> int main() {

char filename[13]; clrscr(); cout<”Enter Filename:\n”; cin.getline(filename,13); ifstream infile(filename); if(!infile) {

cout>>”sorry ! Can not open “<<filename <<”file\n”; Exit(-1);

} int no_bytes=0; char ch; while(cin.get(ch)) {

no_bytes ++; }

cout<<”File Size is”<<no_bytes<<”bytes\n”; return 0; } Q5. What will be the output produced by the following code? Answer: #include<iostream.h> #include<fstream.h> #include<process.h>

Page 29: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 29 -

#include<conio.h> int main() { clrscr() char filename[13]; cout<<”Enter Filename:”; cin.getline(filename,13); ifstream in(filename); if(!in) {cout<<”Cannot open input file!\n”; return (0) } Char str[255]; While(in) {in.getline(str,255); Cout<<str<<”\n”; } in.close(); return 0; }

CHAPTER – 5 DATA BASE CONCEPT Q.1. What is foreign Key? What is its purpose? Ans: A non key attribute, whose value are derived from the primary key of some other table, is known as foreign key in the current table.

The table in which this non-key attribute i.e. foreign key attribute exists, is called a foreign table.

Q.2. Define the terms Tuple and Attribute Ans: Tuples: The rows of tables (relations) are generally referred to as tuples.

Attribute: The columns of tables are generally referred to as attribute.

Page 30: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 30 -

Q.3. What do you understand by the terms Cardinality and Degree of the table? Ans Degree: The number of attributes in a relation determines the degree of a relation. A relation having 3 attributes is said to be a relation of degree 3.

Cardinality: The number of rows in a relation is known as Cardinality. Q.4. What is the main function of DBA. Ans: The DBA must be a manager, more than a technician-seeking to meet the needs of people who use the data. Since many user may share the same data resource, the DBA must be prepared to meet the need and objective. Q.5. Write a query on the customers table whose output will exclude all customers with a rating <=100, unless they are located in Shimla. Ans. SELECT * FROM customers WHERE rating >100 OR city =’Shimla’ ; Q.6. Write a query that selects all orders except those zeros or NULLs in the amount field. Ans. SELECT * FROM Orders WHERE amt < >0 AND (amt IS NOT NULL) ; Q.7. Write a query that lists customers in descending order of rating. Output the rating field first, followed by the customer’s name and number. Ans. SELECT rating, cust-name, cust-num FROM customers ORDER BY rating DESC ; Q.8. Write a command that puts the following values, in their given order, into the salesman table:

cust-name-Manisha, city-Manali, comm.- NULL, cust-num-1901. Ans. INSERT INTO salesman (city, cust-name, comm.,cust-num) VALUES(‘Manisha’,NULL,1901) ; Q.9. What are DDL and DML? Ans:- The DDL provides statements for the creation and deletion of tables and indexes.

The DML provides statements to enter, update, delete data and perform complex queries on these tables.

Q.10. What is the difference between Where and Having Clause ? Ans: The HAVING clause places the condition on group but WHERE clause places the

condition on individual rows Q.11. What do you understand by constraints ? Ans: Constraints are used to enforce rules at table level when ever row is inserted, updated/deleted from table.

Constraints can be defined to one of the Two level. Column Level: Reference to a single column. can be defined any type of integrity.

Table Level: References one or more columns and is defined separately from definition of the columns in the table.

Q.12. Write some features of SQL?

Ans: Recovery ad Concurrency:- Concurrency is concerned with the manner in which multiple user operate upon the Database. Security: The Security can be maintained by view mechanism. Integrity Constraints-> Integrity constraints are enforced by the system.

Q.13. Write various database objects available in SQL?

Ans: Table: A Table is used to store Data View: A view is the temporary table created using Original table. Sequence: Sequences are used to generate Primary key value. Index: They are used to improve queries.

Page 31: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 31 -

Synonym: They give alternative names to objects.

Q.14. Write the rules to name an objects?

Ans :

The maximum length must be 30 character long.

The Object name should not contain quotation mark.

The name must start with letter.

The use of $ and # is discouraged in the object name.

A name must not be a reserved name.

Q.15. What are group Functions

Ans: The aggregate functions are group functions. They return result based on groups of rows. The group functions are AVG(), COUNT(), MAX(), MI N(), SUM()

Q.16. What are column alias?

Ans: In many cases heading table may not be descriptive and hence it difficult to understand. In such case we use columns alias It will change column heading with column alias.

Q.17. Write the SQL query commands based on following table

Table : Book

Book_id Book name Author_name Publisher Price Type Quantity

C0001 Fast Cook Lata Kapoor EPB 355 Cookery 5

F0001 The Tears William Hopkins

First Publi. 650 Fiction 20

T0001 My First c++ Brain & Brooke FPB 350 Text 10

T0002 C++ Brain works

A.W. Rossaine TDH 350 Text 15

F0002 Thunderbolts Anna Roberts First Publ. 750 Fiction 50

Table : issued

Book_Id Quantity Issued

T0001 4

C0001 5

F0001 2

Write SQL query for (a) to (f)

(a) To show book name, Author name and price of books of First Pub. Publisher (b) To list the names from books of text type (c) To Display the names and price from books in ascending order of their prices. (d) To increase the price of all books of EPB publishers by 50. (e) To display the Book_Id, Book_name and quantity issued for all books which have been

issued (f) To insert a new row in the table issued having the following data. ‘F0003’, 1 (g) Give the output of the following

i. Select Count(*) from Books ii. Select Max(Price) from books where quantity >=15 iii. Select book_name, author_name from books where publishers=’first publ.’ iv. Select count(distinct publishers) from books where Price>=400

Ans: (a) Select book_name, author_name , price from books where publisher=’First Publ’ (b) Select book_name from books where type=’Text’

Page 32: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 32 -

(c) Select book_name, price from books Order by Price; (d) Update books set price=price+50 where publishers=’EPB’ (e) Select a.book_id,a.book_name,b.quantity_issued from books a, issued b where

a.book_id=b.book_id (f) Insert into issued Values (‘F0003’,1); (g)

i. 5 ii. 750 iii. Fast Cook Lata Kappor

My First c++ Brain & Brooke iv. 1

Q.18. TABLE: GRADUATE

S.NO NAME STIPEND SUBJECT AVERAGE DIV.

1 KARAN 400 PHYSICS 68 I

2 DIWAKAR 450 COMP. Sc. 68 I

3 DIVYA 300 CHEMISTRY 62 I

4 REKHA 350 PHYSICS 63 I

5 ARJUN 500 MATHS 70 I

6 SABINA 400 CEHMISTRY 55 II

7 JOHN 250 PHYSICS 64 I

8 ROBERT 450 MATHS 68 I

9 RUBINA 500 COMP. Sc. 62 I

10 VIKAS 400 MATHS 57 II

(a) List the names of those students who have obtained DIV I sorted by NAME. (b) Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend received in

a year assuming that the STIPEND is paid every month. (c.) To count the number of students who are either PHYSICS or COMPUTER SC

graduates. (d) To insert a new row in the GRADUATE table:

11,”KAJOL”, 300, “COMP. SC.”, 75, 1 (e) Give the output of following sql statement based on table GRADUATE:

(i) Select MIN(AVERAGE) from GRADUATE where SUBJECT=”PHYSICS”; (ii) Select SUM(STIPEND) from GRADUATE WHERE div=2; (iii) Select AVG(STIPEND) from GRADUATE where AVERAGE>=65; (iv) Select COUNT(distinct SUBDJECT) from GRADUATE;

Assume that there is one more table GUIDE in the database as shown below: Table: GUIDE

(f) What will be the output of the following query:

SELECT NAME, ADVISOR FROM GRADUATE,GUIDE WHERE SUBJECT= MAINAREA;

Ans: (a) SELECT NAME FROM GRADUATE WHERE DIV='I' ORDER BY NAME; (b) SELECT NAME, STIPEND, SUBJECT, STIPEND*12 STIPEND_YEAR FROM GRADUATE; (c) SELECT SUBJECT, COUNT(NAME) FROM GRADUATE GROUPBY (SUBJECT)

HAVING SUBJECT='PHYSICS' OR SUBJECT='COMP. Sc.'; (d) INSERT INTO GRADUATE VALUES(11,'KAJOL',300,'COMP. Sc.',75,1);

MAINAREA ADVISOR

PHYSICS VINOD

COMPUTER SC ALOK

CHEMISTRY RAJAN

MATHEMATICS MAHESH

Page 33: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 33 -

(e) (i) MIN(AVERAGE) 63 (ii) SUM(STIPEND) 800 (iii) AVG(STIPEND) 420 (iv) COUNT(DISTINCTSUBJECT) 4

(f) SELECT NAME, ADVISOR FROM GRADUATE, GUIDE WHERE SUBJECT=MAINAREA; NAME ADVISOR DIVYA RAJAN SABINA RAJAN KARAN VINOD REKHA VINOD JOHN VINOD Q.19. Table: Employees

Empid Firstname Lastname Address City

010 Ravi Kumar Raj nagar GZB

105 Harry Waltor Gandhi nagar GZB

152 Sam Tones 33 Elm St. Paris

215 Sarah Ackerman 440 U.S. 110 Upton

244 Manila Sengupta 24Friends street New Delhi

300 Robert Samuel 9 Fifth Cross Washington

335 Ritu Tondon Shastri Nagar GZB

400 Rachel Lee 121 Harrison St. New York

441 Peter Thompson 11 Red Road Paris

Table: EmpSalary

Empid Salary Benefits Designation

010 75000 15000 Manager

105 65000 15000 Manager

152 80000 25000 Director

215 75000 12500 Manager

244 50000 12000 Clerk

300 45000 10000 Clerk

335 40000 10000 Clerk

400 32000 7500 Salesman

441 28000 7500 salesman

Write the SQL commands for the following : (i) To show firstname,lastname,address and city of all employees living in paris (ii) To display the content of Employees table in descending order of Firstname. (iii) To display the firstname,lastname and total salary of all managers from the tables

Employee and empsalary , where total salary is calculated as salary+benefits. (iv) To display the maximum salary among managers and clerks from the table

Empsalary. (v) Give the Output of following SQL commands:

(i) Select firstname,salary from employees ,empsalary where designation = ‘Salesman’ and Employees.empid=Empsalary.empid;

(ii) Select count(distinct designation) from empsalary; (iii) Select designation, sum(salary) from empsalary group by designation having

count(*) >2; (iv) Select sum(benefits) from empsalary where designation =’Clerk’;

Ans: (i) select firstname, lastname, address, city from employees where city='Paris'; (ii) select * from employees order by firstname desc; (iii) select employees.firstname, employees.lastname, empsalary.salary +

empsalary.benefits total_salary from employees, empsalary where employees.empid=empsalary.empid and designation='Manager';

Page 34: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 34 -

(iv) select max(salary) from empsalary where designation in('Manager','Clerk') (v) (i) select firstname, salary from employees, empsalary where

designation='Salesman' and employees.empid=empsalary.empid FIRSTNAME SALARY Rachel 32000 Peter 28000 (ii)select count(distinct designation) from empsalary; COUNT(DISTINCTDESIGNATION)

4 (iii)select designation, sum(salary) from empsalary group by designation having

count(*)>2; DESIGNATION SUM(SALARY) Clerk 135000 Manager 215000 (iv)select sum(benefits) from empsalary where designation='Clerk'; SUM(BENEFITS)

32000

CHAPTER – 6 BOOLEAN ALGEBRA 1. Prove that X.(X+Y)=X by algebraic method.

Solution: L.H.S.= X.(X+Y)=X .X + X .Y = X + X .Y = X .(1+Y) =X . 1 = X = R.H.S 2. Give duals for the following : a) A+ ĀB b) AB+ĀB

Solution: a) A. (Ā +B) b) (A + B). (Ā + B) 3. State and verify Involution law. Solution:

Involution Law states : Ā = A Truth Table: 4. State and verify Duality principle.

Solution: Principle of duality states that from every boolean relation, another boolean realation can be derived by (i) changing each OR sign(+) to an AND sign(-). (ii) changing each AND sign(-) to an OR sign(+) (iii) replacing each 1 by 0 and each 0 by 1.

The new derived relation is known as the dual of the original relation. Dual of A+ ĀB will be A+ ĀB = A. (Ā +B). 5. State and verify Absorption law in boolean algebra.

Solution: Absorption law states:

A Ā Ā

0 1

1 0

0 1

Page 35: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 35 -

(i) X + XY= X (ii) X ( X + Y) = X

Input Output

X Y X + XY

0 1 1 1

0 1 0 1

0 0 1 1

6. Draw logic circuit diagram for the following expression: Y= AB+BC+CĀ

Solution: a b Y c 7. State the distributive laws of boolean algebra. Soln: Distributive laws states: (i) X(Y+Z)=XY+XZ (ii) X+YZ=(X+Y)(X+Z) 8. Reduce the following Boolean expression using K-Map: F(P,Q,R,S)=Σ(0,3,5,6,7,11,12,15) Soln: R’S’ R’S RS RS’ P’Q’ P’Q

PQ

PQ’

This is 1 quad, 2airs & 2 lock Quad(m3+m7+m15+m11) reduces to RS Pair(m5+m7) reduces to P’QS Pair (m7+m6) reduces to P’QR Block m0=P’Q’R’S’ M12=PQR’S’

1 0

1

1 3

2

4

1 5

1 7

1 6

1 12

13

1 15

14

8

9

1 11

10

A

A

A

Page 36: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 36 -

hence the final expressions is F=RS + P’QS + P’QR + PQR’S’ + P’Q’R’S’ 9. Reduce the following Boolean expression using K-Map: F(A,B,C,D)=∏(0,1,3,5,6,7,10,14,15) Soln:

Reduced expressions are as follows: For pair 1, (A+B+C)

For pair 2, (A’+C’+D) For Quad 1, (A+D’)

For Quad 2, (B’+C’) Hence final POS expression will be Y(A,B,C,D)= (A+B+C) (A+C+D) (A+D) (B+C)

0 0 0

0 0 0

0 0

0

Page 37: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 37 -

CHAPTER – 7 COMMUNICATION AND NETWORK CONCEPTS Q.1 What is protocol? How many types of protocols are there? Ans. When computers communicate each other, there needs to be a common set of rules and instructions that each computer follows. A specific set of communication rules is called a protocol. Some protocol: PPP, HTTP, SLIP, FTP, TCP/IP Q.2 What is the difference between Networking and Remote Networking? Ans. The main difference between Networking and Remote Networking, is the network which we use in offices or other places locally such LAN or INTERNET and remote networking is one which we use TERMINAL Services to communicate with the remote users such WAN. Q.3 What is point-to-point protocol? Ans. A communication protocol used to connect computer to remote networking services include Internet Service Providers. In networking, the Point-to-Point protocol is commonly used to establish a direct connection between two nodes. Its primary use has been to connect computers using a phone line. Q.4 How gateway is different from router? Ans. A gateway operates at the upper levels of the OSI model and translates information between two completely different network architectures. Routers allow different networks to communicate with each other. They forward packets from one network to another based on network layer information. A gateway can interpret and translate the different protocols that are used on two distinct networks. Unlike routers that successfully connect networks with protocols that are similar, a gateway perform an application layer conversion of information from one protocol stack to another. Q.5 What is the role of network administrator? Ans. Basic tasks for which a network administrator may be responsible: Setting up and configuring network hardware and software. Installing and configuring network media and connections. Connecting user nodes and peripherals of all kinds to the network. Adding users to and removing users from the network. Managing user account. Ensuring the security of the network. Provide training to the users to utilize the network’s resources. Q.6 What is the difference between baseband and broadband transmission? Ans. Baseband is a bi-directional transmission while broadband is a unidirectional transmission. No Frequency division multiplexing possible in base band but possible in broadband.

SNo Baseband Broadband

1 Entire bandwidth of the cable is consumed by a signal

broadband transmission, signals are sent on multiple frequencies, allowing multiple signals to be sent simultaneously.

2 Digital signals Analog signals

3 bi-directional transmission unidirectional transmission

4 No Frequency division multiplexing possible

Frequency division multiplexing possible

5 Uses for short distance Uses for long distance

Q.7 What are the difference between domain and workgroup?

Page 38: KENDRIYA VIDYALAYA SANGATHAN REGIONAL OFFICE BHOPAL ... · Constructor Normal Function 1. Constructor has same name as class name. 1. A normal function can have any legal name but

- 38 -

Ans.

SNo Domain Workgroup

1. One or more computers are servers All Computers are peers.

2. If you have a user account on the domain, you can logon to any computer on the domain.

Each computer has a set of accounts.

3. There can be 100+ computers Typically not more then 20-30 computers

4. The computers can be on different local network

All computers must be on the same local netork.

Q.8 What is the differences between POP3 and IMAP Mail Server? Ans. IMAP is a standard protocol for accessing e-mail from a local server. A simpler e-mail protocol is Post Office Protocol 3 (POP3), which download mail to the computer and does not maintain the mail on the server. IMAP, e-mails are stored on the server, while in POP3, the messages are transferred to the client’s computer when they are read. Q.10 Name different layer of the ISO OSI Model. Ans. International Standard Orrganisation – Open Systems Interconnection has seven layers; Physical Layer Data Link Layer Network Layer Transport Layer Session Layer Presentation Layer Application Layer Q.11 What is client server architecture? Ans. To designated a particular node which is well known and fixed address, to provide a service to the network as a whole. The node providing the service is known as the server and the nodes that use that services are called clients of that server. This type of network is called Client-Server Architecture. Q.12 What is FDM? Give example. Ans. FDM-Frequency Division Multiplexing is used in analog transmission. It is often used in short distance. It is code transparent and any terminal of the same speed can use the same sub-channel after the sub-channel is established. The best example if FDM is the way we receive various stations in a radio. Q.13 describe the following in brief: i) MOSAIC ii) USENET iii) WAIS Ans. i) MOSAIC: is the program for cruising the internet. The National centre wrote this program for Super Computer application at the university of Illinois. It has a simple window interface, which creates useful hypertext links that automatically perform some of the menu bar and button functions. ii) USENET: is the way to meet people and share information. Usenet newsgroup is a special group set up by people who want to share common interests ranging from current topic to cultural heritages. iii) WAIS: is a WIDE AREA INFORMATION SERVER.