WEST VIRGINIA UNIVERSITY

COLLEGE OF ENGINEERING

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING

CPE 291C COMPUTER ENGINEERING LABORATORY ON OBJECT-ORIENTED PROGRAMMING IN C++

LAB #6

Objectives:

Practice the use of the "this" pointer, static data members of a class, and operator overloading. Develop a simple class for complex numbers manipulation, and a class for complex vector manipulation.

Procedure:

Part I.

  1. The implementation of a class for doubly linked lists is an example of using the "this" pointer as discussed in class. Load program Listdemo.prj into your IDE. Modify struct Node and the member functions of class List to implement a doubly linked list.
  2. Add a static data member of type int called no_of_objects to the protected section of class Point in figures.cpp. This member should be initialized to zero in the beginning of file figures.cpp, and incremented by one in the constructor function Point. Print the value of this data member at the end of function main().

Part II

3.      Develop a class called "Complex" for complex floating point number manipulation. The class should contain data members needed to specify a complex number, and functions to support the operators +, -, *, and to carry out a complex number addition, subtraction, multiplication, and conjugate operations, respectively. Also include functions for the operators +=, -=, and *=.

4.      Develop a class "Complex_Vector" for specifying and manipulating vectors whose elements are of type Complex. The length of the vector should be declared as a static constant data member of value 100 and used as a default argument in the constructor function of the class. The member functions of this class should support the operators +, -, * (which stands for a dot product), and the indexing operator [].

5.      Write a main() routine to test the classes developed above. Use the indexing operator to add or get elements to a Complex_Vector object. Implement several expressions which involve objects and combine the above operators, and verify their results. For example, let A,B,C, and D be objects of type Complex_Vector, and let x, y, and z be of type Complex, evaluate the following expressions:

z  +=  y  *=  !x  +  y,
A[0] = z,
D = A + B + C,
x = (A+B-C) * D