Starting from:

$30

Assignment 4: Object Oriented Programming in C++

CSE109 
1
Systems Software
Assignment 4: 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 complex numbers in C++. Follow the
directions below.
1. Create a class Complex that has two data members of type double, one for the real
part and one for the imaginary part. Define two constructors for the class, a default
constructor and one with two parameters. The default constructor should initialize the
real part and the imaginary part to 0. Add appropriate getters and setters to the class.
2. Overload the following operators for the class Complex: +, - (subtraction), *, ==, !=,
>>, 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.
3. Define the class interface in the file complex.h and the class implementation in the
file complex.cpp. Create a static library libcomplex.a that contains the object
file of the class implementation (complex.o)
4. Write a C++ program to manipulate complex numbers. The program reads a text file
that contains a pair of complex numbers on each line. For each line, the program
performs the overloaded operations on the pair of complex number and stores the
results in an output file as shown in the sample run below. The program uses the
overloaded operators from the library complex to perform the operations on complex
numbers. The order of the operations, in the output file, is as follows: +, -, *, ==, !=.
5. Create a makefile to build your program in a main folder named assignment4.
Submit folder assignment4 zipped on courseSite.
CSE109 Lehigh University Summer 2020
2
>>./ccalc input_file output_file
Input file contents
1 1+i
i 1+i
1+i 1
1+i i
1+i 1+i
1-i 1+i
1+i 1-i
1-i 1-i
Output file contents
1 1+i 2+i -i 1+i false true
i 1+i 1+2i -1 -1+i false true
1+i 1 2+i i 1+i false true
1+i i 1+2i 1 -1+i false true
1+i 1+i 2+2i 0 2i true false
1-i 1+i 2 -2i 2 false true
1+i 1-i 2 2i 2 false true
1-i 1-i 2-2i 0 -2i true false

More products