CLASS XII SECOND TERM EXAMINATION 2017-2018 SUBJECT : COMPUTER SCIENCE SET A2 (SOLUTIONS) TIME ALLOWED : 3 HRS. MAX. MARKS:70 General Instructions : This paper consists of 6 questions. There are 7 printed pages Attempt all questions neatly and in order. Q1a) What do you understand by GSM? (1) Ans. GSM stands for Global System for Mobile Communications. GSM is a technique that uses narrowband TDMA (Time Division Multiple Access) to allow eight simultaneously calls on same radio frequency. b) What is the importance of URL in networking? (1) Ans. URL refers to Uniform Resource Locator. A URL stores the address of a web page on www. c) What is spam? (1) Ans Spam is flooding the Internet with many copies of the same message, in an attempt to force the message on people who would not otherwise choose to receive it. Most spam is commercial advertising, often for dubious products, getrich-quick schemes, or quasi-legal services. d) Which of the following unit measures the speed with which data can be transmitted from one node to another node of a network? Also, give the expansion of the suggested unit. (1) (i) Mbps (ii) KMph (iii) MGps Ans. (i) Mbps Mega bits per second. e) Granuda Consultants are setting up a secured network for their office campus at Faridabad for their day to day office and web-based activities. They are planning to have connectivity between 3 buildings and the head office situated in Kolkata. Answer the question (i) to (iv) after going through the building positions in the campus and other details, which are given below: (4)
Distance between various buildings: Building RAVI to Building JAMUNA Building RAVI to Building GANGA Building GANGA to Building JAMUNA Faridabad Campus to Head Office Number of Computers Building RAVI 25 Building JAMUNA 150 Building GANGA 51 Head Office 10 120 m 50 m 65 m 1460 km (i) Suggest the most suitable place (i.e., building) to house the server of this organization. Also give a reason to justify your suggested location. (ii) Suggest a cable layout of connections between the buildings inside the campus. (iii) Suggest the placement of the following devices with justification: (a) Switch (b) Repeater (iv) The organization is planning to provide a high speed link with its head office situated in the KOLKATA using a wired connection. Which of the following cable will be most suitable for this job? (a) Optical Fiber (b) Co-axial Cable (c) Ethernet Cable Ans.(i) Building Jamuna. As most computers are situated in this building and as per 80:20 rule of networking, maximum traffic should be local traffic. So server should be in building with maximum computers, i.e., building Jamuna. (ii)
(iii) (a) Switches are needed in every building as they help share bandwidth in every building. (b) Repeaters may be skipped as per above layout, (because distance is less than 100 m) however if building RAVI and building JAMUNA are directly connected, we can place a repeater there as the distance between these two buildings is more than 100 m. (iii) (a) Optical Fiber f) Anuradha is a web developer. She has designed a login form to input the login id and password of the user. She has to write a script to check whether the login id and the corresponding password as entered by the user are correct or not. What kind of script from the following will be most suitable for doing the same? (1) (i) JSP (ii) Client Side Script (iii) VB Script Ans. (i) JSP g) Which protocol helps us to transfer files to and from a remote computer? (1) Ans. FTP OR Telnet OR TCP Q2a) Define a class RESORT in C++ with following description: (4) Private members Rno //Data member to store Room No Name //Data member to store customer name Charges //Data member to store per day charges Days //Data member to store number of days of stay COMPUTE() //A function to calculate and return Amount as Days*Charges and if the value of Days*Charges is more than 11000 then as 1.02*Days*Charges Public Members Getinfo() //A function to enter the content Rno, Name,Charges and Days Dispinfo() //A function to display Rno, Name, Charges,Days and Amount (Amount to be displayed by calling function COMPUTE()) Ans : class RESORT { int Rno; char Name[20]; float Charges; int Days; float COMPUTE(); public:
void Getinfo(); void Dispinfo(); ; void RESORT::Getinfo() {cin>>rno; gets(name); cin>>charges; cin>>days; void RESORT::Dispinfo() {cout<<rno<< <<Name<< <<Charges<< <<Days<< COMPUTE()<<endl; float RESORT::COMPUTE() { float Amount = Charges*Days; if(amount>11000) Amount = 1.02*Days*Charges; return Amount; b) Explain the concept of constructor overloading with a suitable example in C++.(2) Ans: Overloaded constructors have the same name (name of the class) but different number of arguments. Depending upon the number and type of arguments passed, specific constructor is called. Since, there are multiple constructors present, argument to the constructor should also be passed while creating an object. c) Find the output of the following program: (3) #include<iostream.h> #include<conio.h> #include<ctype.h> #include<string.h> class Item { int Id ; char Name [20] ; float Price ; public : Item(int N=0, char M[]= "***", float P=100) { Id=N; strcpy(name, M); Price = P; void Rise(float P) {Price += P ; float RPrice() { return Price; void Show () { cout <<Id<< "#" <<Name<< "#" << Price<<endl ;
; void main () { Item I1, I2(5), I3(10, "Pen", 20) ; I3.Rise(I1.RPrice()) ; I2.Rise (I2.RPrice()) ; I1.Show() ; I2.Show() ; I3.Show(); Ans: 0#***#100 5#***#200 10#Pen#120 Q3a) What is the difference between #define and const? Explain with suitable example. (2) Ans: #define: It is a preprocessor directive in C++ for creating a Macro. Example: #define sqr(i) i*i const: It is an Access Modifier in C++ that assigns a constant (non modifiable) value to a variable. Any attempt in modifying the value assigned to such a variable is reported as an error by the compiler. Example: const float Pi = 3.14; b) Name the header files that shall be needed for the following code (1) void main( ) { char String[]= Hello ; cout<<setw(20)<<string; Ans: iostream.h iomanip.h c) Find the output of the following program: (3) #include<iostream.h> void main() { int X[ ] = {10,25,30,55,110; int *p = X; while ( *p < 110) { if ( *p%3!= 0 ) *p = *p + 1; *p = *p + 2; p++; for(int I = 4; I>=1 ; I--)
{ cout << X[I] << * ; if ( I%3 == 0) cout<<endl; cout<<x[0] * 3<<endl; Ans 110*56* 32*26*33 d) What is the difference between global & local variables? Explain with the help of an example. (2) Ans. A global variable is the one, which is declared outside all functions in the file & is available to all the functions & blocks defined in the file. A local variable is the one, which is declared inside a function or a block & is available to that function or block only. Example : #include<iostream.h> int A=2; int sum (int x, int y) { int z=x+y; return z; void main( ) { int B; B=A+sum(2,3); cout<<b; The variable A is global variable while x & y are local to function sum & B is local to function main. e) What will be the output of the following code: #include<iostream.h> (3) void Spill ( int A[ ], int N, int S) { for (int i=0; i<n; i++) if (i<s) A[i] *=i; A[i] /=i; void Display (int A[ ], int N) { for (int j=0; j<n; j++) if (j%2==0) cout<<a[j]<< % ;
cout<<a[j]<<endl; void main( ) { int Array[ ]= {30,40,50,20,10,5; Spill (Array,6,3); Display (Array,6); Ans 0%40 100%6 2%1 Q4a) Define the push( ), to insert nodes, and pop( ) to delete nodes for a linked implementation of a stack having the following structure of each node : (3+3) struct node { char name[30] ; int clss ; node * link; ; class stack { node * top; public : stack ( ) { top = NULL ; void push ( ); void pop ( ) ; ; Ans. void stack : : push( ) { node * nptr; nptr = new node; nptr link = NULL; cout << Enter name : ; gets(nptr name); cout << Enter the class : ; cin >> nptr clss ; if(top = = NULL) top = nptr; {nptr link = top; top = nptr;
void stack : : pop( ) { if(top = = NULL ) cout << Underflow!! { cout << Element being popped is \n ; cout << top name << ; << top clss<< endl; node * ptr; ptr = top; top = top link; delete ptr; b) Define member functions queinsert( ), to insert nodes and quedel( ), to delete nodes of a linked implemented queue where each node has the following structure: (3+3) struct node { char name[20]; int age; node * link; ; class queue { node * rear, * front ; public : queue() { front = NULL; rear = NULL; void queinsert( ); void quedel( ); ; Ans. void queue :: queinsert () { node * nptr; nptr = new node ; nptr -> link = NULL ; cout << enter the name and age for a new node ; gets ( nptr -> name); cin>>nptr -> age; if (rear == NULL ) { front = rear = nptr ; { rear -> link = nptr; rear = nptr ; void queue :: quedel ( )
{ node * nptr ; if ( front == NULL ) cout << underflow ; { ptr = front; if ( front == rear ) front = rear = NULL; front = front -> link; delete ptr; c) Write a member function to implement deletions in an array containing integer elements implemented as a circular queue. (3) Ans. int queue :: isempty ( ) { return ( front == -1); void queue :: quedel ( ) { int data ; if ( isempty ()) cout<< Underflow ; { data = q [front]; if ( front == rear ) front = rear = -1; if ( front == MAX ) front = 0; front ++ ; d) Evaluate the following postfix expression using a stack and show the contents of the stack after execution of each operation 5, 11, -, 6, 8,+, 12, *, /. (3) Ans. 5, 11, -, 6, 8,+, 12, *, /. Rules : Scanning from left to right (i) If operand Push (ii) If binary operator, pop twice if unary operator pop once (iii) Evaluate the result and push back STACK 1. 5 : operand : Push 5
2. 11 : operand : Push 5, 11 3. - : binary operator : pop # (empty stack) 4. Evaluate 5 11 = -6 : Push back - 6 5. 6 : operand : Push -6, 6 6. 8 : operand : Push -6, 6, 8 7. + : binary operator : pop twice - 6 8. Evaluate 6 + 8 = 14 ; push back -6, 14 9. 12 : operand : push -6, 14, 12 10. * : binary operator : pop back -6 11. Evaluate 14 * 2 = 168 : push back -6, 168 12. / : binary operator : pop twice # (stack empty) 13. Evaluate -6/168 = -1/28 : push back -1/28 14. End of Expression. Pop the result -1/28 = Result e) Convert the expression (TRUE && FALSE)! (FALSE TRUE) to postfix expression. Show the contents of the stack at every step. (3) Ans. (TRUE && FALSE)! (FALSE TRUE) ) Adding ) to the end of expression and inserting ( to the beginning of stack. Scanning from Left to Right S.No Symbol Stack Postfix Expression Y 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. ( TRUE && FALSE )! ( FALSE TRUE ) ( ( ( ( ( ( ( && ( ( && ( ( (! (! ( (! ( (! ( (! ( (! TRUE TRUE TRUE FALSE TRUE FALSE && TRUE FALSE && TRUE FALSE && TRUE FALSE && TRUE FALSE && FALSE TRUE FALSE && FALSE TRUE FALSE && FALSE TRUE TRUE FALSE && FALSE TRUE
13. ) End of Expression TRUE FALSE && FALSE TRUE! Q5a) Answer the questions (i) to (iv) based on the following: class ITEM { int Id; char IName[20]; protected: float Qty; public: ITEM(); void Enter(); void View(); ; class TRADER { int DCode; protected: char Manager[20]; public: TRADER(); void Enter(); void View(); ; class SALEPOINT : public ITEM, private TRADER { char Name[20],Location[20]; public : SALEPOINT(); void EnterAll(); void ViewAll(); ; i) Which type of Inheritance out of the following is illustrated in the above example? ii) Write the names of all the data members, which are directly accessible from the member functions of class SALEPOINT. iii) Write the names of all the member functions, which are directly accessible by an object of class SALEPOINT iv) What will be the order of execution of the constructors, when an object of class SALEPOINT is declared? Ans i) Multiple Inheritance ii) Name, Location, Manager, Qty iii) EnterAll(), ViewAll(), Enter(), View() iv) (i) ITEM() (ii) TRADER() (iii) SALEPOINT()
b) Observe the program segment given below carefully and fill the blanks marked as Statement 1 and Statement 2 using seekp ( ) and seekg ( ) functions for performing the required task. (1) # include <fstream.h> class Item { int Ino; char Item[20]; public: void Search (int); // Function to search and display the content of void modify (int); // a particular record no. // Function to modify the content of a particular record no. ; void Item :: Search (intrecno) { fstream File; File. Open ( STOCK.DAT, ios :: binary ios :: in); // Statement 1 File.read ((char*) this, sizeof(item)); cout<<ino<< = = << Item <<endl; File.close ( ); void Item :: Modify (intrecno) { fstream File; File.open ( STOCK.DAT, ios :: binary ios :: out); cout>>ino; cin.getline(item, 20); // Statement 2 File.write ((char*)this, sizeof(item)); File.close ( ); Ans. File.seekg ((RecNo 1 ) * sizeof (Item); Statement 1 File.seekp ((RecNo 1 ) * sizeof (Item)) ; Statement 2 c) Write a program to read a text file FILE.TXT and then create another file REVERSE.TXT which contains every line of FILE.TXT in the reverse order. (2) Eg. If content of FILE.TXT is Hello how are you? Bye leaving now. REVERSE.TXT should have?uoy era woholleh.won gnivaeleyb Ans. #include <fstream.h> # include <string.h> void main ( ) { ofstream fout ( REVERSE.TXT );
ifstream fin ( FILE.TXT ); char str [ 80 ]; fin.getline( str, 80 ); while ( fin ) { int len = strlen ( str ) ; char temp; for ( int i = 0 ; i<len / 2 ; i ++ ) { temp = str [ i ] str [ i ] = str [ len 1 i ]; str [ len 1 i ] = temp; str [ len ] = \ 0 ; fout<<str<<endl ; fin.getline( str, 80 ); fin.close ( ); fout.close ( ); d) Given a binary file SPORTS.DAT, containing records of the following structure type: struct Sports { char Event[20]; char Participant[10][30]; ; Write a function in C++ that would read contents from the file SPORTS.DAT and creates a file named ATHELETIC.DAT copying only those records from SPORTS.DAT where the event name is Athletics. (3) Ans : void SPORT() { fstream IS,OA; Sports S; IS.open( SPORTS.DAT,ios::binary ios::in); OA.open( ATHLETIC.DAT,ios::binary ios::out); while(is.read((char*) &S,sizeof(S))) { if(strcmp(s.event, Athletics )==0) OA.write((char *)&S,sizeof(S)); IS.close(); OA.close(); e) The array A[20][10] is stored in the memory with each element requiring one byte of storage if the base address of A is Co. Determine Co if the location of A[10][15] is 2000, when the array is stored in Row major form. (3) Ans. Total rows M = 20
Total Columns N = 10 W (size in bytes of each element) = 2 Row major form Add (A[ I ] [ J ]) = Base Address + w ( ( I 0 ) N + ( J 0 ) ) Add (A[ 10 ] [ 15 ]) = C 0 + 1 ( ( 10 0 ) 10 + ( 15 0 ) ) 2000 = C 0 + 1 (100 + 15) 2000 = C 0 + 115 C 0 = 2000 115 = 1885 Base Address of array A = 1885 Q6a) Write definition for a function void Primes (int A[], int N), which assigns N number of prime integers to the N number of locations of the array A. For example if N is passed as 5, then the array should store. (3) 2 3 5 7 11 Ans : void Primes(int a[],int n) { int num = 2; int i=0; if (n==1) a[i]=2; { while (i < n) { int nofac=0; for (int j=2;j<=num/2;j++) if (num%j == 0) nofac++; if (nofac == 0) { a[i]=num; i++; num++; b) What do you understand by memory leak? Explain briefly. (2) Ans. If the objects, that are allocated memory dynamically, are not deleted, the memory block remains occupied even at the end of the program. Such memory blocks are known as orphaned memory blocks. These orphaned memory blocks when increase in number, brings an adverse effect on the system. This situation is known as memory leak. c) Write definition for function void SnakesLadders (int A[4] [4]) which assigns natural numbers to the cells of the 2D array of order 4X4, exactly like the snake
and ladders game boars, starting from bottom left corner of the board, as follows: (3) 16 15 14 13 9 10 11 12 8 7 6 5 1 2 3 4 Ans: void SnakesLadders(int a[4][4]) { int num=1; for (int i=3;i>=0;i--) { if (i%2==1) for (int j=0;j<4;j++) {a[i][j]=num; num++; for (int j=3;j>=0;j--) {a[i][j]=num; num++; d) Find the output of the following (Assume all header files are included): (2) # include <iostream.h> #include<ctype.h> void main () { char STR [ ] = "HLY 2017" ; char *P = STR; while (*P!= '\0') { if (isdigit (*P)) *P +=2; if (isalpha(*p)) *P = *(P+1); *P = '*' ; P++; cout << STR << endl;
Ans : LY *4239