University of Sharjah
Department of Computer Science
                                               1501211: Programming II
                                                   Fall 2023 – 2024
                                                        Lab #7
  Name:                                                                     ID:
Objectives
     Further practice with structs, classes, and inheritance.
                                    Lab Exc.                         Mark   Out of
               Program Code (correctness, style, modularity, etc.)                5
               Comments, indentation                                              1
               Naming of identifiers                                              1
               Output correctness                                                 2
               Output format                                                      1
                                    TOTAL:
A chauffeur has a name name and works a number of hours numberOfHours at a rate rate making a
wage
                                                    1/3
                                   wage = rate x numberOfHours
Example: If the chauffeur worked 12 hours at a rate 50 dirhams per hour, then his wage is 12 x 50 =
600 dirhams.
A car cost 1.8 dirhams for each liter of oil.
Example: If the car consumed 25 liter of oil, then the car cost 25 x 1.8 = 45 dirhams.
The car owner decides to use his car as a taxi. So the car cost the chauffeur wage and oil money but
generates the passenger fare (15 dirhams plus 5 dirhams for each kilometer).
Example: If the car travels 170 kilometers then the passenger fare is 15 + 5 x 170 = 865 dirhams.
       The chauffeur wage is 600 dirhams and the oil cost is 45 dirhams, then the taxi profit is 865 –
       600 – 45 = 220 dirhams.
       If the taxi pays 8% tax then the net profit is 202.4 dirhams.
Define a struct called Chauffeur with components name of type string, numberOfHours of type integer,
rate and wage of type float.
Define a class called Car with private data members oil, and cost of type float. The class has the
private member function calculateCost( ), the public member functions set( ), getCost( ), print( ), and
a constructor with parameter.
Define a class called Taxi which publicly inherits the class Car and has the private data members
Carter of type Chauffeur, tax, distance, and Profit of type float. The class has the private member
function calculateCost( ), the public member functions set( ), print( ), and a constructor with
parameters.
Hint: One liter of oil cost 1.8 dirhams and the fare of 1 kilometer is 5 dirhams.
Implement all member functions enforcing the least privileged property. Group the classes and
functions to use information hiding. Use the following driver:
int main()
{
  Chauffeur sample;
    sample.name = "Ali Omar";
    sample.numberOfHours = 12;
    sample.rate = 50;
    sample.wage = sample.numberOfHours * sample.rate;
    Taxi niceCar(sample, 25, 170, 8);
    niceCar.print();
    return 0;
}
Sample input / output:
                                                   2/3
3/3