QUESTION 3 Given the following inheritance hierarchy and the list of data members and methods for Hospital, Inpatient and Outpatient classes: Abstract Superclass: Hospital Attributes: String name // patient's name String gender // patient's gender (male or female) int age // patient's age in year Methods: constructor, mutator, accessor, printer, abstract method abstract double calcharges() // calculate the charges

Subclass: Inpatient Attributes: int wardType; // ward type int day; $/ /$ number of days stay double treatmentFee; // treatment charges Methods: constructor, mutator, accessor, printer Subclass: Outpatient Attributes: double consultationFee // consultation fee double medicineFee // medicine fee String consultationDate // (dd/mm/yyyy) $/ /$ e.g 15/10/2018 Methods: constructor, mutator, accessor, printer

a) Write the normal constructors for Inpatient and Outpatient classes. (4 marks) b) Write a method calccharges () for both subclasses to calculate the charges to be paid by the patients of the hospital. For senior citizens, they are entitled to get $50 \%$ discount for the charges. The patients are considered as senior citizens when their ages are greater than 60 years old. The daily ward charges for inpatients are shown in the following table: \begin{tabular}{|c|c|} \hline Ward Type & Charges (RM) /day \\ \hline 1 (1-bed) & 350 \\ \hline 2 (2-bed) & 250 \\ \hline 4 (4-bed) & 100 \\ \hline \end{tabular} The charge for inpatients is calculated based on the given formula: \[ \text { charges }=\text { ward charges }+ \text { treatment fee } \] For outpatients, they only have to pay for consultation and medicine fees. (5 marks) c) Write program fragments that use the concept of polymorphism to perform the following: i. Declare an array of objects to store 100 patients. (1 mark) ii. Display the details of female inpatients that have been admitted to the hospital. (2 marks) iii. Count and display the inpatient's details who have been admitted in the hospital for more than ten days. (4 marks) iv. Calculate and display the total charges of all outpatients in the month of October 2018. (4 marks)

Public Answer

CYQTR5 The First Answerer