Object Oriented Programming 2074

Tribhuwan University
Institute of Science and Technology
2074
Bachelor Level / Second Semester / Science
Computer Science and Information Technology ( CSC161 )
( Object Oriented Programming )
Full Marks: 60
Pass Marks: 24
Time: 3 hours
Candidates are required to give their answers in their own words as far as practicable.
The figures in the margin indicate full marks.

Section A

Attempt any two questions:(2 x 10 = 20)

1. Write down the features of  object oriented programming language and explain.

10 marks view

2. Differentiate between single inheritance and multiple inheritance? Imagine a college hires some lectures. Some lectures are paid in period basic, while others are paid in month basic. Create a class called lecture that stores ID and name of lectures. From this class derive two classes: part time, which adds payperhr(type float): and full time, which adds paypermonth(type float). Each of these three classes should have a readdata() function to get its data from user at the key board and printdata() function to display the data.

Write a main() program to test the Full time and Part time classes by creating instance of them asking the user to fill their data with readdata () and display the data with printdata().

10 marks view

Program:

#include <iostream>

using namespace std;

class Lecture

{

    public:

    int id;

    string name;

    void readdata()

    {

        cout<<"Enter the Id of lecture:";

        cin>>id;

        cout<<"Enter the name of leture:";

        cin>>name;

    }

    void printdata()

    {

        cout<<"Id of lecture : "<<id<<endl;

        cout<<"Name of lecture: "<<name<<endl;

    }

    

};

class PartTime:public Lecture

{

    public:

    float payperhr;

    void readdatapt()

    {

        cout<<"Enter the salary paid per hour: ";

        cin>>payperhr;

        

    }

    void printdatapt()

    {

        cout<<"Salary paid per hour:"<<payperhr<<endl;

    }

};

class FullTime:public Lecture

{

    public:

    float paypermonth;

    void readdataft()

    {

        cout<<"Enter the salary paid per month: ";

        cin>>paypermonth;

        

    }

    void printdataft()

    {

        cout<<"Salary paid per month:"<<paypermonth<<endl;

    }

};


int main()

{

    PartTime p1;

    FullTime f1;

    

    cout<<"***Part Time***"<<endl;

    p1.readdata();

    p1.readdatapt();

    cout<<"***Displaying Data***"<<endl;

    p1.printdata();

    p1.printdatapt();

    

    cout<<"***Full Time***"<<endl;

    f1.readdata();

    f1.readdataft();

    cout<<"***Displaying Data***"<<endl;

    f1.printdata();

    f1.printdataft();

    

    return 0;

}

3. Why data conversion is needed? Write a program to convert kilogram into gram using user define to user define data conversion.(1 kg = 1000 gm).

10 marks view

Section B

Attempt any eight questions:(8 x 5 = 40)

4. What is constructor ? Write a program to demonstrate constructor overloading. 

5 marks view

5. What is function overloading ? Explain with example.

5 marks view
6.What is function? Write a program to find greatest number among any three numbers using function.
5 marks view

7. What is the role of protected access specifies in inheritance ? Explain with example.

5 marks view

8. Differentiate between virtual function and pure virtual function.

5 marks view

9. What is abstract base class? Give an example.

5 marks view

10. Explain the role of operator overloading with example.

5 marks view

11. What is friend function? Write a program to multiply any two private numbers of two different classes using friend function.

5 marks view

A friend function is a function that can access private members of a class even though it is not a member of that class.

Program:

#include <iostream>

using namespace std;

class XYZ;

class ABC

{

private:

    int value;

public:

ABC()

{

value = 6;

}

friend int multiply(ABC, XYZ); 

};


class XYZ

{

private:

    int value;

public:

XYZ()

{

value = 4;

}

friend int multiply(ABC, XYZ);   

};


int multiply( ABC v1, XYZ v2 )       

{

return (v1.value * v2.value);

}

int main()

{

ABC a;

XYZ x;

cout << "Product of two number is : " << multiply( a, x ) << endl;

return 0;

}

12. Define try, throw and catch statement in C++ with example.

5 marks view

13. Differentiate between class template and function template.

5 marks view