PHYCS 3730/6720 Lab Exercise

Reading and references:

This exercise introduces classes in C++. It works with several files in the directory ~p6720/exercises/intro_to_classes. Copy all of them to a working directory.

The answer file is lab11.

Exercise 1. A primitive complex class

This is an exercise in C++ classes. We will be working with a class that allows one to do arithmetic with complex numbers. It is primitive. There are a number of standard templates for this purpose, but we will be playing with our own to understand how classes work.

First, look at mycomplex0.h and checkcmplx0.cc. Compile checkcmplx0 and run it. In your answer file, answer these questions:

Exercise 2. Adding constructors and accessors

Now look at the files mycomplex1.h and checkcmplx1.cc. Compile checkcmplx1 and run it.

Execise 3. Adding arithmetic operations

Next, look at the files mycomplex.h and checkcmplx.cc to see what they do. Then compile and run the program checkcmplx. Check the answers with Maple. Note that Maple represents complex numbers in the straightforward notation a + b*I.

Copy your program output to the answer file.