# CS223 Machine Problem 5

Software Laboratory: Spring 1998
University of Illinois, Urbana-Champaign

Due Date | Thursday, Apr 16th, at 4:00 PM
Readings | Lectures 1-11, Chapters 1-11 of Deitel & Deitel, Labs 1-11
Files to submit | Submit only the files mfc.h, mfc.C, malice.h, malice.C, mp5.C

## Introduction

Date: 98.04.04 23:30
From: Mike Stern
To: Malice Serf #000666
Subject: Blue Crush
Dear Malice Serf #000666,
The Esteemed Chairman of MaliceSoft, Wilhelm Goetz,
has declared war on NaiveScape. For the next two weeks,
the Core Development Team at MaliceSoft will impede any
development efforts at NaiveScape by any means necessary.
NaiveScape has one fundamental weakness, an inescapable
dependence on the MaliceSoft Foundation Class. We intend to exploit
the weakness with devastating effect.
Your mission is to document and implement the next generation
of the MFC class. Implement each function so that the default behavior
generates all kinds of problems for NaiveScape. Write the documentation
in such a way that each description is correct but extremely vague.
Next, document and implement a new Malice class derived from
the MFC class in such a way that each function overrides the respective
function in the MFC class and exhibits the desired behavior. In addition,
write the documentation in a clear, detailed, and concise manner.
Finally, you will write a simple demonstration program
to test both the MFC and Malice classes. If all goes well,
the new MFC class will render NaiveScape products unusable - ensuring
that MaliceSoft becomes the sole provider of usable products in the market.
While the Federal Government slumbers in ignorance,
MaliceSoft will crush NaiveScape in the blink of an eye.
The grand designs of The Esteemed Chairman will lead us to victory.
Failure is unacceptable,
Mike Stern
General Manager, Special Operations
MaliceSoft, Inc.

The Machine Problem

### Class Hierarchy

MFC (base class)
public: insert(), <<, round(), sort()
private: d_array[], size
protected: ???
Malice (derived class)
public: <<, round(), sort()
private: ???
You are encouraged to replace "???" with whatever functions and data
are required to facilitate the implementation of the Malice class.

### Class Design

data: d_array[]
maximum size: 32 elements
description:
Each element is a double
data: size
description:
The variable size keeps track of the number of valid elements
in d_array[]. Initially, d_array[] contains no valid elements,
so the initial value of size is zero.
function: insert()
input: double d
description:
If d_array[] has an open slot,
then the double d enters the first available slot,
and the size increases by one.
Otherwise, d_array[] and size remain unchanged.
output: none
function: output operator
objective: format
description:
Overload the output operator.
Print each valid element in d_array[].
output:
MFC: d_array[size -1] d_array[size -2] ... d_array[0]
Malice: d_array[0], d_array[1], ..., d_array[size -1]
function: round()
objective: accuracy
input: integer i
description:
Round d_array[i] to the nearest whole number.
algorithm:
MFC: Truncate
Malice: IEEE 754
output: none
function: sort()
objective: efficiency
description:
Sort the valid elements in d_array[].
algorithm:
MFC: Bubble Sort
Malice: Merge Sort
output:
MFC: "Bubble Sort: " MFC Output
Malice: "Merge Sort: " Malice Output

### Demonstration Program

function: main()
objective: demonstration
interface: menu
description:
Menu One has the following options:
1. MaliceSoft
2. NaiveScape
0. exit
When the user chooses "MaliceSoft", the program creates a new instance of the Malice class and proceeds to Menu Two.
When the user chooses "NaiveScape", the program creates a new instance of the MFC class and proceeds to Menu Two.
Menu Two has the following options:
1. insert
2. print
3. round
4. sort
0. exit
When the user chooses "insert", the program prompts the user for an element to insert.
When the user chooses "round", the program prompts the user for the element number.
When the user chooses "exit" in Menu Two, the program returns to Menu One.

## Submission

First, create a subdirectory in your home directory, and call it cs223mp5/.

mkdir cs223mp5

Change into this directory, with

cd cs223mp5

You have been provided with several test cases. (There is no wrap.C, since you will define main() yourself.)
You should copy the files in the ~cs223/src/mp5/test/ directory to your work directory

cp ~cs223/src/mp5/test/* ./

The TA solution is available as ~cs223/bin/ta-mp5. You can execute the program by giving the command:

~cs223/bin/ta-mp5

at the Unix prompt. Play around with this program to get a sense of what sort of classes and member functions you have to write.

To compile your code give the command

% make
It will produce the executable file a.out.To run the program, give the command a.out at the unix prompt.

% a.out < infile

will redirect input from infile.

To test your program against the test cases, give the command

% make testQ

where Q=1, ..., 7

% make tests

will cause all the tests to execute.

To handin your program, use the command

% make handin

Note that you must give the above handin command only from the sparc-machines in the Sparc-labs (1235/1245 DCL).

## Assessment

Your solution should compile correctly. Furthermore, output from all the test cases should match the standard output given. You should also write your program so that it adheres to the specification.

Criterion

insert(): MFC: | 5 shares in MaliceSoft
output operator: MFC: Malice: | 5 shares in MaliceSoft 5 shares in MaliceSoft
round(): MFC: Malice: | 5 shares in MaliceSoft 10 shares in MaliceSoft
sort(): MFC: Malice: | 10 shares in MaliceSoft 20 shares in MaliceSoft
main(): new object creation: old object destruction: | 5 shares in MaliceSoft 5 shares in MaliceSoft
Class Design: MFC (virtual functions): Malice (inheritance): | 5 shares in MaliceSoft 5 shares in MaliceSoft
Documentation: interface: MFC (vague): Malice (clear): implementation: MFC (clear): Malice (clear): | 4 shares in MaliceSoft 4 shares in MaliceSoft 1 shares in MaliceSoft 1 shares in MaliceSoft
Style: logical structure: meaningful identifiers: usage of idioms (e.g., i++): columns at most 75 characters: proper indentation: | 2 shares in MaliceSoft 2 shares in MaliceSoft 2 shares in MaliceSoft 2 shares in MaliceSoft 2 shares in MaliceSoft

There is an automatic 24 hour extension beyond the Thursday 4 pm deadline. There is no penalty for submission during the extension. However, Wilhelm Goetz will accept no late submissions beyond the extension.

Last revised: Apr 4th, 1998