COMPUTER SCIENCE Half Yearly Examination 2011 Class - 12 Max marks: 70 1. Explain the term Programming.

Polymorphism with example, Time: 3 Hrs in Gontext of Object Oriented [2] [2x3]

2.

Differentiate between the following, giving suitable examples: a) Automatic Type Conversion and Type Casting b) #define and const c) Primitive and Non Primitive Data Structure Name the header files needed for executing the following code: void maine) { int Num; puts("Enter an Integer"); cin»Num; float Root = sqrt(Num); cout«"Square Root of = "«setw(10)«Num«"="«Root;
}

3.

[1]

4.

Given the following code, choose the correct option(s) for output of the code. Justify ybur answer. Assume header files included. void main ( )
{

[2]

randomize() ; char Dice[3] [4] = {"ooo", "000", "000" int Nl = random (3), N2 = random(3) for (int I=O; I<=Nl; I++)

};

r

for

}

D
} o

(int J = 0 ; J<=N2; ~++) cout«Dice[I] [J]; cQut«endl;

I
d) c)

0

a)

[1J ,

[;JJ

This paper contains 8 printed sides
[DPSR/COMP12/2011-12/HY/Set A]

'«Pl.X«'*'«--P2.Y = P2. -'. 1>=0. x=x-y.{7 . Give the output of the following code. { 1++) for(int J = 0. 1--) Word[1] = Change(Word[1]).5 . int &y) x=x+y. This paper contains 8 printed sides [DPSR/COMP12/2011-12/HY/Set A] . void main () Point Pl..1<3.6} .X--.Y«endl. 1++) { Rearrange (X[1] [0]. Pl.X««endl. J++) cout«X[1] [J]«"#".{4 . cout«Pl.X«'#'«++Pl. cout«P2.SOO}. Pl. } _______________________________________ 1.Y. { int X.9} }. cout«endl. #define Change(CH) (CH>='O' && CH<='9')?CH+l:CH-l void main () { String Word = "HY201l". P2={320. } for(1 = 0. } void main () { in t X [3] [3]= {{1 . } } (c) struct { Point }. y=x-y.X«' . for(int I = strlen(Word)-l. } (b) void Rearrange(int { &x. for(int 1=0. cout<<Word<<endl.2 .X+Pl.3} .. Y.X = ++P2.J<3.8 .1<3.'«P2. Assumethe header file included: (a) [2x4] typedef char String [80] .Y«"&"«P2.X«' . X[1] [2]).

txt". char S[]) Duration = D. Show (). public: Exam(int D=3.E. strcpy (Name.File("Halfyrly. { } void main () Exam El (1. Underline all corrections made: (a) #include<iostream.Name) . } void Show () { cout«Duration«"&"«Name«endl. char Name [20] ."MT") . Exam (Exam &E) { Duration = E. while(File.Duration*2.(d) class Exam { int Duration. char S[]="HY") { Duration = D.h> void main () { [3] fstream File. Rewrite the following code after correcting the syntax error(s). } 6. } S). puts (String) . strcpy(Name.Edit(2. } void Edit(int { D. Exam E2(El). El.getline(String» { ."WT") . open. Name[O]='F' . Show ().S). strcpy(Name. }. cout«"Started"«endl. El. .ios:in) char String[ ]. E2. } This paper contains 8 printed sides [DPSR/COMP12/2011-12/HY/Set A] .

•...•... __ ..... Public Members Function EnterltemO to input Itemno and Itemname Function ShowltemO to display all data members Function Update(int) to increment Qty by the value passed as parameter and invoke AssignStatusO •..... _--- .•. Word = W....•....•••."Exam")....... answer the questions that follow: _ .. strcpy(M... This paper contains 8 printed sides [DPSR/COMP12/2011-12/HY/Set A] - [4] ...Num=lO. } 7.. _------_ ..•... char Word[lO] .•••.. char W[]) Num = N... void main () { MyClass M..close() .. public void Assign(int { N...Word. . Function AssignStatusO to assign value of Status based on Qty as follows: Qty Status >=100 Sufficient <100 and >=25 Low <25 Insufficient 8.. Ou tpu t ()..•..•.•......•.h> class MyClass { ..•.. Define a class Store having the following members: Private Members Itemno Integer type Itemname String type Qty Integer type Status String type [4] ._.•. M.•. [3] int Num...••.. } (b) #include<iostream.. M.-- ..•.._--_ . • • • Given the following C++ code..File.... } void Output { cout«setw } } (10)«Num«setw(20) <<Word<<endl.•....••.

char Sname[20]. BDisplay() . What type of inheritance is given above? What will be the size of an Object of classes Board. Name the members accessible to an object of Department inside main() Given the following C++code class Sample { [2] int Sno. }. Chairman[20]. void DDisplay() . School and Department respectively? Name the members accessible to DDisplay(). Board Principal [20] . BEnter(). }. { class School: public char protected: char public: void void Sname[20]. } : v' This paper contains 8 printed sides [DPSR/COMP12/2011-12/HY/Set A] . { class Department: f public School char Dname[20]. Head[20]. void Display() . Sdisplay() . //function int RSno () { to enter data members to display data members return } Sno. (i) (ii) (iii) (iv) 9. }. SEnter (). public: void DEnter() .class Board char protected: char public: void void State[20]. public: //function void Enter().

int NoP. Write definition for a function FindPriceO. Write definition for a function FirstChar( ) which reads a text file "Test.close() . //Number of Pages float Cost. //function to input data members void BShow( ). which reads a binary file Book. txt" and prints the first character of each of its words in a different line. new values . 2. if { (S.dat containing records of class Book (as given below). while(!file. //statement //statement 3 4 } } file.void Edit(int { N) file. Example.Enter (). ". //function to display data members int RNoP () { This paper contains 8 printed sides [DPSR/COMP12/2011-12/HY/Set A] . } ~ Write C++ statements for statements 1.RSno()== N) cout«"Enter S . //Cost of Book public: void BEnter( ). J and 4..eof(» { //statement 2 c++. int C=O.dat for read and write 2 : to iread a record from the file into S 3 : to1place the put pointer at the beginning of Cth record 4 : to write the new values of S to the file 10. //statement 1 fstream Sample S. which would perform the following corresponding tasks: (Assumenecessaryheader file(s) included) Statement Statement Statement Statement 1 to open binary file Sample. The function should display the Total Accumulated Cost of all those Booksfor which Number of Pagesis above 999. if the file contains "A Text File" Then the output should appear as A T F [4] 11.. [4] class Book { //Name of Book char Bname[20] .

This paper contains 8 printed sides [DPSR/COMP12/2011-12/HY/Set A] . Write definition for a function void Reverse(int A[]. 10.2] is 5500.. If the address of 5(10][5] is 2000. } float RCost () { return } Cost. The function should rearrange the array such that the middle row elements get swapped with the middle column elements. if the array passedas parameter contains the values [4] Then the function should rearrange it to become LIOJ49~ Note: The array contents (Original or Reversed) are not to be displayed 13. [3] An array S[20] [15] is stored in the memory in column major form.then calculate the addressof the location A[4. If the array is stored alongthe row and the addressof A[3. which reverses the contents of the array A containing N number of integers.20. + 15. then calculate the address of the location 5[15] [10]. int N).return NoP. *. Write definition for a function Alter( int [3][3]) which accepts an integer array of size 3 x 3 as its argument.. Display the rearranged array in a matrix format. ry 8 9 Should be rearranged and printed as 1 4 258 3 7 14. [4] Example: The array 123 8 5 (.-2]. -. For example... 6-TCf- Eachelement of an array A[ -3.4] requires2 bytes of storage. . with each element occupying 4 bytes of memory.6. [3] Evaluate the following postfix expression using a stack and show the contents of the stack after each operation: [2] 3.5. 4. } 12. -5. 16. I.

char Sname [20]·. Convert the following infix expression to its equivalent postfix expression: (A + B) / (C . (b) Define a function to Push an integer into a static Stack which can contain a maximum of 10 integers. ~8.. The function should check for an overflow and on availability of space insert the integer into the proper location of the array. int Admno.17. The function should perform an underflow check and on availability of a student display his details alongwith a message"removed".D) .E * F [2] (a) Define a function to remove a student from an array-implemented queue of students. [4] This paper contains 8 printed sides [DPSR/COMP12/2011-12/HY/Set A] . [4] struct { Student } . which can contain a maximum of 9 students.