I Mid Semester May 01 : Class XII : Computer Science Max Mark 50 : Time Hrs 1. a) What is macro in C++? Give example b) Give the Header file for the following functions:- i) gets ( ) ii) tolower( ) 1 c) Rewrite the following program after removing syntax errors. Underline each correction. # include <iostream. h > one = 10, two = 0 ; call ( one ; two ) ; call ( two ) ; void call ( int a ; int b = 0 ) cout<< a << <<b << endl ; d) What is a Pointer? 1 e) Find the output of the following program segment : - # include <iostream.h> int * a, m [ ] = 10, 0, 0, 0 ; a = m ; m [ ] + = 0 ; cout << First = << * a << endl ; * a - = 10 ; a + = ; cout << Second = << * a << endl ; a++ ; cout << Third = << * a << endl ; cout << Forth = << m [ 0 ] << endl ; f) Find the output of the following program segment : - float cal ( int & x ) return 0.5 * ++ x ; float cal ( int & x, int y ) return x++ * y ; int a = 9, b = 5 ; cout << cal ( a, b ) << endl << cal ( b, cal ( a ) ) << endl ; cout << a << endl << b << endl ; 1
g) In the following program, find out which output (s) from the options given will not be expected from the program? # include <iostream. h > # include <stdlib.h> options : - randomize ( ); i ) 9 # 6 # int arr[ ] = 9, 6, N ; ii ) 19 # 17 # int change = random ( ) + 10 ; iii ) 19 # 16 # for( int c = 0 ; c < : c++ ) iv ) 0 # 16 # N = random ( ) ; cout << arr [ N ] + change << # ;. a) Rewrite the following program after removing syntax errors. Underline each correction. structure student int no = 10 ; char name [0] ; float fees ; ; st studuent ; cin >> st.name ; cout<< fees ; b) Find the output of the following program struct matrix int row, col ; ; void Print ( matrix p) cout << p. row << <<p.col << endl; void Cal ( matrix & A, matrix B ) A.row + = B.col ++ ; A.col + = ++ A.row + B.col ; matrix X =,6, Y = 7, 9 ; Cal ( X, Y ) ; Cal ( Y, X ); Print ( X ) ; Print (Y) ;. a) What is Data Abstraction? Explain with suitable example. b) Give two differences between Constructor and member function. Give example.
c) Rewrite the following program after removing errors. Underline the corrected statements. class sample ( ) int a, b ; void calculate ( ) ; sample ( ) ; void input ( ) ; void output ( ) ; s ; void input ( ) cin >> x >> y ; s. input ( ) ; output ( ) ; d) Consider the following class declaration and answer the following questions. class games int code; char name [ 0 ]; float charges ; games ( int cd, char nm [ ], float amt ) ; // function 1 games ( games & s ) ; // function ; i) Write statement to access function 1. ii) Write the function definition for function. ( Body of the function ) e) Define a class tour for the following descriptions:- Private members: Tourcode integer ( in the range of 1000 9000) Place string Nooftravelers integer Cost float Public member functions :- Accept ( ) a function to input values of all data members except cost. Calcost ( ) a function to calculate the cost based on following conditions. Cost = nooftravelers * 75.Give 5% discount if the no of travelers are more than 0 and less than 0. 7 % discount for 0 and more. Display ( ) a function to print all the data members.. a) Consider the following classes and answer the following questions : - class company int no [10] ; char Oname[10][0] ; company ( ) ; void input_one ( ) ; void output_one ( ) ; ;
class factory : protected company int no ; factory ( ) ; void input_two ( ) ; void output_two ( ) ; char Tname [ 5 ]; double a, b; ; class shop : public factory double T; void cal ( ) int t = a + b ; shop ( ) ; void display ( ); void Accept ( ) ; ; i) What will be the size of objects declared based on classes factory and shop? ii) Name the data members that can be accessed by the member function display( ). iii) Name the inherit member functions factory? iv) write the classes in which the data member Oname can be accessed? b) Consider the following class : class school int rollno ; char sname[0] ; float marks ; void result ( ) ; school ( ) ; void Enroll ( ) ; void Display ( ); ; class college long Tcode ; char Tname [ 0 ] ; float salary ; college ( ) ; void Enter ( ) ; void show ( ) ; ;
class university : public college, private school long ccode [ 10 ] ; char course [ 0 ] ; char startdate [ 8 ], enddate [ 8 ] ; university ( ) ; void commence ( ) ; void detail ( ); ; i) Name the member functions, which are accessible from objects of class university. ii) Name the data members, which are accessible from member function commence. iii) What is the size of object declared based on class college and university? iv) Which constructor will be accessed first when the object is declared based on class university? 5. a) Consider the following class stationary. class stationary int code ; char itemname [ 0 ]; float cost ; void input ( ) cin >> code >> itemname >> cost ; vod output ( ) cout<<code <<itemname<<cost ; int retcode ( ) return code; ; A binary file store.dat consists of records of stationary type. Write a function to display of a particular item when the code is accepted in the function. print error message if the search is unsuccessful. b) Consider a text file book.txt and write a function to copy all the words which are starting with a vowel onto a new file Newbook.txt. c) Consider a following program segment, which involves to find the number of records in a binary file, where each record is of the type employee. void count ( ) ifstream file( emp.dat,ios : : binary ) ; file.( ); cout<< Number of Records = << ; d) Consider the following structure product struct product char code ; char description [0] ; float price ; ; write a function to increase the price by 10 % for a particular item of a binary file "stock.dat" when the code is accepted in the function. Modify the record without using temporary file. e) What is the similarity and difference between ios::app and ios :: out? 5
I Mid Semester Exam May 01 Class XII (Computer Science ) Answer Key 1. a) 1 mark for explanation and 1 mark for any examples b) ½ mark for each correct output i) gets <stdio.h> ii) tolower <ctype.h> c) ½ mark for each error marks d) 1 marks For correct definition e) With working for correct answer marks First = 10 Second = 50 Third = 0 Forth = 0 f) With working for correct answer marks 60 5 11 6 g) mark for correct answer with justification. a) ½ mark for each error marks b) ½ mark for each correct answer, marks, 1 mark for working 1 9 7 76. a) 1 mark for definition, 1 mark for example b) 1 mark for differences and 1 mark for example. c) ½ mark for each error marks d) 1 mark for each correct answer, marks e) 1 mark for class declaration 1 mark1 for each function, marks. a) 1 mark for each correct answer marks b) 1 mark for each correct answer marks 5. a) ½ mark for opening the file m, ½ mark for closing the file 1 mark for loop and local variable declaration, 1 mark for body of program b) ½ mark for opening the file, ½ mark for closing the file 1 mark for loop and local variable declaration, 1 mark for body of program c) 1 mark for each correct answer void count ( ) ifstream file( emp.dat,ios : : binary ) ; file. seekg( 0,ios:: end ); cout<< Number of Records = << fob.tellg ( ) / sizeof (employee); d) ½ mark for opening the file m, ½ mark for closing the file 1 mark for loop and local variable declaration, 1 mark for body of program e) 1 mark for similarity and 1 mark for difference. 6