(Computer Science) CBSE Class XII Important Questions Computer Science (2008)

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

Computer Science : CBSE Class XII Important Questions Computer Science (2008)


Chapter 3 – Object Oriented Programming

Q. 12. What do you understand by function overloading? Give an example illustrating its use in a C++ program.

Ans: A function name having several definitions that are differentiable by the number or types of their arguments is known as function overloading. For example;
            float area(float a)
            {
                        return a * a;
            }
            float area(float a, float b)
            {
                        return a * b;
            }

 

Q. 13. Enlist some advantages of OOP.

  1. Reusability of code

  2. Ease of comprehension

  3. Ease of fabrication and maintenance

  4. Easy redesign and extension.


Chapter 4 – Classes and Objects

Q. 14. Describe the methods of accessing data members and member functions of a class in the following cases:

  1. Inside the main program

  2. Inside a member function of the same class

  3. Inside a member function of another class.           

Ans:

  1. The public members can be accessed using the syntax
    Objectname.public membername;

  2. All the members of the class are accessed as ordinary members. No class name or object name is required here.

  3. Here only the public members are accessed using the objects of the same type i.e. Objectname.membername.

 

Q. 15. Define a class student with the following specifications:

Private members:
            rollno                integer
            name                character array of size 20
            class_st            character array of size 8
            marks               integer array of size 5
            percentage        float
            calculate           that calculates overall percentage marks and returns the percentage.

Public Members:
            readmarks reads marks and invokes the calculate function
            displaymarks prints the data.

Ans:

class student
{
            int roll_no;
            char name[20];
            char class_st[8];
            int marks[5];
            float percentage;
            float calculate;
public:
            void readmarks( );
            void displaydata( );
};
float student::calculate( )
{
            float p = 0;
            int tot = 0;
            for(int i =0; i<5; i++)
                        tot += marks[i];
            p = tot/5.0;
            return p;
}
void student::readmarks( )
{
            cout<<”Enter roll number”;
            cin>>roll_no;
            cout<<”Enter name:”;
            gets(name);
            cout<<”Enter class:”;
            gets(class_st);
            cout<<”Enter marks in 5 subjects:”;
            for(int i =0;i<5;i++)
                        cin>>marks[i];
}
void student::displaydata( )
{
            cout<<”Roll number:”<<roll_no<<endl;
            cout<<”Name:”<<name<<endl;
            cout<<”Class:”<<class_st<<endl;
            cout<<”Marks in 5 subjects:”;
            for(int i=0;i<5;i++)
                        cout<<marks[i]<<” “;
            cout<<endl;
            percentage = calculate( );
            cout<<”Percentage=”<<percentage<<”%”;
}

 

Q. 16. What are the advantages and disadvantages of inline functions?

Ans: The main advantage of inline functions is that they save on the overheads of a function call as the function is not invoked, rather its code is replaced in the program.

The major disadvantage of inline functions is that with more function calls, more memory is wasted as for every function call, the same function code is inserted in the program. Repeated occurrences of same function code waste memory space.

 

Chapter 5 – Constructors and Destructors

Q .17. Given the following C++ code, answer the questions i and ii:

class readbook
{
                                    public:
                                    readbook( )                  //Function1
                                    {
                                                cout<<”Open the Book”<<endl;
                                    }
                                    void readchapter( )       //Function 2
                                    {
                                                cout<<”Reading chapter one”<<endl;
                                    }
                                    ~readbook( )                //Function 3
                                    {
                                                cout<<”Close the book”<<endl;
                                    }
                        };

  1. In OOP, what is Function 1 referred as and when does it get invoked/called?

  2. In OOP, what is Function 3 referred as and when does it get invoked/called?

Ans:

  1. Function 1 is referred to as constructor and it gets invoked when an object gets created.

  2. Function 3 is referred to as Destructor and it gets invoked when an object goes out of scope.i.e. when its scope is over.

 

Q. 18. Define the following:

  1. Default Constructor

  2. Copy Constructor

Ans:

  1. Default Constructor: A constructor that accepts no parameter is called default constructor.

  2. Copy Constructor: A constructor that is invoked when an object is defined and initialized with another object. It takes the following form:

classname(classname &);

 

Q. 19. Distinguish between the following two statements:

time T1(13, 10, 25);                             //statement 1
time T1 = time(13,10,25);                     //statement 2

Ans: The first statement creates the object T1 by calling the time constructor implicitly. On the other hand, the second statement creates the object T1 by calling the time constructor explicitly.

 

Q. 20. Predict the output for the following code:

#include<iostream.h>
class student_rec
{
            int m1,m2,m3;
            float percentage;
public:
            student_rec( )
            {
                        m1 = m2 = m3 = 0;
                        percentage = 0.0;
            }
            void calc_perc(int x, int y, int z)
            {
                        m1 = x; m2 = y; m3 = z;
                        percentage = (m1+ m2 + m3)/3.0;
                        display_rec( );
            }
            void display_rec( )
            {
                        cout<<endl<<”Percentage=”<<percentage<<”%”;
            }
};
void main( )
{
            student_rec s1;
            s1.display_perc( );
            s1.calc_perc( );
            s1.display_perc( );
}

Ans: Percentage = 0%, Percentage = 35%

 

 

Previous | Next