JB ACADEMY HALF-YEARLY EXAMINATION 2016 CLASS XII COMPUTER SCIENCE Time: 3:00 Hrs. M.M.: 70 Q.1 (a) Explain in brief the purpose of function prototype with the help of a suitable example. (b) Identify the errors in the following program code: #include<iostream.h> void main( ) int A[10]; A=[3,2,5,4,7,9,10]; for( p = 0; p<=6; p++) { if(a[p]%2==0) int S = S+A[p]; } cout<<s; } Rewrite the following program after removing the syntactical error(s) if any. Underline each correction. #include<iostream.h> void main( ) { Struct movie { char moviename[20]; char movietype; int tic_cost=100; } MOVIE; cout << enter movie name &movie type\n ; gets(moviename); gets(movietype); } (d) Find the output of the following C++ program: class Class { int Cno,total; char section; Class(int no=1) { Cno=no; section='a'; total=30; } void addmission(int c=20) { section++; total+=c; } void ClassShow() { cout<<cno<<":"<<section<<":"<<total<<endl; } } ; void main() { Class C1(5),C2; C1.addmission(25); C1.ClassShow(); C2.addmission(); C1.addmission(30); C2.ClassShow(); C1.ClassShow(); } Pg-1
(e) Study the following C++ program and select the possible output(s) from it. void main() { randomize(); char city[ ]={ PKD, EKM, TVM, KOL, CAL }; int ZEN; for(int i=0;i<3;i++); { ZEN=random(2)+1; cout<<city[zen]<< @ ; } } (i) PKD@ EKM @TVM@ (iii) TVM@KOL@CAL@ (ii) EKM @TVM@ EKM @ (iv) TVM@ EKM @TVM@ (f) Find the output of the following program : #include<iostream.h> void switchover(int A[ ],int N, int split) { for(int K = 0; K<N; K++) if(k<split) A[K] += K; else A[K]*= K; } void display(int A[ ],int N) { for(int K = 0; K<N; K++) If (K%2== 0) cout<<a[k]<<"%" else cout<<a[k]<<endl; } void main( ) { int H[ ] = {5,10,20,50,40,30}; switchover(h,6,3); display(h,6); } Q.2 (a) How encapsulation and abstraction are implemented in C++ language? Explain with an example. (b) What is Function Overloading? Give an example in C++ to illustrate the same using constructor. What do you mean by virtual base class? How is it use full in programming? (d) Answer the questions (i) to (iv) after going through the following class. class player { int health, age; public : player() { health = 7; age = 17; } //constructor1 player( int h, int a) { health=h; age= a; } // constructor 2 player(player &p) {...} //constructor 3 ~player() { cout << \nmemory free ; }; void main() { player p1(9,26); //statement 1 player p2 = p1; //statement 2 } Pg-2
(i) (ii) (iii) Write the name of construtor1, constructor2 and constructor3. When p2 object is created, specify which constructor gets invoked and why? Write complete definition of constructor. Q.3 (a) Define a class Tourist in C++ with the following description : Data Member: cno to store city no., Ctype to store character A, B, C, D as city type, perkm to store kilo Meter charges, dis to store distance travelled (in KM) Member Function: A constructor to initialize data members as Ctype as A and Cno as 0. A function citycharges to assign perkm as per the following table : Ctype PerKm A 20 B 18 C 15 A function RegisterCab() to allow user to enter the values of Cno and Ctype and also call citycharges() to assign perkm charges. A function DisplayCab() to show the data members. (b) Define a class Departmental with the following specification : private data members :- Prod_name string (45 charactes) [ Product name] Listprice long Dis_Price long [ Discount Price] Net long [Net Price ] Dis_type char(f or N) [ Discount type] Cal_price() The store gives a 10% discount on every product it sells. However at the time of festival season the store gives 7% festival discount after 10% regular discount. The discount type can be checked by tracking the discount type. Where F means festival and N means Non-festival.The Cal_price() will calculate the Discount Price and Net Price on the basis of the following table. Product Name List Price(Rs.) Washing Machine 12000 Colour Television 17000 Refrigerator 18000 OTG 8000 CD Player 4500 public members :- Constructor to initialize the string elements with NULL, numeric elements with 0 and character elements with N Accept() Ask the store manager to enter Product name, list Price and discount type. The function will call Cal_price() to calculate Discount Price and Net Price. ShowBill() To generate the bill to the customer with all the details of his/her purchase along with the bill amount including discount price and net price. Answer the questions (i) to (iv) based on the following code : class DRUG { char catg[10]; char DOF[10], comp[20]; DRUG( ); void endrug( ); Pg-3
void showdrug( ); }; class TABLET { protected: char tname[30],volabel[20]; TABLET( ); void entab( ); void showtab( ); }; class PAINKILLER : protected DRUG, public TABLET { int dose, usedays; long double, price; char seffect[20]; public : void entpain( ); void showpain( ); }; (i) How many bytes will be required by an object of PAINKILLER (ii) Write names of all the member functions of class PAINKILLER. (iii) Write names off all members accessible from object of class PAINKILLER. (iv) Write names of all data members accessible from functions of class PAINKILLER. (d) Consider the following C++ declaration and answer the questions given below: class A { void any( ); protected: int a, b; void proc( ); A(); void geta( ); void puta( ); }; class B : protected A { int c,d; protected: int e, f; void getb( ); int g; B ( ); void putb( ); }; class C : private B { int p; protected: int q; void getc( ); int r; void showc( ); }; i. Name all the member functions and data members which are accessible by the object of class C? ii. Name the base class and derived class of class B? iii. Name the data members which are accessible from member functions of class C? iv. How many bytes will an object belonging to the class C require? Q.4 (a) Suppose an array P containing float is arranged in ascending order. Write a user defined Pg-4
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 to show presence of the number in the array. the function should have the parameters as (1) an array P (2) the number DATA to be searched (3) number of elements N. (b) Suppose A,B,C are arrays of size m, n, m+n respectively. Array A is stored in ascending order and array B is in descending order. Write a function to receive 3 arrays and their sizes to store the elements of A and B into C in descending order. Write a function in C++ to perform Insert and delete operation in a static stack containing integers. (d) Write a function in C++, which accepts an integer array and its size as arguments and swap the elements of every even location with its following odd location. example : if an array of nine elements initially contains the elements as 2,4,1,6,5,7,9,23,10 then the function should rearrange the array as 4,2,6,1,7,5,23,9,10 Q.5 (a) Assume a text file coordinate.txt is already created. Using this file create a C++ function to count the number of.words having first character capital. (b) Write a function in C++ to count and display the no of three letter words in the file VOWEL.TXT. Example: If the file contains: A boy is playing there. I love to eat pizza. A plane is in the sky. Then the output should be: 4 Write a function in C++ to search for a laptop from a binary file "LAPTOP.DAT" containing the objects of class LAPTOP (as defined below). The user should enter the Model No and the function should search and display the details of the laptop. class LAPTOP { long ModelNo ; float RAM, HDD ; char Details [120] ; void StockEnter ( ) { cin>>modelno>>ram>>hdd; gets (Details); } void StockDisplay ( ) { cout<<modelno<<ram<<hdd<<details<<endl; } long ReturnModelNo ( ) {return ModelNo ;} } ; (d) Observe the program given below carefully, and answer the question that follows: class Member { int Member_no ; char Member_name[20] ; public : void enterdetails ( ) ; //function to enter Member details void showdetails ( ) ; //function to display Member details int RMember_no( ) //function to return Member_no { return Member_no ;} } ; Pg-5
void Update (Member NEW) { fstream File ; File.open( MEMBER.DAT, ios :: binary l ios :: in l ios :: out) ; Member OM ; int Recordsread = 0, Found = 0 ; while (!Found && File.read((char*) & OM, sizeof(om))) { Recordsread++ ; if (NEW.RMember_no( ) == OM.RMember_no( )) { // Statement 1 // Statement 2 Found = 1 ; } else File.write((char*) & OM, sizeof(om)) ; } if (!Found) cout<< Record for modification does not exist ; File.close( ) ; } If the function Update( ) is supposed to modify a record in file MEMBER.DAT with the values of Member NEW passed to its argument, write the appropriate statements for statement1using seekp( ) or seekg( ) whichever needed, statement 2 using read( ) or write( ) method, whichever needed in the above code that would write the modified record at its proper place. Q.6 (a) What are different file modes? What is their role in handling data file? (b) Write about following terms: (i) getline ( ) (ii) file pointers (iii) Containership (iv) Explicit constructor Name the header files, to which the following built-in functions belong. (i) strcpy( ) (ii)random( ) (iii) islower( ) (iv) gets( [1] Pg-6