Object-Oriented Programming using C++ - B.Tech 3rd Semester Special Exam., 2020

2020Semester 2Civil-CAEnd Semester
Aryabhatta Knowledge University, Patna
B.Tech 3rd Semester Special Exam., 2020

Object-Oriented Programming using C++

Time: 03 HoursCode: 100313Full Marks: 70

Instructions:

  1. The marks are indicated in the right-hand margin.
  2. There are NINE questions in this paper.
  3. Attempt FIVE questions in all.
  4. Question No. 1 is compulsory.
Q.1 Answer any seven of the following questions:[14]
  1. How void pointers differ from general pointers?

  2. Is it possible to access data without any member function in the class? Justify your reason.

  3. How precedence of operators effects evaluation of an expression?

  4. Write the advantage of object-oriented programming over procedural programming.

  5. Why we generally avoid goto in the programming?

  6. What is the role of try block in the exception handling?

  7. Write the difference between class and structure.

  8. What is the use of scope resolution operator?

  9. Why we require derive data types in the programming when we already have different data types?

  10. Write a small code which illustrates the concept of multilevel inheritance.

Q.2 Solve both questions :[14]
  1. On a certain day the British pound was equivalent to $1.487 US, the French franc was $0.172, the German deutschemark was $0.584, and the Japanese yen was $0.00955. Write a program in C++ that allows the user to enter an amount in dollars, and then displays this value converted to these four other monetary units.

  2. What are command line arguments? Write a program in C++ to finding factorial for a given number using command line argument.

Q.3 Solve both questions :[14]
  1. What is a principal reason for passing arguments by reference? Write a function called zeroSmaller() that is passed two int arguments by reference and then sets the smaller of the two numbers to 0. Write a main() program to exercise this function.

  2. Write a C++ program to which replace all the words "dog" with "cat".

Q.4 Solve both questions :[14]
  1. Compare and contrast dynamic memory allocation using the C++ operators new and delete, with dynamic memory allocation using the C standard library functions malloc and free.

  2. Write programs to evaluate the following function to 0.0001% accuracy:
    \( SUM = 1 + \left(\frac{1}{2}\right)^{2} + \left(\frac{1}{3}\right)^{3} + \left(\frac{1}{4}\right)^{4} + \dots \)

Q.5 Solve both questions :[14]
  1. Create a class Rectangle. The class has attributes length and width, each of which defaults to 1. It has member functions that calculate the perimeter and the area of the rectangle. It has set and get functions for both length and width. The set functions should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0.

  2. Assume that there is a class Derv that is derived from a base class Base. Write the decelerator for a derived-class constructor that takes one argument and passes this argument along to the constructor in the base class.

Q.6 Solve both questions :[14]
  1. What is operator overloading? Write a program in C++ to overload unary minus operator.

  2. A friend function cannot be used to overload the assignment operator =. Explain why.

Q.7 Solve both questions :[14]
  1. Discuss why converting a base-class pointer to a derived-class pointer is considered dangerous by the compiler.

  2. What is a virtual function? Why we need virtual functions?

Q.8 Solve both questions :[14]
  1. What are the different forms of inheritance? Give an example for each.

  2. Write a program that uses a function template called min to determine the smaller of two arguments. Test the program using integer, character and floating-point number pairs.

Q.9 Solve both questions :[14]
  1. What is the relationship between function templates and overloading? Explain with the help of an example

  2. What are the advantages of using exception handling mechanism in a program? Explain with an example.