Computrr Class 12 Paper

Embed Size (px)

Citation preview

  • 8/13/2019 Computrr Class 12 Paper

    1/8

    Max marks: 70

    COMPUTERSCIENCEHalf Yearly Examination 2011Class - 12 Time: 3 Hrs

    1. Explain the term Polymorphism with example, in Gontext of Object OrientedProgramming. [2]2. Differentiate between the following, giving suitable examples: [2x3]a) Automatic Type Conversion and Type Castingb) define and constc) Primitive and Non Primitive Data Structure3. Name the header files needed for executing the following code: [1]void maine)

    { int Num;puts Enter an Integer );cinNum;float Root = sqrt Num);cout Square Root of = setw 10)Num = Root;

    }

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

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

  • 8/13/2019 Computrr Class 12 Paper

    2/8

    - . Give the output of the following code. Assumethe header file included: a) typedef char String [80];

    define Change(CH) (CH>='O' && CH=0; 1--)Word[1] = Change(Word[1]);cout

  • 8/13/2019 Computrr Class 12 Paper

    3/8

    d class Exam{

    int Duration; char Name [20];public:

    Exam(int D=3, char S[]= HY ){

    Duration = D; strcpy(Name, S);cout Started endl;}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 allcorrections made:

    a includevoid main (){

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

    puts (String) ;}

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

    [ ]

  • 8/13/2019 Computrr Class 12 Paper

    4/8

    File.close() ;}

    Integer typeString typeInteger typeString type.

    7.

    b includeclass MyClass{ ,

    int Num;char Word[lO] ;publicvoid Assign(int N, char W[]){

    Num = N;Word = W;

    }void Output{

    coutsetw (10)Numsetw(20)

  • 8/13/2019 Computrr Class 12 Paper

    5/8

    class Boardchar State[20];

    protected:char Chairman[20];public:

    void BEnter ;void BDisplay ;};

    class School: public Board{

    char Sname[20];protected:

    char Principal [20] ;public:

    void SEnter ;void Sdisplay ;

    };class Department: public School{

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

    void DDisplay ;};i What type of inheritance is given above?ii What will be the size of an Object of classes Board, School and Departmentrespectively?iii Namethe members accessible to DDisplay .iv Name the members accessible to an object of Department inside main

    9. Given the following C++codeclass Sample{

    [ ]

    int Sno;char Sname[20];

    public:void Enter ;void Display ;int RSno{

    //function to enter data members//function to display data members

    return Sno;}

    } :

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

    v

  • 8/13/2019 Computrr Class 12 Paper

    6/8

    void Edit(int N){

    fstream file; int C=O;//statement 1

    Sample S;while( file.eof({

    //statement 2c++;if (S.RSno()== N){

    cout Enter new values ...;S .Enter ();

    //statement 3//statement 4

    }} ~file.close() ;

    }Write C++ statements for statements 1, 2, J and 4, which would perform thefollowing corresponding tasks: Assumenecessaryheader file s) included)

    Statement 1 to open binary file Sample.dat for read and writeStatement 2 : to iread a record from the file into SStatement 3 : to1place the put pointer at the beginning of Cth recordStatement 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 andprints the first character of each of its words in a different line. Example, if the filecontainsA Text FileThen the output should appear asAT

    F ]11. Write definition for a function FindPriceO, which reads a binary file Book.datcontaining records of class Book as given below). The function should display theTotal Accumulated Cost of all those Booksfor which Number of Pagesis above 999.

    ]class Book{ char Bname[20] ;

    int NoP;float Cost;

    public:void BEnter( );void BShow( );int RNoP (){

    //Name of Book//Number of Pages//Cost of Book

    //function to input data members//function to display data members

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

  • 8/13/2019 Computrr Class 12 Paper

    7/8

    return NoP;}float RCost{

    return Cost;}

    } ;2. Write definition for a function void Reverse int A[], int N , which reverses thecontents of the array A containing N number of integers. For example, if the arraypassedas parameter contains the values [4]

    Then the function should rearrange it to becomeLIOJ49~Note: The array contents Original or Reversed are not to be displayed

    3. Write definition for a function Alter int [3][3] which accepts an integer array ofsize 3 x 3 as its argument. The function should rearrange the array such that themiddle row elements get swapped with the middle column elements. Display therearranged array in a matrix format. [4]Example: The array1238 5 ;y 8 9

    Shouldbe rearranged and printed as1 4 32587 6-TCf-

    . Eachelement of an array A[-3...6, -5...4] requires2 bytesof storage. If the array is storedalongthe row and the addressof A[3,2] is 5500,then calculate the addressof the locationA[4,-2]. [3]

    . An array S[20] [15] is stored in the memory in column major form, with eachelement occupying 4 bytes of memory. If the address of 5 10][5] is 2000, thencalculate the addressof the location 5[15] [10]. [3]

    . Evaluate the following postfix expression using a stack and show the contents of thestack after each operation: [2]3,20, 4, ,5, -, 10, +This paper contains 8 printed sides

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

  • 8/13/2019 Computrr Class 12 Paper

    8/8

    17 Convert the following infix expression to its equivalent postfix expression:A + B / C - D - E * F [2]~8.

    a) Define a function to remove a student from an array-implemented queue ofstudents,. which can contain a maximum of 9 students. The function shouldperform an underflow check and on availability of a student display hisdetails alongwith a message removed . [4]

    struct Student{

    int Admno;char Sname [20];

    } ;b) Define a function to Pushan integer into a static Stack which can contain amaximum 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]