Reg. No.
MANIPAL INSTITUTE OF TECHNOLOGY
Manipal University
Sixth SEMESTER B.Tech. (E & C) DEGREE END SEMESTER EXAMINATION
- April/May 2017
SUBJECT: OOP Using C++ (ECE - 4030)
TIME: 3 HOURS MAX. MARKS: 50
Instructions to candidates
Answer ALL questions.
Missing data may be suitably assumed.
1A. What are in-line functions? Illustrate with an example. What are their advantages and
disadvantages?
1B. What is a reference variable? With a simple example, explain the usage of reference parameter.
When should we pass arguments by reference?
1C. What are constructors and destructors? How are they useful in programming?
(5+3+2)
2A. What are classes and objects in C++? Explain with an example. Explain the access specifiers that
can be used in classes?
2B. Create a class called Time that has separate int member data for hours, minutes, and seconds. The
constructor should initialize all these data to 0, or should initialize it to values given by user.
Another member function should display it, in 11:59:59 (am/pm) format.
Input Validation: Accept values only between 0 and 23 for the hour, between 0 and
59 for the minute and seconds.
2C. Define and explain multiple inheritance with a relevant diagram.
(5+3+2)
3A. Explain with an example for each, the concept of shallow copy and deep copy.
3B. Write the definitions for the below mentioned member functions of the class Time. Write a main
function which exercise all the member functions. Set the time to noon for the no-parameter
constructor.
class Time
{
private:
int *hour,*minute,*second;
public:
Time ();
Time (int h,int m,int s);
void printTime ();
void setTime (int h,int m,int s);
~Time();
};
3C. Explain dangling pointer with a simple example.
ECE – 4030 Page 1 of 2
(5+3+2)
4A. Define a Time class which has hours, minutes and seconds. Write overloaded constructor which
takes parameters from user, with default being set to noon value. Define a friend function t3=
add_time (t1, t2) which uses the overloaded + operator to add two times. Write a program to
exercise all the member functions of the class.
4B. Write appropriate destructor/s for the below mentioned class definition. Write the order of their call
in the below mentioned class definition.
class X
{ public:
X( ) { p = new int[10]; cout << "X’s ctor “ << endl;}
private: int *p;
};
class Y : public X
{ public:
Y( )
{ q = new int[100];
cout << "Y() : Y::q = " << q << ". "; }
private: int *q;
};
4C. Write a program that uses a class (define the class and make all the data members as private) named
MovieData to store the following information about a movie:
Title
Director
Year Released
Running time (in minutes)
Include a constructor that allows all four of these member data values to be specified at the
time a MovieData variable is created. The main function should create two MovieData variables
and pass (by reference) each one in turn to a function that displays the information about the movie.
(5+3+2)
5A. Explain the Exception handling mechanism in C++ with proper syntax. Write an interactive
program to compute square of a positive number. The input value must be tested for validity. If it is
negative the program should raise an exception. Write an appropriate catch block to print an error
message and close the program.
5B. Write a program to open an existing file in text mode and copy it to another new file (create a
replica). Both the file names should be taken from the user at run time.
ECE – 4030 Page 2 of 2
5C. With an example, explain the two methods of accessing class’s members.
(5+3+2)
ECE – 4030 Page 3 of 2