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

2020Semester 3Civil-CAEnd Semester
Aryabhatta Knowledge University, Patna
B.Tech 3rd Semester 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 parts:[14]
  1. Write the name of the function in C++ used for opening a file for input only.

  2. What is the purpose of using a derived class?

  3. Is there any difference between public protection and private protection?

  4. How does abstract class differ from interface?

  5. What is the role of catch block in the exception handling?

  6. Is it possible to return more than one value from a function? Explain with a small example.

  7. What are the mutator functions? Give an example.

  8. Discuss the role of default constructor when an object of a class is created.

  9. Write a small code which illustrates the concept of multiple inheritance.

  10. Differentiate between compile-time polymorphism and run-time polymorphism.

Q.2 Solve both questions :[14]
  1. Write a language program in C++ which accepts the user's first and last name and print them in reverse order with a space between them.

  2. Create the equivalent of a four-function calculator. The program should ask the user to enter a number, an operator and another number. (Use floating point.) It should then carry out the specified arithmetical operation: adding, subtracting, multiplying or dividing the two numbers. Use a switch statement to select the operation. Finally, display the result. When it finishes the calculation, the program should ask whether the user wants to do another calculation. The response can be 'y' or 'n'.

Q.3 Solve both questions :[14]
  1. Use a single-subscripted array to solve the following problem: Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, print it only if it is not a duplicate of a number already read. Provide for the 'worst case' in which all 20 numbers are different. Use the smallest possible array to solve this problem.

  2. Write a program in C++ to read text file and display count of character in file.

Q.4 Solve both questions :[14]
  1. What is the main advantage of passing arguments by reference? When do we need to use default arguments in a function?

  2. What do you mean by dynamic binding? How is it useful in OOP?

Q.5 Solve both questions :[14]
  1. What is constructor? Write a program in C++ to find the area of the circle using constructor.

  2. Define a class to represent a bank account. Include the following members:
    Data members: 1. Name of the depositor 2. Account number 3. Type of account 4. Balance amount in the account
    Member functions: 1. To assign initial values 2. To deposit an amount 3. To withdraw an amount after checking the balance 4. To display name and balance.
    Write a main program which handles 10 customers.

Q.6 Solve both questions :[14]
  1. What do you mean by dynamic initialization of objects? Why do we need to do this? How is dynamic initialization of objects achieved?

  2. Write a C++ program to define a class string and use overloaded == operator to compare two strings.

Q.7 Solve both questions :[14]
  1. Some programmers prefer not to use protected access because it breaks the encapsulation of the base class. Discuss the relative merits of using protected access vs. insisting on using private access in base classes.

  2. Write a C++ program to demonstrate example of hierarchical inheritance to get square and cube of a number.

Q.8 Solve both questions :[14]
  1. We knew that a private member of a base class is not inheritable. Is it anyway possible for the objects of a derived class to access the private members of the base class? If yes, how?

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

Q.9 Solve both questions :[14]
  1. Describe the relationship between class templates and inheritance. Why is it appropriate to call a class template a parameterized type?

  2. Write a program that demonstrates how certain exception types are not allowed to be thrown.