KUWAIT SAHODAYA EXAMINATION FIRST TERM 08-09 SUBJECT : COMPUTER SCIENCE (08) : CLASS - XII SET - Time : Hours MM=70 Instructions- (Based on the model of CBSE Exams). a) Find and write the output of the following C++ program code: struct Ticket char Level ; int price ; ; void compute ( Ticket & T ) if ( T.Level == A ) T.price + = 50 ; if ( T.Level == B ) T.price+ = 0 ; if ( T.Level == C ) T.price+ = 0 ; cout<< T.Level << : << T. price <<endl ; void main ( ) Ticket show [ ] = C, 00, A, 50, B, 50 ; for ( int c = ; c > = 0 ; ) compute ( show [ c - - ] ) ; b) Consider the following C++ code and find the possible output(s) from the options(i) to (iv) following it. Also, write the highest and lowest character that can be assigned in the array A when the value of j =. randomize(); char C[ ] = abcdefghij, A[ ] ; for( int j=0; j<; j ++) A[j]=C [ random(j+) ] ; for(int k=; k >= 0; k -- ) cout<<a [ k ]<<"#"; Options :- i) a # b # b # A # ii) c # c # b # a # iii) d # b # c # a # iv) d # c # b # a # c) Find and write the output of the following C++ program code: #define Change ( x ) x* - 5 int array [ ]=5,,9,; int *P=array, C; for(c=; C>=0; C--) array[c]=change (array [ c ]);
for (C=0; C<=; C++) cout<<*p<<":"; P++; d) Write the names of the correct header files to compile the code successfully: ifstream FIN("EXAM.TXT"); char ST[ ]="new"; char ST[]="Delhi"; int n = strlen(st); FIN<<ST<<n <<endl; e) Find and write the output of the following C++ program code: void Convert(int&Number, int& n, int m = ) inti ; for(i=n; i<= m ; i ++) Number += i; n = i ; intresult = 0, A=,B= 9; Convert(Result, A); cout<<result << & <<A<<"&"<<B<<endl; Convert(Result, A,B); cout<<result << & << A<<"&"<<B<<endl; Convert (Result, B, A ); cout<<result << & << A<<"&"<<B<<endl; f) What are the difference between call by value and call by reference? Give example. g) Rewrite the following C++ code after removing all syntactical errors with each correction underlined. Typedef double dob; amt dob; cout<<"enter the Amount :"; cin>>amt; for ( j = ; j<=0 ; j++) cout<<amt<< "*"<<j<<end; h) Write the type of C++ tokens from the following : (i) do (ii) defaut (iii) (iv) struct
) a) Write the definition of a class SHOP in C++ with following description : Private Members - ID // data member of integer type - QTY // data member of float type - RATE // data member of float type - Amount // data member of float type - CalAmount( ) // Member function to calculate and return QTY * RATE Public Members - GetDetail( ) // A function to allow user to enter values of ID, QTY, RATE. This Function should also call CalAmount( ) function to assign value for Amount. - DispDetail( ) // A function to display the values of all data members. b) Answer the questions (i) to (iv) based on the following: class Passenger int PCode; protected: char PName[0]; Passenger( ); void Enter( ); void Show( ); ; class Train int TID; protected: char TName[0]; Train( ); void Input( ); void Display( ); ; class Ticket : public Train, private Passenger int Day, Mon, Year; Ticket( ); void Accept ( ); void Show ( ); ; void main( ) Ticket T ; i) Which type of Inheritance out of the following is illustrated in the above example? ii) Write the names of all the members, which are directly accessible by the member Function Accept( ) of class Ticket. iii) Write the names of all the members, which are directly accessible by the object T of class Ticket declared in the main( ) function. iv) What will be the order of execution of the constructors, when the object T of class Ticket declared in the main( ) function?
c) Answer the questions (i) to (iv) based on the following: class First int A; protected: float A; First( ); void Get( ); void Show( ) ; ; class Second : private First int B; protected: float B; Second( ); void Get( ); void Show( ); ; class Third : public Second int C; Third( ); void Get( ); void Show( ); ; void main( ) Third T; //Statement ; //Statement i) What will be the size of Object T declared based on class Third? ii) Write the names of all the member functions, which are directly accessible by the object T of class Third as declared in main( ) function. iii) Write Statement to call function Show( ) of class Second from the object T of class Third. iv) What will be the order of execution of the constructors, when the object T of class Third is declared inside main( )? d) What are the differences between Constructor and destructor? Give points with example. e) Observe the following C++ code and answer the questions (i) and (ii). ; class TOP int n ; void Display( ) //Member Function cout<<num<<endl;
class BOTTOM: public TOP int m ; void Display( ) //Member Function cout<<num<<endl; ; void main( ) BOTTOM B ; //Statement //Statement i) Which Object Oriented Programming feature is illustrated by the member function () and function () in class TOP and BOTTOM? ii) Write Statement and Statement to execute Member Function and Member Function respectively using the object B. f) Observe the following C++ code and answer the questions (i) and (ii). class EXAM long Code; char EName[0]; float Marks; EXAM( ) //Member Function Code=00;strcpy(EName,"Noname");Marks=0; EXAM(EXAM &E) //Member Function Code=E.Code+; strcpy(ename,e.ename); Marks=E.Marks; ; void main( ) //Statement //Statement i) In OOP what is function? Also write the use of it. ii) Write Statement and Statement to execute Member Function and Member Function respectively.. a) Write definition for a function SUMROW ( int MAT[ ][0],intR,int C ) in C++, which finds sum of the first row and last row elements of the matrix MAT (Assuming C represents number of Columns and R represents number of rows integer ). The result should be:- Sum of First Row = Sum of Last Row = b) Consider the following structure declaration. struct Library 5
int BCode ; char BName [ 0 ]; ; Write a function to Push a book into the static stack where each book is based on structure Library. All the necessary variables are passed through parameters of the function. c) Write the definition of a function Reverse(int Ar[ ], int N) in C++, which should reverse the entire content of the array Ar having N elements, without using any other array. Example: if the array Ar contains 0 5 0 5 Then the array should become 5 0 5 0 d) T[0][0] is a two dimensional array, which is stored in the memory along the row with each of its element occupying bytes, find the address of the element T[5][0], if the element T[0][5] is stored at the memory location 55000. e) Write the definition of a function ReArange(int A[ ], int N) in C++, which should shift all the elements of the array A to left side and transfer the first element to the last location. Example: if the array A contains 5 9 5 5 Then the array should become 5 9 5 5 f) Write the definition of a member function ADDREC() for a class QUEUE inc++, to add a student in a dynamically allocated Queue of Students considering the following code is already written as a part of the program. struct STUDENT int RNO; char NAME[0]; STUDENT *Next; ; class QUEUE STUDENT *Rear,*Front; QUEUE( ) Rear=NULL; Front=NULL; void ADDEREC(); void DELETEREC(); ; g) Convert the following Infix expression into postfix expression by showing the content of stack for each step. ( A + B ) * C D / E h) Evaluate the following Postfix expression showing the stack contents for each step of calculation. 50, 0, /,5,-,,5,*,+. a) Consider the following function and give the out. The file consists of 00 records. Each record of the file is based class EMPLOYEE (in Q (b) ) void Display ( ) EMPLOYEE E ; ifstream file ( employee.dat, ios :: binary ) ; file.seekg ( * sizeof ( E ) ) ; file.seekg ( * sizeof ( E ) ) ; file. read ( ( char * ) & E, sizeof ( E ) ) ; 6
cout<< First = << file. tellg ( ) / sizeof ( E ) + ; file.seekg ( 0, is :: end ) ; cout<< Second = << file. tellg ( ) / sizeof ( E ) + ; file. close ( ) ; b) Consider the following class :- class EMPLOYEE int EID; char Name[0];float Salary; void INPUT( ) cin>>eid;gets(name);cin>>salary; void OUTPUT( ) cout<<eid<<":"<<name<< : <<Salary<<endl; float RetSal( )return Salary; int retno ( ) return EID ; void UPDATE ( ) cout<< Enter Salary ; cin>> Salary ; ; Write definition of a function SUMSAL( ) in C++ to find the total salary paid to all the employees in a company. The employee s detail of this company is stored in a binary file EMPLOYEE.DAT. Display the result in the function. c) Write a function definition SEARCH( ) in C++ to count all the articles the, a and an present in a text file TEXT.TXT. Note : Ensure that the, a and an are counted as independent words and not asa part of any other word. d) The following function is used to modify a record in a binary file EMPLOYEE.DAT where each record is based on class EMPLOYEE(in Q (b) ). Fill in the blanks to execute the code successfully. void Modify ( ) fstream file ; EMPLOYEE E ; file. open ( EMPLOYEE.DAT, ios :: binary ios :: in ios :: out ) ; while ( file. read ( (char * ) &E, sizeof ( E ) ) ) if ( E. RetSal ( ) < 000 ) E. UPDATE ( ); int pos = file. tellg ( ) ; // to set the position of file pointer in order to rewrite. // to write the updated record into the file. file. close ( ) ; e) Consider the Class EMPLOYEE and write a function to display the details of a particular employee from a binary file EMPLOYEE.DAT where each record is based on class EMPLOYEE( in Q (b) ). Accept the employee number in the function. f) Write a function to count number lower case vowels (only ) in a text file INFO.TXT. 7
KUWAIT SAHODAYA EXAMINATION FIRST TERM 08-09 SUBJECT : COMPUTER SCIENCE (08) : CLASS - XII Time : Hours MM=70 Instructions- (Based on the model of CBSE Exams) ANSWER KEY SET,, Q SET SET SET. a) c) h) (i) operator (ii) punctuator (iii) punctuator (iv) none (Full Marks for ALL correct answers - (i), (ii) and (iv)) (½ Mark for any TWO correct answers out of (i), (ii) and (iv)) ( Mark for any ONE correct answer out of (i), (ii) and (iv)) b) d) f) ½ marks for each difference, two points mark mark for example. c) a) d) (i) fstream (ii) string (½ Mark for writing each correct answer) NOTE: Any other header file to be ignored d) b) g) typedefdoubledob; dobamt ; cout<<"enter the Amount :"; cin>>amt; for (int j = ; j<=0 ; j++) cout<<amt<< "*"<<j<<endl; (½ Mark for correcting each correct Error) or ( Mark for only identifying all the errors correctly) e) h) a) B : 80 A : 50 C : 0 mark for each correct line Deduct ½ mark partial answer f) g) e) 9 & 5 & 9 5 & 0 & 9 7 & 0 & ( Mark for writing each correct line) Note:Deduct only ½ Mark for not considering any or all correct placements of & Deduct only ½ Mark for not considering any or all line break g) e) c) 5:9::7:(½ Mark for writing each correct value) Note:Deduct ½ Marks if the values are written in reverse order
h) f) b) Correct options (ii) and (iv) Lowest value of array A is a and Highest is c. a) c) d) mark for differences and mark for example. b) f) e) mark for correct answer ( function overloading / polymorphism ) mark for correct answer for statements. c) a) f) ½ mark for each correct answer. ½ mark for each correct statement. d) b) a) (½ Mark for declaring class header correctly) (½ Mark for declaring data members correctly) ( Mark for defining CalAmount() correctly) (½ Mark for taking inputs in GetDetails()) (½ Mark for invoking CalAmount() inside GetDetails()) (½ Mark for defining DispDetails() correctly) (½ Mark for correctly closing class declaration with a semicolon ; ) e) d) c) i) Multiple Inheritance ( Mark for writing correct option) ii) Data Members : PName, TName, Day, Month, Year Member function : Enter, passenger::show, Input ( ),Display ( ), Ticket :: show ( Mark for writing all correct member names ) iii) Input ( ),Display ( ), Accept ( ), Ticket :: show ( Mark for writing all correct member names ) iv) ( Mark for writing correct order) NOTE: No Marks to be awarded for any other combination/order. f) e) b) i) bytes ii) Get( ), ( Show() OR Three::Show( ) ) Get( ),Two::Show() iii) T.Two::Show() iv) First, Second, Third. a) c) d) ( Mark for writing correct formula (for Row major) OR substituting formula with correct values) (Mark for correct calculation) ( Mark for final correct address) b) e) c) ( ½ Mark for correctly writing the loop) ( ½ Mark for correctly writing the logic for reversing the content) c) g) a) (½ Mark for correctly writing the loop) ( Mark for adding first row elements and last row elements) (½ Mark for displaying the results) d) f) e) ( ½ Mark for correctly writing the loop) ( ½ Mark for correctly writing the logic for reversing the content) e) d) h) marks for correct steps using stack. Note reduce marks according to the position of the error.
f) b) g) marks for correct steps using stack. Note reduce marks according to the position of the error. g) h) b) (½ Mark for correctly writing the function heading) ( Mark for checking overflow error) (½ Mark for rest of the statements) h) a) f) ( Mark for creating a new Node) ( Mark for accepting values of RNO and NAME) (½ Mark for checking EMPTY condition) (½ Mark for assigning NULL to Rear and Front as T) (½ Mark for connecting Rear with T) (½ Mark for assigning Rear as T). a) c) b) (½ Mark for opening the file correctly) (Mark for reading records from the file) (Mark for comparing the records) (½ Mark for displaying the calculated sum.) b) e) c) ( Mark for opening the text file correctly) ( Mark for reading each character (using any method) from the file) c) a) e) (½ Mark for opening the file correctly) (Mark for reading records from the file) ( ½ Mark for comparing the records along with the input of value for search) d) b) f) ( Mark for opening the text file correctly) ( Mark for reading each characterfrom the file and search for vowels) e) f) d) ½ for each correct answer, mark for correct answer. file. Seekg ( pos sizeof ( E ) ) ; file. wirte ( ( char * ) & E, sizeof ( E ) ) ; f) d) a) ½ for each correct answer, mark for correct answer. First = 7 Second = 0