Project 0
(Due 2/11/1010)
Question 1
Create a class called Complex for
performing arithmetic with complex numbers. Write a driver program
to test your class.
Complex numbers have the form
realPart + imaginaryPart * i
where i is (1)^(1/2)
Use integer (or floatingpoint) to represent the
private data of the class.
Provide a constructor function that enables an object of this class
to be initialized when it is declared. The constructor should
contain default values in case no initilizers are provided. Provide
public member functions for each
of the following:
a) Addition of two Complex numbers: The
real parts are added together and the imaginary parts are added
together.
b) Subtraction of two Complex numbers: The
real part of right operand is subtracted from the real part of left
operand and the imaginary parts of right operand is subtracted from
the imaginary part of left operand.
c) Printing Complex numbers in the form
(a, b) where a is the real part and b is the
imaginary part.
Hints:
Question 2
Write a grading program for a class with the
following grading policies:
1. There are two quizzes, each graded on the basis
of 10 points
2. There is one midterm exam and one final exam,
each graded on the basis of 100 points.
3. The final exam counts for 50% of the grade, the
midterm exam counts for 25%, and the two quizzes together count
for a total of 25%.
Any grade of 90 or more is an A, any grade of 80 or
more (but less than 90) is a B, any grade of 70 or more (but
less than 80) is a C, any grade of 70 or more (but less than 90)
is a D, and any grade below 60 is an F.
The program will
read in student’s scores and output the student’s record, which
consists of two quiz and two exam scores as well as the student’s
average numeric score for the entire course and final letter grade.
Define and use a class for the student record. Also, input/output
should be done with files.
Hints:
Note: Input and output must be done
using the with files. An example is given
here.
Project #1
Polynomial Calculator Program
This program simulates a polynomial calculator (Addition) that works
on a stack and a list of operations. The model is of a reverse
Polish calculator where operands are entered before the operators.
An example to add two polynomials and print the answer is
?P?Q+=
P and Q are the operands to be entered, + is add, and = is print
result. The result is put onto the calculator's stack.
Enter a string of instructions in reverse Polish form. The allowable
instructions are:
?:Read +:Add =:Print :Subtract
*:Multiply q:Quit /:Divide h:Help
Enter the coefficients and exponents for the polynomial, one pair
per line. Exponents must be in a descending order. Enter a
coefficient of 0 or an exponent of 0 to terminate.
For example take an addition of F(x)=4x²+3x and G(x)=3x³+1
You should input as
Select command and press <Enter>:?
coefficient? 4
exponent? 2
coefficient? 3
exponent? 1
coefficient? 0
Select command and press <Enter>:?
coefficient? 3
exponent? 3
coefficient? 1
exponent? 0
Select command and press <Enter>:+
Select command and press <Enter>:=
3 x^3 + 4 x^2 + 3 x + 1
Grading criteria
Correctness:
(50%) Your program must be compilable under Microsoft Visual Studio
.Net or Microsoft Visual Studio C++ platform and must accept valid
input and produce the correct result in correct format. A program
that fails to compile or produces unreasonable results loses all
credits for the correctness.
Design:
(25%) Your program should include
term.h,
polynomi.h,
polynomi.cpp
and a test driver. Of course, if you have more functions or
modules, you can include more files. You must add comments at the
beginning of your main module, and the description of every module
in your project.
Style:
(25%) You source code should comply with
the programming style
requirement listed below.
Bonus assignment (optional)
Subtraction
(2%): Besides P(x) = F(x) + G(x), also compute S(x) = F(x)  G(x).
When printing out R(x), the negative coefficent must be properly
printed. e.g., you must use the format " 2x^2 1" instead of "
2x^2 + 1 ".
Multiplication
(3%): Also compute and print M(x) = F(x) * G(x).
Division
(5%): Also compute and print the quotient Q(x) and remainder R(x) in
the division F(x) / G(x), such that F(x) = G(x) * Q(x) + R(x).
You must specify which bonus assignment have you done in the head
comments of your main module,
in order to get the
bonus points.
Reference
Section 4.5 on the
textbook page 141151
Hints
Project #2
Sorting Program
Create a Sortlist that implements 6 different
sorting methods
 Insertion sort
 Selection sort
 Shell sort (optional)
 Quick sort
 Heap sort
 Bubble sort
and calculate and print
Requirements
1. The following source files are given through
SortList.zip
Key.h and Key.cpp implement the Key class to conduct
and count Key comparisons and assignments.
Record.h and Record.cpp implement the Record class
which is used as List entry. Also, it provides operator Key to
conduct and count comparisons and assignments.
List.h is the template based array
implementation of List class
Random.h and Random.cpp implement the Random class
to set random seed and generate
random integers.
Timer.h and Timer.cpp implement the Timer class to
calculate time interval.
Utility.h provides definition of Error_code.
Main.cpp is the test driver to test the
Sortlist class. It contains user interface, filling the list with
random integers, calling Sortlist sorting functions and calculate
the CPU time, the number of comparison
of keys, and the number of assignments of list entries during the
sorting list.
Sortlist.h is the derived class of the List class.
You MUST follow the public functions I provide, but you can
add more member functions if necessary.
2. Implement the following member
functions
 void
insertion_sort(); // todo: implement insertion sort
 void
selection_sort(); // todo: implement selection sort
 void
shell_sort(); // todo; implement shell sort (optional)
 void
quick_sort(); // todo; implement quick sort
 void
heap_sort(); // todo; implement heap sort
 void
bubble_sort(); // todo; implement bubble sort
3 Submit Sortlist.h (Sortlist.cpp) only by
