100% found this document useful (1 vote)
344 views7 pages

Employee Details: Page 1 of 7

This document contains an 8-question assignment on object-oriented programming in C++ from SDM College of Engineering & Technology. The questions cover topics such as features of OOP, defining classes with member functions and friend functions, inheritance, polymorphism, virtual functions, base and derived class pointers, and initializing base classes. Students are asked to write C++ programs to demonstrate concepts like defining classes, inheritance, overriding methods, and default constructors. They are also asked to determine outputs of code snippets and explain errors.

Uploaded by

appu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
344 views7 pages

Employee Details: Page 1 of 7

This document contains an 8-question assignment on object-oriented programming in C++ from SDM College of Engineering & Technology. The questions cover topics such as features of OOP, defining classes with member functions and friend functions, inheritance, polymorphism, virtual functions, base and derived class pointers, and initializing base classes. Students are asked to write C++ programs to demonstrate concepts like defining classes, inheritance, overriding methods, and default constructors. They are also asked to determine outputs of code snippets and explain errors.

Uploaded by

appu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

SDM College of Engineering & Technology – Dharwad

Department of Information Science & Engineering


Course : B.E. Semester : IV
Subject : Object Oriented Programming Sub. Code: 18UISC400
Course Instructor : Ms. Pratibha Badiger
UNIT – I

Q1. Explain any five salient features of object oriented programming.


Q2. Write a C++ program to define a class that has a m x n matrix as data member,
member functions (to read elements of the matrix and to display the matrix) and a
friend function to find the transpose of the matrix. The friend function must accept a
matrix object as argument and must return the transpose matrix. Write a main function
to test the member functions and the friend function.
Q3. Write a C++ program to define a class Employee, to read the employee details* of ‘n’
employees and then to display the details of ‘x’ employee based on the employee_id
entered.
*employee details
 Name of the employee
 Employee ID
 AADHAAR Number
 Gross Salary
Q4. Write a C++ program to define a class Time with hours, minutes and seconds as data
members, a member function to display the members of a Time object and a friend
non-member function that accepts two Time objects as arguments and returns their
sum. Write a main function in which two Time objects are created, the friend function
is invoked and display the result.
Note : The value of ‘minutes’ and the value of ‘seconds’ in the Time object returned by
the friend function must be less than 60.
Q5. With suitable example code, illustrate the following:
 const member functions
 inline functions
Q6. Write a C++ program to define a class Distance with feet and inches as data members,
a member function to display the members of a Distance object and a friend non-
member function that accepts two Distance objects as arguments and returns their
difference. Write a main function in which two Distance objects are created and the
friend function is invoked and display the result.
Note : The value of ‘inches’ in the Distance object returned by the friend function must
be less than 12.

Page 1 of 7
Q7. Determine the output of the following C++ code. If the compilation fails, explain the
error.
(i)
1 #include<iostream>
2 using namespace std;
3
4 namespace i1{
5 class A{
6 public:
7 void test( ){
8 cout<<"Fix the bug."<<endl;
9 }
10 };
11 }
12 namespace i2{
13 class A{
14 public:
15 void test( ){
16 cout<<"Solve the problem before you code."<<endl;
17 }
18 };
19 }
20 int main( ){
21 i2::A a2;
22 using namespace i1;
23 A a1;
24 a2.test( );
25 }
(ii)

Page 2 of 7
1 #include<iostream>
2 int sum (int x, int y = 42, int z = 50)
3{
4 return x + y + z;
5}
6
7 int sum (int a = 24, int b = 20)
8{
9 return a + b;
10 }
11
12 int main ( )
13 {
14 std::cout << sum (8) << endl;
15 std::cout << sum ( ) << endl;
16 return 0;
17 }
Q8. Explain how the reference variables are different from pointer variables with suitable
code.

Page 3 of 7
SDM College of Engineering & Technology – Dharwad
Department of Information Science & Engineering

Course : B.E. Semester : IV


Subject : Object Oriented Programming Sub. Code: 18UISC400
Course Instructor : Ms. Pratibha Badiger
UNIT – II

Q1. With an appropriate example code, explain the mechanism of handling an out-of-
memory condition during dynamic memory allocation.
Q2. Explain the dynamic memory allocation and deallocation in C++ with an appropriate
example code.
Q3. Illustrate the different types of constructors with an example program.
Q4. Explain the need for a destructor with a suitable example program.
Q5. Determine the output of the following C++ code. If the compilation fails, explain the
error and write the corrected code.
(i)
1 #include<iostream>
2 using namespace std;
3
4 class Train{
5 int number, distance;
6 public:
7 int Train(int n, int dist){
8 number = n;
9 distance = dist;
10 }
11 void print( );
12 };
13
14 void print( ){
15 cout<<“Train with no. ”<<number<<“ covers ”<<distance<<“ k.m.”<<endl;

Page 4 of 7
16 }
17
18 /*Do not modify anything in main( )*/
19 int main( ){
20 Train t1;
21 t1.print( );
22 Train t2(17416, 856);
23 t2.print( );
24 }
(ii)
1 #include<iostream>
2 using namespace std;
3
4 class Train{
5 int *num;
6 public:
7 Train(int n){
8 num = new int(n);
9 }
10 ~Train(){
11 cout<<“Destructor called for the Train#”<<*num<<endl;
12 delete num;
13 }
14 };
15
16 int main(){
17 Train t1(10);
18 Train t2(11);
19 {

Page 5 of 7
20 Train t3(12);
21 {
22 Train t4(13);
23 Train t5(14);
24 }
25 Train t6(15);
26 }
27 Train t7(16);
28 {
29 Train t8(17);
30 }
31 }
Q6. Write a note on set_new_handler function with an example program.
Q7. The compiler creates the formal argument of the default copy constructor as a reference
object. Explain the reason.
Q8. Explain the need for explicitly defining a copy constructor with an appropriate
program.

Page 6 of 7
SDM College of Engineering & Technology – Dharwad
Department of Information Science & Engineering
Course : B.E. Semester : IV
Subject : Object Oriented Programming Sub. Code: 18UISC400
Course Instructor : Ms. Pratibha Badiger
UNIT – III

Q1. Explain the different ways of resolving the ambiguities that arise in multiple
inheritance.
Q2. Write a C++ program to create a class Shape which is inherited by class Rectangle
(inherited by class Square) and class Triangle. The class Shape must have two private
data members (dim1 and dim2) and a function calcArea( ) that will be implemented by
derived classes. In the main create objects and test the methods. The program shouldn't
allow you to instantiate Shape class.
Q3. Explain the need for virtual destructors with an appropriate C++ program.
Q4. Create a base-class Worker and derived-classes HourlyWorker and SalariedWorker.
Every worker has a name and a salary rate. Write a method computerPay(int hours)
that computes the weekly pay for every worker. An hourly worker gets paid the hourly
wage for the actual number of hours worked, if hours is at most 40. If the hourly
worker worked more than 40 hours, the excess is paid at twice the salary rate. The
salaried worker gets paid the hourly wage for 40 hours, no matter what the actual
number of hours is. Write a main function to test these classes and methods.
Q5. Describe the working of virtual functions with a suitable code.
Q6. Explain the concept of base class and derived class pointers.
Q7. Write a C++ Program to create a class FixedDeposit with member data(Principal
amount, Period of investment, Interest rate and Return value of amount) and member
functions to compute Return Value for given amount, period and interest rate. Create 3
objects. The program must demonstrate the use of overloaded constructors. The
parameter values to these constructors must be provided at run time.
The user can provide input in one of the following forms:
 Amount, period and interest in decimal form
 Amount, period and interest in percent form
 Amount and period [by default interest rate is 7%]
Q8. With a suitable example explain how to initialize the base class in its derived class.
Date : 08-05-2021
Course Instructor : Ms. Pratibha Badiger

HOD – ISE : Dr. Jagadeesh D. Pujari

Page 7 of 7

You might also like