(Paper) Sample Paper Class - XII Computer Science 2008-3

Disclaimer: This website is NOT associated with CBSE, for official website of CBSE visit - www.cbse.gov.in

  • #include<iostream.h>

int max(int &x,int &y,int &z)

{

            if(x>y &&y>z)

            {

                        y++;

                        z++;

                        return x;

            }

            else

                        if(y>x) 

                                    return y;

                        else

                                    return z;

}

void main()

{

            int a=10,b=13,c=8;

            a=max(a,b,c);

            cout<<a<<b<<c<<endl;

            b=max(a,b,c);

            cout<<++a<<++b<<++c<<endl;

}

 

  • void main()

{

            int a=32,*X=&a;

            char ch=65,&cho=ch;

            cho+=a;

            *X+=ch;

            cout<<a<<’,’<<ch<<endl;

}

 

  • #include<iostream.h>

struct point

{

            int x,y;

};

void show(point p)

{

            cout<<p.x<<’;’<<p.y<<endl;

}

void main()

{

            point U={0,10},V,W;

            V=U;

            V.x+=0;

            W=V;

            U.y+=10;

            U.x+=5;

            W.x-=5;

            show(U);

            show(V);

            show(W);

}

 

  • void main()

{

            int x[]={10,20,30,40,50};

            int *p,**q;

            int *t;

            p=x;

            t=x+1;

            q=&t;

            cout<<*p<<”,”<<**q<<”,”<<*t++;

}

 

  • class state

{

            char *statename;

int size;

public:

state()

{

            size=0;

            statename=new char[size+1];

}

void display() { cout<<statename<<endl; }

state(char *s)

{

size=strlen(s);

statename=new char[size+1];

strcpy(statename,s);

}

                        void replace(state &a, state &b)

                        {            size=a.size+b.size;

                                    delete statename;

                                    statename=new char[size+1];

                                    strcpy(statename,a.statename);

                                    strcat(statename,b.statename);

                        }

            };

void main()

{

                        char *temp=”Delhi”;

                        state state1(temp),state2(“mumbai”),state3(“Nagpur”),S1,S2;

                        S1.replace(state1,state2);

                        S2.replace(S1,state3);

                        S1.display();

                        S2.display();

            }

  • void main()

{

            long NUM=1234543;

            int f=0,s=0;

            do{

                        int rem=NUM%10;

                        if(rem%2==0)

                                    f+=rem;

                                    else

                                                s+=rem;

                                    NUM/=10;

                        }while(NUM>0);

                        cout<<f-s;

            }

Classes & constructor

  1. Answer the questions(i) and (ii) after going through the following class :

class Exam

{

            int year;

            public :

                        Exam(int y) { year=y; }

                        Exam(Exam &t);

}

(i)     Create an object, such that it invokes constructor 1.

(ii)    Write complete definition for constructor 2.

  1. Define a class named Housing in C++ with the following descriptions :

private members

            reg_no                     integers (Ranges 10-1000)

            name                        char array

            type                          character

            cost                           float

public members

·  function Read_data() to read an object of housing type.

·  function display() to display the details of an object.

·  function draw_nos() to choose and display the details of 2 houses selected randomly from an array of 10 objects of type Housing. Use random function to generate the registration no with reg_no from the array.

  1. Define a class named Cricket in C++ with the following descriptions :

private members

            Target_scope            int

            Overs_bowled          int

            Extra_time                int

            Penalty                     int

            cal_panalty() a member function to calculate penalty as follows :

                        if Extra_time <=10 , penalty =1

                        if Extra_time >10 but <=20, penalty =2

                        otherwise, penalty =5

public members

            a function extradata() to allow user to enter values for target_score,overs_bowled,extra_time.

            a function dispdata() to follow user to view the contents of all data members.

  1. Define a class named Directory in C++ with the following descriptions :

private members

            docunames                        string (documents name in directory)

            freespace                        long (total number of bytes available in directory )

            occupied                        long (total number of bytes available in directory)

  public members

            newdocuentry()            a function to accept values of docunames,freespace & occupied from user

            retfreespace()                        a function that return the value of total kilobytes available. (1 KB=1024 b)

            showfiles()                        a function that displays the names of all the documents in directory.

  1. Define a class named Publisher in C++ with the following descriptions :

private members

            Id                                long

            title                              40 char

            author                          40 char

            price , stockqty            double

            stockvalue                   double

            valcal()                        A function to find price*stockqty with double as return type Public members

·  a constructor function to initialize price , stockqty and stockvalue as 0

·  Enter() function to input the idnumber , title and author

·  Takestock() function to increment stockqty by N(where N is passed as argument to this function) and call the function valcal() to update the stockvalue().

·  sale() function to decrease the stockqty by N (where N is sale quantity passed to this function as argument) and also call the function valcal() to update the stockvalue

·  outdata() function to display all the data members on the screen.

  1. Define a class named Serial in C++ with the following descriptions :

private members

            serialcode                 int

            title                           20 char

            duration                    float           

            noofepisodes            integer

Public members

·  a constructor function to initialize duration as 30 and noofepisodes as 10.

·  Newserial() function to accept values for serialcode and title.

·  otherentries() function to assign the values of duration and noofepisodes with the help of corresponding values passed as parameters to this function.

·  dispdata() function to display all the data members on the screen.

  1. Considering the following specifications :

Structure name               data                 type                 size

Namefirst                       char array            40

                                      mid                   char array            40       

                                      last                   char array            60       

Phone                             area                  char array            4

                                       exch                 char array            4

                                       numb                char array            6

 

 

Class name                 Data              Type

P_rec                           name               Name

                                                phone              Phone

 

            Member functions:

·  Define constructor (outside the class P_rec) that accepts the values of data members from the user.

·  Define the display_rec (outside the class P_rec) that shows the current values .

 

Declare structures in C++ for Name and Phone . Declare the class P_rec.

 

  1. Define a class Competition in C++ with the following descriptions:                                                                   

Data Members     

 Event_no               integer

                Description            char(30)

                Score                    integer

                Qualified                char

 

 

 Member functions

                A constructor to assign initial values Event_No number  as 101,Description as “State level” Score is 50 , qualified ‘N’.

 Input()                        To take the input for event_no,description and score.

            Award(int)                   To award qualified as ‘Y’, if score is more than the cutoffscore  passed as argument to the function  else ‘N’.             

                Show()                       To display all the details.

 

9. Declare a class bank to represent bank account of 10 customers with the following data members: name of depositor, account   number, type of account(s for savings and c for current account), balance amount. The class also contains the following   member functions:

(a)  To initialize data members.

(b)   To deposit money

(c)   To withdraw  money after checking minimum balance (say 1000)

(d)   To display the data members on screen.

 

< Pervious

 Next >


  Go To Page :   1,   2,   3,   456   >>