Sie sind auf Seite 1von 8

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"); cinNum; 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++)

};

for

D
} o

(int J = 0 ; J<=N2; ~++) coutDice[I] [J]; cQutendl;

I
d) c)

a)

[1J ,

[;JJ

This paper contains 8 printed sides


[DPSR/COMP12/2011-12/HY/Set A]

., -'.

Give the output of the following code. Assumethe header file included:
(a)

[2x4]

typedef char String [80] ; #define Change(CH) (CH>='O' && CH<='9')?CH+l:CH-l void main ()
{

String Word = "HY201l"; for(int I = strlen(Word)-l; 1>=0; 1--) Word[1] = Change(Word[1]); cout<<Word<<endl;
}

(b) void Rearrange(int


{

&x, int &y)

x=x+y; y=x-y; x=x-y;


}

void main ()
{

in t X [3] [3]= {{1 ,2 ,3} ,{4 ,5 ,6} ,{7 ,8 ,9} }; for(int 1=0;1<3; 1++)
{

Rearrange (X[1] [0], X[1] [2]);


}

for(1 = 0;1<3;
{

1++)

for(int J = 0;J<3; J++) coutX[1] [J]"#"; coutendl;


}
}

(c)

struct
{

Point

};
{

int X, Y;

void main () Point Pl, P2={320,SOO}; Pl.X = ++P2.Y; Pl.Y = P2.X--; coutPl.X' ,'Pl.Y"&"P2.X' ,'P2.Yendl; coutP2.X+Pl.X'#'++Pl.X'*'--P2.Xendl;
}

_______________________________________

1.

This paper contains 8 printed sides


[DPSR/COMP12/2011-12/HY/Set A]

(d) class Exam


{

int Duration; char Name [20] ; public: Exam(int D=3, char S[]="HY")
{

Duration = D; strcpy(Name, cout"Started"endl;


}

S);

Exam (Exam &E)


{

Duration = E.Duration*2; strcpy(Name,E.Name) ; Name[O]='F' ; } void Edit(int


{

D, char S[])

Duration = D; strcpy (Name, .S);


}

void Show () { coutDuration"&"Nameendl;

};
{

void main () Exam El (1,"MT") ; El. Show (); El.Edit(2,"WT") ; Exam E2(El); E2. Show ();
}

6.

Rewrite the following code after correcting the syntax error(s). Underline all corrections made:
(a) #include<iostream.h> void main ()
{

[3]

fstream File; open.File("Halfyrly.txt",ios:in) char String[ ]; while(File.getline(String


{

puts (String) ;
}

This paper contains 8 printed sides


[DPSR/COMP12/2011-12/HY/Set A]

File.close() ;
}

(b) #include<iostream.h> class MyClass


{
,

[3]

int Num; char Word[lO] ; public void Assign(int


{

N, char W[])

Num = N; Word = W;
}

void Output
{

coutsetw
} }

(10)Numsetw(20)

<<Word<<endl;

void main ()
{

MyClass M; M.Num=lO; strcpy(M.Word,"Exam"); M. Ou tpu

t ();

}
7.

Define a class Store having the following members: Private Members Itemno Integer type Itemname String type Qty Integer type Status String type

[4]

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 . Function AssignStatusO to assign value of Status based on Qty as follows: Qty Status >=100 Sufficient <100 and >=25 Low <25 Insufficient
8.

Given the following C++ code, answer the questions that follow:

..............

....--

.......................................

__

...........

This paper contains 8 printed sides


[DPSR/COMP12/2011-12/HY/Set A]

[4]

..............

_------_ ,_._--_
.....

_---

class Board char protected: char public: void void State[20]; Chairman[20]; BEnter(); BDisplay() ;

};
{

class School: public char protected: char public: void void Sname[20];

Board

Principal [20] ; SEnter (); Sdisplay() ;

};
{

class Department:
f

public

School

char Dname[20], Head[20]; public: void DEnter() ; void DDisplay() ;

};

(i) (ii) (iii) (iv)


9.

What type of inheritance is given above? What will be the size of an Object of classes Board, School and Department respectively? Name the members accessible to DDisplay(). Name the members accessible to an object of Department inside main() Given the following C++code
class Sample
{

[2]

int Sno; char Sname[20]; public: //function void Enter(); void Display() ; //function int RSno ()
{

to enter data members to display data members

return
}

Sno;

} :

v'

This paper contains 8 printed sides


[DPSR/COMP12/2011-12/HY/Set A]

void Edit(int
{

N) file; int C=O; //statement 1

fstream

Sample S; while(!file.eof(
{

//statement

c++;
if
{

(S.RSno()== N) cout"Enter S .Enter (); new values ... "; //statement //statement 3 4

}
file.close() ;
}

Write C++ statements for statements 1, 2, J and 4, which would perform the following corresponding tasks: (Assumenecessaryheader file(s) included)
Statement Statement Statement Statement

1 to open binary file Sample.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.

Write definition for a function FirstChar( ) which reads a text file "Test. txt" and prints the first character of each of its words in a different line. Example, if the file contains "A Text File" Then the output should appear as
A

T
F

[4]

11.

Write definition for a function FindPriceO, which reads a binary file Book.dat containing records of class Book (as given below). The function should display the Total Accumulated Cost of all those Booksfor which Number of Pagesis above 999. [4]
class Book
{

//Name of Book char Bname[20] ; int NoP; //Number of Pages float Cost; //Cost of Book public: void BEnter( ); //function to input data members void BShow( ); //function to display data members int RNoP ()
{
This paper contains 8 printed sides [DPSR/COMP12/2011-12/HY/Set A]

return NoP;
}

float RCost ()
{

return
}

Cost;

12.

Write definition for a function void Reverse(int A[], int N), which reverses the contents of the array A containing N number of integers. For example, 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. Write definition for a function Alter( int [3][3]) which accepts an integer array of size 3 x 3 as its argument. The function should rearrange the array such that the middle row elements get swapped with the middle column elements. Display the rearranged array in a matrix format. [4] Example: The array
123

5 (; ry 8 9

Should be rearranged and printed as 1 4


258

7
14.

6-TCf-

Eachelement of an array A[ -3...6, -5...4] requires2 bytes of storage. If the array is stored alongthe row and the addressof A[3,2] is 5500,then calculate the addressof the location A[4,-2]. [3] An array S[20] [15] is stored in the memory in column major form, with each element occupying 4 bytes of memory. If the address of 5(10][5] is 2000, then calculate the address of the location 5[15] [10]. [3] Evaluate the following postfix expression using a stack and show the contents of the stack after each operation: [2] 3,20, 4, I, *,5, -, 10, +

15.

16.

This paper contains 8 printed sides


[DPSR/COMP12/2011-12/HY/Set A]

17.
~8.

Convert the following infix expression to its equivalent postfix expression: (A + B) / (C - D) - E * F

[2]

(a)

Define a function to remove a student from an array-implemented queue of students,. which can contain a maximum of 9 students. The function should perform an underflow check and on availability of a student display his details alongwith a message"removed". [4]
struct
{

Student

int Admno; char Sname [20];

(b)

Define a function to Push an integer into a static Stack which can contain a maximum of 10 integers. The function should check for an overflow and on availability of space insert the integer into the proper location of the array. [4]

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

Das könnte Ihnen auch gefallen