Shehzad Ali, Iqra Adnan Program Name: BSCS Time Allowed: 120 Minutes Maximum Marks: 40
Date: June 09, 2023 Course Mentor: Dr. M Atif
Signature: Student’s Name: Reg. No: Section: A, B, C, D & E
******Solve all Questions on answer book provided separately. This is an open book exam.**** Note: All the data in all the classes is supposed to be private.
Question 1: [10 Marks]
Imagine a publishing company that markets both book and audiocassette versions. Create a class called Publication that stores the title (type string) and price (type float) of a Publication. From this class derive two classes: Book, which adds a page_count (type int); and Tape, which adds a playing_time in minutes (type float). Each of the three classes should have a respective getter and setter functions. Write a main() function create two objects of the class Book and two objects of the class Tape. Display the title and price of the book having more pages. Similarly, display the title and price of the tape having more playing time. Question 2: [10 Marks] Define a class for a bank account that includes the following data members: • Name of account holder • Account Number • Balance amount in the account The class also contains the following member functions: ✓ A constructor to assign initial values. ✓ Overload + operator that adds the balance of one account to another account. ✓ Overload ‘<=’ operator to compare the balance of two accounts. Question 3: [10 Marks] Define the parent class "Furniture" with a pure virtual function called "calculatePrice." 1. Implement the "calculatePrice" function in the child class "Table" to calculate the price of a table. The price is calculated as: 𝑙𝑒𝑛𝑔𝑡ℎ × 𝑤𝑖𝑑𝑡ℎ × 100 2. Implement the "calculatePrice" function in the child class "BookShelf" to calculate the price of a book shelf. The price is calculated as: 𝑛𝑢𝑚𝑒𝑟 𝑜𝑓 𝑠ℎ𝑒𝑙𝑓𝑠 × 1500 3. Implement the "calculatePrice" function in the child class "Dice" to calculate the price of a dice. The price is calculated as: ℎ𝑒𝑖𝑔ℎ𝑡 × 3500 In main(), take input in each class object and calculate the price of each furniture object polymorphically. Question 4: [10 Marks] Write a program that reads a file named "Numbers.txt" containing whole number values, and displays the count of even and odd numbers present within the file.