$30
CSE109
1
Systems Software
Lab 3: Object Oriented Programming in C++
Lab Objectives
In this activity, students should demonstrate the following abilities:
1. Create and instantiate classes in C++
2. Overload operators for class types
3. Create a library for class types
Lab Assignment
In this lab, you will create a new type to manipulate fractions in C++. Follow the directions
below.
1. Create a class Fraction that has two data members of type int, one for the
numerator and the other for the denominator. Define two constructors for the class, a
default constructor and one with two parameters. The default constructor should
initialize the numerator to 0 and the denominator to 1. Add appropriate getters and
setters to the class.
2. Define an additional member function reduce to simplify a fraction.
3. Overload the following operators for the class Fraction: +, -, *, /, ==, !=, <, <=, >,
>=, >>, and <<. All the operator overloading functions should be member functions of
the class except for the operators >> and << which should be defined outside the class.
4. Define the class interface in the file fraction.h and the class implementation in the
file fraction.cpp. Create a static library libfraction.a that contains the object
file of the class implementation (fraction.o)
5. Write a C++ program to manipulate fractions. The program uses the library fraction
to allow users to perform operations on fractions. A sample run of the program is
provided at end of this document for testing.
6. Include all your files in a main folder named lab4. Submit the folder lab4 zipped on
courseSite.
CSE109 Lehigh University Summer 2020
2
>>./fraction_calculator
Enter a fraction operation of the form: f1 operation f2
f1, f2 in the form 2/3 for example
operation: (+, -, *, /, ==, !=, <, <=, >, >=)
1/3 + 2/3
= 1
Do you want to perform another operation? (y/n):y
Enter a fraction operation of the form: f1 operation f2
f1, f2 in the form 2/3 for example
operation: (+, -, *, /, ==, !=, <, <=, >, >=)
3/4 - 1/2
= 1/4
Do you want to perform another operation? (y/n):y
Enter a fraction operation of the form: f1 operation f2
f1, f2 in the form 2/3 for example
operation: (+, -, *, /, ==, !=, <, <=, >, >=)
1/2 * 1/2
= 1/4
Do you want to perform another operation? (y/n):y
Enter a fraction operation of the form: f1 operation f2
f1, f2 in the form 2/3 for example
operation: (+, -, *, /, ==, !=, <, <=, >, >=)
1/2 / 1/2
= 1
Do you want to perform another operation? (y/n):y
Enter a fraction operation of the form: f1 operation f2
f1, f2 in the form 2/3 for example
operation: (+, -, *, /, ==, !=, <, <=, >, >=)
1/3 == 2/3
= false
Do you want to perform another operation? (y/n):y
Enter a fraction operation of the form: f1 operation f2
f1, f2 in the form 2/3 for example
operation: (+, -, *, /, ==, !=, <, <=, >, >=)
2/3 < 3/4
= true
Do you want to perform another operation? (y/n):y
Enter a fraction operation of the form: f1 operation f2
f1, f2 in the form 2/3 for example
operation: (+, -, *, /, ==, !=, <, <=, >, >=)
3/18 == 1/6
= true
Do you want to perform another operation? (y/n):n