Skip to content

CS 1415 - Lab #5

Objectives: 

Program with classes

Preparation: 

Review sections 13.1-13.17 from Starting Out with C++ by Gattis.

Programming: 

  1.  Name your files LlllFfffLab05.cpp, LlllFfffComplex.cpp, and LlllFfffComplex.h where Llll is the first four letters of your last name and Ffff is the first four letters of your first name.
  2. Create a class called Complex to model a complex number. Use double variables for the two data members. Provide an explicit value constructor with default arguments. Provide member functions for addition of two complex numbers, subtraction of two complex numbers, and printing a complex number. The printing function should output the complex number in the form a + bi where a is the real part and b is the imaginary part. The addition and subtraction functions should be set up so that the following statement would add c2 and c1 together returning the result without changing c2 and c1.

    c3 = c2.add(c1); 

  3. In addition to the Complex class, you need to write a driver program to test/demonstrate your class. The program should get two complex numbers from the user and show the sum and difference of those two numbers. The program's output statements should show the two complex operands as well as the complex result. All code for the class should be in its own library.
  4. Verify your program works correctly.
  5. Submit your source code files to ude.wons@nosneros.htrag. Due at 8:00 am on 4 February.