Download Question Paper (Link Below)
Question Paper Solution
1. A. Write down a C++ program that demonstrates how to use conditional operators to make decisions and perform conditional assignments according to the question. In the program, three integer variables are defined: num1. num2 and num3. The conditional operator is used to find and store the maximum value between num1, num2 and num3. Next, use the conditional operator to determine whether num3 is even or odd.
The question is based on - Conditional Operator in C++
Output
B. Create C++ program to find the sum of all even numbers between 1 and a user- defined positive integer. The program should also ensure that the user enters a positive number.
Output
2. A. Write a C++ program to create an array where each element, starting from the third element onward, is the sum of the two preceding elements.
Ouput
B. Using C++, develop a program that demonstrates how structures are used to represent and store student information. Create a structure named "Student" and define its members as follows:
a) rollNumber (an integer}: to store the student's roll number.
b) name (a string): to store the student's name.
c) marks (an array of floating-point numbers): to store the student's marks in three subjects and calculate the average marks.
Output
3. A. Define a "Book" class with the following private members:
a) title (a string): to store the title of the book.
b) author (a string): to store the author's name.
c) publicationYear (an integer): to store the year the book was published.
d) isbn (a string): to store the International Standard Book Number (ISBN) of the book.
In the "Book" class, create a constructor that takes parameters for initializing its title, author, publication year, and ISBN. The private members in the constructor are set based on the parameters provided. Using the constructor, create a book object and initialize it. Display the details of the book object, including its title, author, publication year, and ISBN.
Output
B. Create a C++ program with a hierarchy of vehicle classes. Start with the "Vehicle" base class, including private members for "make" (string) and "year" (integer), a constructor for initialization, and a displaylnfo() method. Then, derive the "Car" class from the "Vehicle class" with an additional "model" (string) member and a drive() method. Also, derive the "Bicycle" class from the "Vehicle class" with a "type" (string) member and a pedal() method. In the main program, create instances of both "Car" and "Bicycle" classes, display their information, and demonstrate the drive() and pedal() methods.
Output
4. A. Write a C++ program demonstrating polymorphism with geometric shapes, creating a base class "Shape" with a pure virtual method calculateArea(). The "Circle" class calculates its area based on its radius, while the "Rectangle" class calculates its area based on its length and width. Create instances of the "Circle" and "Rectangle" in the main program and utilize an array of "Shape" pointers to demonstrate polymorphism. Calculate and display areas by iterating through an array of "Shape" pointers.
Output
B. Develop a C++ program in which you demonstrate how files can be handled for student record management. Create a structure entitled "Student" with members for student IDs (an integer), names (strings), and GPAs (floats). Create a text file named "student_records.txt" in write mode and allow the user to input student records, including ID, name, and GPA, until they decide to stop. Each student record should be written to the file in a structured format and closed afterwards. Reopen the "student_records.txt" file in read mode and display the student records on the screen, one record per line.
This question is based on - File Handling in C++
Output
5. A. What is a function? Differentiate between call by value and call by reference.
B. 5 + 3 * 2 - 4/2. Calculate the result based upon the operator precedence.
Solution: Operator precedence:
5 + 3 * 2 - 4 / 2
= 5 + 6 - 2
= 9
C. Differentiate between class and structure.
D. Program to find the smallest element in any given array.
Output
E. Define constructor and elaborate the types of constructors.
F. What is inheritance? With diagrams, explain inheritance types.
G. Differentiate between compile-time and run-time polymorphism.
H. Need for exception handling in C++ programming.
Exception handling ensures the program handles errors gracefully, preventing crashes and allowing recovery from runtime errors.
I. Significance of error handling in file operations in C++.
Error handling in file operations prevents data loss, handles file opening failures, and ensures data integrity.
J. Example of cascading for code readability and efficiency.