Object Oriented Programming 2074

Question Paper Details
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

Official Answer
AI Generated Answer

AI is thinking...

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

Official Answer
AI Generated Answer

AI is thinking...

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

10 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

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
Details
Official Answer

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;

}

AI Generated Answer

AI is thinking...

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
Details
Official Answer
AI Generated Answer

AI is thinking...

Section B

Official Answer
AI Generated Answer

AI is thinking...

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

Official Answer
AI Generated Answer

AI is thinking...

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

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

5. What is function overloading ? Explain with example.

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

6.What is function? Write a program to find greatest number among any three numbers using function.
5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

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

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

8. Differentiate between virtual function and pure virtual function.

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

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

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

10. Explain the role of operator overloading with example.

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

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

5 marks
Details
Official Answer

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;

}

AI Generated Answer

AI is thinking...

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

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

13. Differentiate between class template and function template.

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...