MOCK PRE-BOARD EXAMINATION 2017_18 Class : XII Computer Science ( Answer Key) 1. (a) In the context of inheritance, what is the difference between private and protected members of a class. Explain with suitable example. 2 Private members Protected members Private members of the class cannot be Protected members of the class can be inherited by the child class inherited by the child class Example : class capsules: public medicines private : int id; protected: char capsule_name[30]; char volume_label[20]; float price; capsules(); void entercapsuledetails(); void showcapsuledetails(); ; class antibiotics: public capsule int dosage_units; char side_effects[20]; int use_within_days; antibiotics(); void enterdetails(); void showdetails(); ; Here private members of class capsule are not inherited in class antibiotocs. (b) Answer the questions(i) & (ii) after going through the following class. 2 class interview int month; interview(int y) //constructor 1 month=y; interview( interview &t); // constructor 2 ; (i) create an object, such that it invokes constructor 1; (ii) write complete definition for constructor 2; (i) interview obj(10); (ii) interview( interview &t) month= t.month; XII / Comp. Science Page 1 of 12
(c) Answer the questions (i) to (iv) based on the following. 4 class medicines char category[10]; char date_of_manufacture[10]; char company[20]; medicines(); void entermedicinedetails(); void showmedicinedetails(); ; class capsules: public medicines protected: char capsule_name[30]; char volume_label[20]; float price; capsules(); void entercapsuledetails(); void showcapsuledetails(); ; class antibiotics: public capsule int dosage_units; char side_effects[20]; int use_within_days; antibiotics(); void enterdetails(); void showdetails(); ; (i) How many bytes will be required by an object of class medicines and an object of class antibiotics respectively? Medicine: 40, Antibiotics : 118 (ii) Write names of all the member functions accessible from the objects of antibiotics. entermedicinedetails(), showmedicinedetails(), entercapsuledetails(), showcapsuledetails(),enterdetails(), showdetails() (iii) Write names of all members accessible from member functions of class capsules. Member functions: entermedicinedetails(), showmedicinedetails(), entercapsuledetails(), showcapsuledetails() Data Members: capsule_name, volume_label, price (iv) What will be the order of invocation of the constructors, when the object T of class antibiotics is declared (inside main ())? medicines capsules antibiotocs 2. (a) Find the output of the following program segments. (Assume all header files included). 2 void changestring( char text[], int &counter) XII / Comp. Science Page 2 of 12
char *ptr=text; int length=strlen(text); for(; counter<length-2; counter+=2,ptr++) *(ptr+counter)=toupper(*(ptr+counter)); void main() int position=0; char message[]= Pointers Fun ; changestring(message,position); cout<<message<< @ <<position; PoiNteRs Fun@10 (b) Find the output of the following program segments. ( assume all header files included). 2 typedef char str80[80]; void main() char *notes; str80 str= VR2GooD ; int n=6; notes=str; while( n>=3) str[n]=(isupper(str[n])?tolower(str[n]):toupper(str[n])); cout<<notes<<endl; n--; notes++; VR2Good VR2GoOd VR2GOOd VR2gOOd 3. (a) Define a function REVERSE(int B[], int M) to replace each element of the array with its reverse. 3 For Example: If array contains 21 12 35 42 18 3 36 5 The changed array will be 12 21 53 24 81 3 63 5 int REV(int x) int rem,rev=0; while(x!=0) rem = x%10; rev = rev*10 + rem; x=x/10; return rev; void REVERSE(int a[10], int n) XII / Comp. Science Page 3 of 12
for(int i=0 ; i<n ; i++) cout<<endl<<rev(a[i]); (b) Write the definition of function ADDMID( int MAT[][10], int R, int C) in C++, which finds the sum of the middle row elements and sum of middle column elements separately. R denotes number of rows and C denoted number of columns. Assuming both R and C are odd numbers. 3 Ans : void ADDMID(int MAT[][10], int R, int C) int mid,sum=0; mid = R/2; for(int i=0 ; i<c ; i++) sum = sum+mat[mid][i]; cout<<"\n Sum of middle row : "<<sum; mid = C/2; sum=0; for( i=0 ; i<r ; i++) sum = sum+mat[i][mid]; cout<<"\n Sum of middle column : "<<sum; (c) An array T[30][20] is stored in the memory along the row with each of the elements occupying 4 bytes. Find out the base address and address of element T[20][15], if an element T[25][10] is stored at the memory location 9800. 3 No. of rows=m=30 No. of columns=n=20 Width=w=4 Let base address = b Memory location of A[25][10] = 9800 Address of A[i][j]= b+ ( (I-0) * n +(j-0)) *w 9800=b + (25 * 20 +10) * 4 =b+510*4 =b+2040 B=9800-2040= 7760 Now address of A[20][15] = 7760 +( 20 * 20 +15) * 4 =7760 +415 * 4 =7760 + 1660 =9420 (d) Write a function DISPLAYALTERNATE(int A[][], int m, int n) to display alternate elements starting from A[0][0]. 2 void DISPLAYALTERNATE( int A[][], int m, int n) ` int flag=1; for( int i=0; i<m;i++) for( int j=0; j<n; j++) XII / Comp. Science Page 4 of 12
if( flag==1) cout<<a[i][j]; flag= flag * -1; OR Any other logic to solve the program (e) Evaluate the following postfix expression using stack. Show status of stack for each operation 2 False, True, NOT, OR, True, False, AND, OR Scanned element operation Stack status Final output PUSH TRUE PUSH TRUE NOT POP TRUE EVALUATE NOT TRUE PUSH # OR POP POP EVALUATE OR PUSH # TRUE PUSH TRUE PUSH TRUE AND OR POP POP TRUE EVALUATE TRUE AND PUSH POP POP EVALUATE OR PUSH TRUE # ; POP AND PRINT (f) Convert the following infix expression to its equivalent postfix expression. Showing the stack contents for each step of conversion. 3 X Y / ( Z + U) * V elements operation Stack Expression ( Push ( X Print ( X - Push (- X Y Print (- XY / Push (-/ XY ( Push (-/( XY Z Print (-/( XYZ + Push (-/(+ XYZ U Print (-/(+ XYZU XII / Comp. Science Page 5 of 12
) Pop and print (-/ XYZU+ Pop and cancel * Push (-* XYZU+/ V Print (-* XYZU+/V ) Pop and print Pop and print Pop and cancel (- ( # XYZU+/V* XYZU+/V*- XYZU+/V*- (g) Write a complete definition of addition() and deletion() function in C++ in a dynamically allocated Queue containing names of Cities. 4 struct node char name[20]; node * next; ; class queue node *rear, *front, *temp; queue() front=rear=null; void addition() temp= new node; cout<< enter data value ; gets(temp->name); temp->next=top; if( rear==null) rear=temp; front=temp; else rear->next=temp; rear=temp; void deletion() if(front==null) cout<< Queue empty ; exit(0); else cout<< deleted element <<front->name; temp=front; front=front->next; delete temp; if( front==null) rear=null; ; XII / Comp. Science Page 6 of 12
4. (a) What is the use of seekg() and tellg() function in file operation. Also write syntax of each 2 seekg() is used to transfer the file pointer to a specific location. Syntax : fl1.seekg(+/-n, ios::beg/end/cur); F1.seekg(10, ios::beg); tellg() gives the placement of pointer i.e the number of bytes passed from beginning. Syntax : long n=fl1.tellg(); (b) Write down any two differences between text mode and binary mode files. 2 Text mode files Binary mode files Text files stores data in the form of ASCII characters. Binary files stores data in the same format as is stored in memory. Text files are slower to process as data translation takes place. It takes more time than binary files. Binary files are faster to process as no translation takes place. (c) Assuming that a text file named DAIRY.TXT contains some text written into it, write a function named countdo(), that reads the file and count and display all 3 letter words from the file. 2 void countdo() ifstream if1( dairy.txt ); char word[10]; int ctr=0; if1>>word; while(!if1.eof()) // while(if1) if( strlen(word) ==3 ) ctr++; cout<<endl<<word; if1>>word; if1.close(); cout<< The number of 3 letter words are <<ctr; OR Any other correct function definition performing the desired operation (d) Assuming a text file words.txt contains some text. Write a function which replaces all I present in a file by E. 2 Ans : void REPLACE() ifstream f1("words.txt"); ofstream f2("temp.txt"); char ch; f1>>ch; while(!f1.eof()) if(ch=='i') ch='e'; f2<<ch; f1>>ch; XII / Comp. Science Page 7 of 12
f1.close(); f2.close(); remove("words.txt"); rename("temp.txt","words.txt"); (e) Write a function in c++ to read and display the detail of all the users whose status is A from a binary file USER.DAT. Assuming the binary file USER.DAT is containing objects of class USER, which is defined as follows: 2 class user int uid; // user id char uname[20]; //user name char status; //user type a/i void register(); //function to enter the content void show(); //function to display all data member char getstatus() return status; ; void display() ifstream if1; if1.open( USER.DAT, ios::binary); user U; while( if1.read((char *)&U, sizeof(u))) if( U.getstatus()== A ) U.show(); if1.close(); 5. (a) How Alternate key is different from candidate key. Give suitable example of each through a table with sample data. 2 The table may have multiple candidate keys. Out of that user has to decide one to the primary key and others are automatically called alternate kay. If STUDENT table contains the fields admno class sec roll fname address percentage then candidate key may be (i) admno (ii) class + sec+ roll (iii) fname + address Suppose user selects admno as primary key then other groups are called alternate keys. (b) Consider the following tables EMPLOYEE and INCHARGE and answer (b1) and (b2) parts of the question: Table: EMPLOYEE EMPNAME BASIC DEPARTMENT DATEOFAPP AGE SEX KARAN 8000 PERSONNEL 27/03/97 35 M DIVAKAR 9500 COMPUTER 20/01/98 34 M DIVYA 7300 ACCOUNTS 19/02/97 34 F XII / Comp. Science Page 8 of 12
ARUN 8350 PERSONNEL 01/01/95 33 M SABINA 9500 ACCOUNTS 12/01/96 36 F JOHN 7400 ACCOUNTS 24/02/97 36 M ROBERT 8250 PERSONNEL 20/02/97 39 M RUBINA 9450 MAINTENANCE 22/02/98 37 F VIKAS 7500 COMPUTER 13/01/94 41 M MOHAN 9300 MAINTENANCE 19/02/98 37 M Table : INCHARGE DEPT HEAD PERSONNEL RAHUL COMPUTER SATYAM ACCOUNTS NATH FINANCE GANESH MAINTENANCE JACOB (b1) Write SQL commands for the following statements: 4 x1=4 (i) To display name of all employees who are more than 34 years of age in ascending order of their name. SELECT EMPNAME FROM EMPLOYEE WHERE AGE>34 ORDER BY EMPNAME; (ii) To display name, department and annual basic salary ( assume monthly basic given in the table). SELECT EMPNAME, DEPARTMENT, BASIC *12 FROM EMPLOYEE; (iii) To display number of employees who are either in PERSONNEL or COMPUTER department. SELECT COUNT(*) FROM EMPLOYEE WHERE DEPARTMENT= PERSONNEL OR DEPARTMENT= COMPUTER ; (iv) To display name, department, sex and head for all employees. SELECT EMPNAME,DEPARTMENT, SEX, HEAD FROM EMPLOYEE, INCHARGE WHERE EMPLOYEE.DEPARTMENT=INCHARGE.DEPT; (b2) Give the output of the following SQL queries: 4x ½ =2 (i) SELECT COUNT(DISTINCT DEPARTMENT) FROM EMPLOYEE; 4 (ii) SELECT EMPNAME, DEPARTMENT FROM EMPLOYEE WHERE EMPNAME like %A ; DIVYA ACCOUNTS SABINA ACCOUNTS RUBINA MAINTENANCE (iii) SELECT MAX(BASIC), MIN(BASIC) FROM EMPLOYEE where DATEOFAPP> 22/02/97 ; 9500 7400 (iv) SELECT EMPNAME, HEAD FROM EMPLOYEE, INCHARGE WHERE BASIC=9500 AND DEPARTMENT=DEPT; DIVAKAR SATYAM SABINA NATH 6. (a) Verify the following Boolean expression algebraically. 2 X.Y + Y.Z = X.Y.Z + X.Y.Z + X.Y.Z XY + Y Z = XY (Z+Z ) + (X+X )Y Z ( complementary law) = XY Z + XY Z + XY Z +X Y Z ( distributive) = XY Z + XY Z + X Y Z ( Idempotent law) XII / Comp. Science Page 9 of 12
(b) Write CANNONICAL SOP form of a Boolean function X + X Y + X Z. 2 X + X Y + X Z = X( Y+Y ) + X Y + X Z = XY + XY +X Y + X Z =XY(Z+Z ) +XY (Z+Z ) + X Y(Z+Z ) + X Z(Y+Y ) =XYZ+XYZ +XY Z+XY Z +X YZ+X YZ +X YZ+X Y Z =XYZ+XYZ +XY Z+XY Z +X YZ+X YZ +X Y Z (c) Reduce the Boolean expression using K-map. F(a,b,c,d) = (0,1,2,4,5,6,8,10) 3 c d c d cd cd ab cd 00 01 11 10 00 a b 1 01 a b 1 11 ab 0 4 1 1 1 3 5 7 1 1 6 2 10 ab 1 12 13 14 15 1 8 9 11 10 F= a c + b d + a d (d) Draw the logic circuit for the Boolean expression using NAND gates only. X.Y + X. Y 2 X Y (e) Write the dual of expression X + X. Y = X + Y 1 Ans : X. (X + Y ) = X.Y 7.(a) Write an advantage and disadvantage of using Optical fibre cable. 1 adv: it is guarantee secure transmission and has a very high transmission capacity. Dis adv: expensive, connection losses are common problem. (b) Expand the following terms 1 (i) HTTP (ii) GSM HTTP : Hyper Text Transfer Protocol GSM : Global Service for mobile communication ( mobilisation) XII / Comp. Science Page 10 of 12
(c) What is cyber crime? 1 Crimes committed with the use of computers or relating to computers through internet. Tampering with computer source documents, Hacking, publishing of information, child pornography, accessing protected system are under cyber crime. (d) What is the significance of cookies stored on a computer. 1 Cookies is small text file that web servers send to a web browser so that the web server can keep track of the user s activity on a particular website. (e) Bias Methodologies is planning to expand their network in India, starting with three cities in India to build infrastructure for research and development of their chemical products. The company has planned to setup their main office in Pondicherry- at three different locations and have named their offices as Back Office, Research Lab and Development Unit. The company has one more Research office namely Corporate Office in Mumbai. A rough layout of the same is as follows. 4 Approximate distances between these offices are as follows: Research lab to Back Office 110Mts Research lab to Development Unit 16Kms Research lab to Corporate Unit 1800Kms Back Office to Development Unit 13Kms INDIA Corporate Unit [Mumbai] Pondicherry Development Unit Research Lab Back Office In continuation of above, the company experts have planned to install the following number of computers in each of their offices. Research lab 158 Back Office 79 Development Unit 90 Corporate Unit 51 (i) Suggest network type ( out of LAN/MAN/WAN) for connecting each of the following offices. Research lab and Back office Research lab and Development Unit Research lab and Back office LAN Research lab and Development Unit MAN (ii) Which device you will suggest to be procured by the company for connecting all the computers within each of their offices out of the following devices? i. Switch/Hub ii. Modem iii. Telephone (I) Switch/Hub XII / Comp. Science Page 11 of 12
(iii) Which of the following communication medium, you will suggest to be procured by the company for connecting their local offices in Pondicherry for very effective and fast communication? Telephone cable Optical fibre Ethernet Cable Ethernet cable (iv) Suggest a cable/wiring layout for connecting the company s local offices located in Pondicherry. Also, Suggest an effective method /technology for connecting the company s regional offices with offices located in Mumbai. INDIA Pondicherry Corporate Unit [Mumbai] Development Unit Research Lab Back Office Satellite communication is required for connecting the company s regional offices located in Mumbai. (f) Kabir wants to purchase a Book online and he has placed the order for that book using an e- commerce website. Now, he is going to pay the amount for that book online using his Mobile, then he needs which of the following to complete the online transaction:- 1 1. A bank account, 2. Mobile phone which is attached to above bank account, 3. The mobile banking app of the above bank installed on that mobile, 4. Login credentials (UID & Pwd) provided by the bank, 5. Or all of above. Option No.5 (g) What do you mean by data encryption? For what purpose it is used for? 1 Ans : Data encryption is a technique used for data security in which original message is converted or encoded using an algorithm into a form not understood by anyone except the person who has the key to decode it. XII / Comp. Science Page 12 of 12