Task A

Define a class Car to represent an automobile in a driving simulation program. You are required to include the following components:

  • an integer ID number,
  • the odometer reading,
  • the name of the manufacturer
  • the purchase dates (define another class called Date),
  • the fuel economy rating in kilometres per litre,
  • and the petrol tank (define a class Tank)

The class tank includes the following components:

  • the tank's capacity and
  • the current fuel level, giving both in litres,

Include default constructors and constructors for all classes.

Overload << and >> for all three new classes, ensuring that the definitions of << and >> for Car use the definitions of << and >> for Date and Tank.

Define a member function called fillUp for class Tank

Define a member function called drive for class Car.

Function fillUp should copy the tank capacity value into the current fuel level component and return a type double value indicating the number of litres re- quired to fill the tank.

Function drive should take the number of kilometres driven as an input argument and should adjust the odometer reading and the tank's current fuel level component.

Write a driver function that fills several Car-class variables in ways designed to test the three classes' various constructor functions and the overloaded >> and << operators. Also include calls to fillUp and drive.

Store class interface and implementation in separate files.

Task B

A rational number is a number that can be represented as the quotient of two integers. For example, 1/2, 3/4, 5/3 etc. (“/” indicates the normal notation for a fraction not the integer division used in a C++ program.)

Write a rational number class with the following properties:

  • Represent rational numbers as two values of type int, one for the numerator and one for the denominator. Call the class Rational. You may give it a different suitable name if you wish.
  • Include a constructor with two int type arguments that can be used to set the member variables of an object to any legal values. Since every int is also a rational number, as in 2/1 or 17/1, you should also provide a constructor with a single int parameter. Also include a default constructor that initializes an object to 0.
  • Overload the input and output operators » and «. Numbers are to be input and output in the form 1/3, 17/31, 100/403 etc. Note that the numerator, the denominator, or both may contain a minus sign, so -1/3, 17/ -31, and -100/-403 are also possible inputs.
  • Overload all of the following operators so that they correctly apply to the type Rationa1: ==, <, <=, >, >=, +, -, * , and / .

The following formulas will be useful in defining the class functions: See image.

Store the Rational class interface and implementation in separate files.

Write a test program to test your class.

Your are required to provide:

  • A report detailing the requirements, design, implementation and a fully implemented test plan.
  • Code files with comments in both hard and soft copies.
  • Sample output of your test program in hard copy.
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.