KENDRIYA VIDYALAYA SANGATHAN ERNAKULAM REGION FIRST PRE-BOARD EXAMINATION 2014-15 COMPUTER SCIENCE Time allowed: 3 hours Maximum Marks : 70 Instructions: (i) All questions are compulsory. (ii) Programming Language : C++ 1. (a) Differentiate between a Call by Value and Call by Reference, giving suitable examples of each. 2 (b) Name the header file that shall be needed for the successful compilation of the following C++ code. 1 void main() char spacecraft[40]; strcpy( spacecraft, Mangalyaan ); puts(spacecraft); (c) Rewrite the following C++ code after removing all the syntax error(s), if present in the code. Make sure that you underline each correction 2 include<iostream.h> class FLIGHT long flightcode; char description[25]; public ; void addinfo() cin>>flightcode; gets( description); void showinfo() cout<<flightcode; puts(description); void main() FLIGHT F; addinfo.f; showinfo.f;
(d) Obtain the output from the following C++ program as expected to appear on the screen after its execution. 2 int main() char *Text= "HIMALAYA"; int *P, Num[]=1,5,7,9; P=Num+1; cout<<*p<<text<<endl; Text++; P++; cout<<*p+2<<text+1<<endl; return 0; (e) Obtain the output of the following C++ program, which will appear on the screen after its 3 execution. #include<iostream> #include<stdio.h> #include<string.h> struct THREE_D ; int x,y,z; void movein(three_d &t, int step = 1) t.x += step; t.y -= step; t.z += step; void moveout(three_d &t, int step = 1) t.x -= step; t.y += step; t.z -= step;
int main() THREE_D t1=10,20,5, t2=30,10,40; movein(t1); moveout(t2,5); cout<<t1.x<< ", "<<t2.y<<", "<<t1.z<<endl; cout<<t2.x<< ", "<<t1.y<<", "<<t2.z<<endl; t2 = t1; movein(t1, 10); cout<<t1.x<< ", "<<t1.y<<", "<<t1.z<<endl; return 0; (f) In the following program, find the correct possible output(s) from the options: 2 #include<stdlib.h> #include<iostream.h> void main() randomize(); char direction[][10] = NORTH, SOUTH, EAST, WEST ; int i, t; for(i=3; i>0;i--) t = random(i) + 1; cout<<direction[t]<< # ; (i) NORTH#SOUTH#EAST# (iii) WEST#SOUTH#SOUTH (ii) WEST#EAST#WEST (iii) WEST#SOUTH#NORTH 2. (a) What do you understand by data encapsulation and data hiding? Also give an example in C++ to illustrate both. 2 (b) Answer the questions after going through the following class. 2
class Exam char subject[20]; int marks; Exam() //Function 1 strcpy(subject, Computer ); marks = 0; Exam(char p[]) //Function 2 strcpy(subject,p); marks[0]; Exam(int m) //Function 3 strcpy(subject, Computer ); marks = m; Exam(char p[], int m) //Function 4 strcpy(subject, p); marks = m; ; (i) Which feature of Object Oriented Programming is demonstrated using Function 1. (ii) Write statements in C++ that would execute Function 3 and Function 4 of class Exam. (c) Define a class BOOK with the following specifications. 4 Private members book_no integer type book_title 20 Characters price float(price per copy) No_Copy Integer type total_cost( ) A function to calculate the total cost for N number of copies Public members input() Function to read book_no, book_title, price, No_Copy and invokes total_coast()
purchase() Function to display all data members (d) Consider the following declarations and answer the questions given below: 4 class vehicle int wheels; protected: int passenger; void read_vehicle(int, int); void display_vehicle(); ; class heavyvehicle : private vehicle int fuel; protected: int load; void read_hv(int, int); void write_hv(); ; class bus : public heavyvehicle ; int passengers; void read_bus(); void display_bus(); (i) Which type of inheritance is shown in the above example? (ii) Write the names of those member functions, which can be accessed from the objects of class bus. (iii) Write the names of those data members, which can be directly accessible from the member functions of class bus. (iv) Is it possible to directly call function display_vehicle() of class vehicle from an object of class heavyvehicle?
3. (a) Write code for a function rotate (int S[], int N) in C++, to rotate the contents of the array S by one position towards the right. 3 For example if the original content of the array S is S[0] S[1] S[2] S[3] S[4] S[5] 57 11 10 16 19 6 The modified content will be S[0] S[1] S[2] S[3] S[4] S[5] 6 57 11 10 16 19 (b) An array Arrl25ll201 is stored along the row in the memory with each element requiring 4 bytes of storage. If the address of array element Arr[10][15] is 4200, find out the address of Arr[15][10]. 3 (c) Write a function printdiagonal(int A[][9], int size)in C++ which accepts a 2D array of integers and its size as arguments and displays the elements which lie on diagonals. 2 [Assuming the 2D Array to be a square matrix with odd dimension i.e. 3 3, 5 5, 7 7 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 (d) Evaluate the following expression in postfix notation: 2 10 20 + 25 15 - * 30 / (e) Consider the following structure. Write the defintion of function PUSH() to insert a new node inside stack and definition of POP(), to delete a node from the stack. 4 struct Node char name[20]; int age; Node *link; ; class STACK Node *top; STACK()top = NULL; void PUSH(); void POP(); ; 4. (a) Observe the program segment given below carefully and fill the blanks marked as statement 1 and statement 2 using tellg() and seekp() functions for performing the required task. 1
class PracFile int Pracno; char PracName[20]; int TimeTaken; int Marks; void EnterPrac( );// function to enter PracFile details void ShowPrac( ):// function to display PracFile details int RTime() return TimeTaken;// function to return TimeTaken void Assignmarks (int M)// function to assign Marks ; Marks = M; void AllocateMarks( ) fstream File; File.open( MARKS.DAT,ios::binary ios::in ios::out); PracFile P; int Record = 0; while (File.read(( char*) &P, sizeof(p))) if(p.rtime()>50) else File.close(); P.Assignmarks(0); P.Assignmarks(10); //statement 1 //statement 2 Record + + ; If the function AllocateMarks () is supposed to Allocate Marks for the records in the file MARKS.DAT based on their value of the member TimeTaken. Write C++ statements for the statement 1 and statement 2, where statement 1 is required to position the file write pointer to an appropriate place in the file and statement 2 is to perform the write operation with the modified record. (b) Write a function in C++ to count the number of vowels present in a text file BOOK.txt. 2
(c) Write a function in C++ to search and display details of all trains, whose destination is DELHI from a binary file TRAIN.DAT. Assuming the binary file is containing the objects of the following class: 3 class TRAIN ; int tno; char from[20]; char to[20]; char *getfrom()return from; char *getto() return to; void input(); void output(); 5. (a) What do you understand by the terms Primary key and Degree of a relation in relational Database? 2 NOTE : Answer the questions (b) and (c) on the basis of the following tables EMPLOYEES and EMPSALARY. Employees Empid Firstname Lastname Address City 10 Ravi Kumar Raj nagar GZB 105 Harry Waitor Gandhi Nagar GZB 152 Sam Tones 33 Elm st. Paris 215 Sarah Ackerman 440 U.S. 110 Upton 244 Manila Sengupta 24 Friends 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 Empsalary Empid Salary Benefits Designation 10 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
(b) Write the SQL queries: 4 (i) To display Firstname, Lastname, Address and City of all employees living in Paris from the table EMPLOYEES. (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 EMPLOYEES and EMPSALARY, where Total Salary is calculated as Salary+ Benefits. (iv) To display the Maximum salary among Managers and Clerks from the table EMPSALARY. (c) Write the output of the following SQL commands: 2 6. (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 ; (a) State Associative law and verify the same using truth table. 2 (b) Write the POS form of a Boolean function G(U,V,W), which is represented in a truth table as follows: 1 U V W G 0 0 0 1 0 0 1 1 0 1 0 0 0 1 1 0 1 0 0 1 1 0 1 1 1 1 0 0 1 1 1 1
(c) Write the equivalent Boolean expression for the following logic circuit: 2 (d) Reduce the following Boolean expression using K-Map 3 F(w,x,y,z) = Σ(0,2,4,5,7,8,10,12,13,15) 7. (a) What is web 2.0? 1 (b) Expand 1 (i) W3C (ii) FSF (c) Which type of network (out of LAN, PAN and MAN) is formed, when you connect two mobiles using Bluetooth to transfer a video? 1 (d) How is a hacker different from a cracker? 1 (e) Write two characteristics of WiMAX. 1 (f) What are cookies? 1 (g) The Hightech University is setting up its Academic Schools at Chandan Nagar and planning to set up a network. The university has 3 academic schools and one administration center as shown in the diagram below: 4
Center to center distances between various buildings is as follows : Law School to Business School Business School to Technology School Law School to Technology Sch 50m 70m 125m Technology School to Admin Center 80m Law School to Admin Center Business to Admin Center 175m 90m Number of computers in each of the Schools/Center is as follows: Law School 50 Technology School 150 Admin Center 15 Business School 30 (i) Suggest the most suitable place (i.e. School/Center) to install the server of this university with a suitable reason. (ii) Suggest an ideal layout for connecting these schools/center for a wired connectivity. (iii) Which device will you suggest to be placed/installed in each of these schools/center to efficiently connect all the computers within these schools/center? (iv) The university is planning to connect its admission office in the closest big city, which is more than 350 km from the university. Which type of network out of LAN, MAN or WAN will be formed? Justify your answer.