Вы находитесь на странице: 1из 3

OOP – ASSIGNMENT-1

Instructions:

• Solve the following tasks exactly in the given order.

• Make a separate project for each task.

• Indent your code properly.

• Use meaningful variable and function names. Follow the naming conventions.

• Use meaningful prompt lines and labels for all input/output.

• Make sure that there are NO dangling pointers or memory leaks in your program.

DEADLINE DATE: 22-04-2019

Task 1 (5+3+4+4+4+6+6+5+5+3): Implement a class Fraction, which has private data members,
numerator (int), denominator (int).

Task 1.1: Write a parameterized, default and copy constructors for the Fraction class with default values
of numerator=1 and denominator=1.

Task 1.2: Getters and setters for the both the data members.

Task 1.3: Overload the + operator so that on it adds the two Fraction objects.

F1 (5,2)

F2 (1,2)

F3 = F1 + F2 (F3.x=6, F3.y=2)

Task 1.4: Overload the - operator so that on it subtracts the two Fraction objects.

F1 (3,2)

F2 (1,2)

F3 = F1 - F2 (F3.x=2, F3.y=2)

Task 1.5: Overload the * operator so that on it subtracts the two Fraction objects.

F1 (3,2)

F2 (1,2)

F3 = F1 * F2 (F3.x=3, F3.y=4)

Task 1.6: Overload the / operator so that on it subtracts the two Fraction objects.

F1 (3,2)
F2 (1,2)

F3 = F1 / F2 (F3.x=3, F3.y=1)

Task 1.7: Overload the > operator so that compares two Point objects and returns true if both x and y of
one point object is greater than the other.

F1 (3,2)

F2 (1,2)

F1 > F2 (returns true)

Task 1.8: Overload the == operator that compares two Fraction objects and returns two if both are
equal.

F1(3,4)

F2(1,4)

F1 == F2 (returns false).

Task 1.9: Implement a function simplify() that simplifies the fraction.

F1(4,2)

F1.simplify() (F1.x=2, F1.y=1)

Task 1.10: void print( ) const Printing Fractional numbers in the form a/b, where a is the numerator and
b is the denominator.

Now write a driver program to test your Fractional class. Instantiate several Fractional objects. Test that
all your member functions work properly.

Task 2: (5+5+5):

For this assignment you will design a set of classes that work together to simulate a car’s fuel gauge and
odometer. The classes you will design are:

• The FuelGauge Class: This class will simulate a fuel gauge.

Its responsibilities are

– To know the car’s current amount of fuel, in gallons.

– To report the car’s current amount of fuel, in gallons.

– To be able to increment the amount of fuel by 1 gallon.

This simulates putting fuel in the car. (The car can hold a maximum of 15 gallons.)
– To be able to decrement the amount of fuel by 1 gallon, if the amount of fuel is greater than 0 gallons.
This simulates burning fuel as the car runs.

• The Odometer Class: This class will simulate the car’s odometer.

Its responsibilities are:

– To know the car’s current mileage.

– To report the car’s current mileage.

– To be able to increment the current mileage by 1 mile. The maximum mileage the odometer can store
is 999,999 miles. When this amount is exceeded, the odometer resets the current mileage to 0.

– To be able to work with a FuelGuage object. It should decrease the FuelGauge object’s current
amount of fuel by 1 gallon for every 24 miles traveled. (The car’s fuel economy is 24 miles per gallon.)
Demonstrate the classes by creating instances of each. Simulate filling the car up with fuel, and then run
a loop that increments the odometer until the car runs out of fuel. During each loop iteration, print the
car’s current mileage and amount of fuel.

Task 4 (Class) (40):

Create a class TicTacToe that will enable you to write a complete program to play the game of tic-tactoe.
The class contains as private data a 3-by-3 two-dimensional array of integers. The constructor should
initialize the empty board to all zeros. Allow two human players. Wherever the first player moves, place
a 1 in the specified square. Place a 2 wherever the second player moves. Each move must be to an
empty square. After each move, determine whether the game has been won or is a draw.
(Bonus) If you feel ambitious, modify your program so that the computer makes the moves for one of
the players. Also, allow the player to specify whether he or she wants to go first or second.

Вам также может понравиться