Docsity

CS 101 Homework IV: Modifying Existing Code in CS101 Course - Prof. James Cohoon, Assignments of Computer Science

Toggle sidebar
bg1
CS 101 Unpledged
CS 101 Page 1 of 4 Fall 1996
Homework IV
Assigned in Laboratory V
Due Start of Laboratory VII
Please perform the following activities. This assignment is unpledged. You may work with one
other person. You are allowed to talk with others, but your work must be your own.
Objective
Much of software development is taking existing code and modifying it. The modifications may
be to add a new feature to the software, fix some bug, improve performance, or just do things bet-
ter. Because existing software is continually updated and modified, it is important that it be con-
structed so that it is easy to change. In this assignment, we update the tax graph program in
several ways. This should help you appreciate the difficulties of modifying existing code.
Problem
You are to modify your tax graph program. The modifications fall into two areas. First, the pro-
gram is not structured very well. This was not your fault, because when you wrote the original ver-
sion, you did not know about functions. Your first task is to restructure the program so that it is
broken into smaller, more manageable pieces (i.e., functions). For example, it is common practice
to have the input and output of the program handled by separate functions. One reason for this is
that these sections of a program are the most likely to change. Therefore, it is nice to have these
sections encapsulated or isolated in functions. As one part of this assignment, you should restruc-
ture your program to use functions where appropriate. At a minimum, the input and the output of
the program should be handled by separate functions. There are other tasks or subtasks that could
and should be handled by separate functions.
Before modifying any code, it would be a good idea to sit down and break the program up into
logical tasks. Once you’ve done this, you might show your proposed design to a teaching assistant
for feedback. We recommend that you do this before modifying your code. Do not wait till the
last minute to get feedback!
The second area of modification concerns the display of the bar graph. As currently displayed, the
graph is hard to interpret. Most bar graphs of this type use a stack of segments. When displayed
this way, it is easy to see what percentage of the whole each tax bracket is contributing. Addition-
ally, the current graph is hard to interpret because there is no legend. It would be nice to label the
graph so that what each portion represents is clear. The EzWindows API provides a class that can
help us do this. Look at page 736 in your book at the class Label. We can use this class to place
text at appropriate points in the window. In particular, you can use it to label the segments of the
bar graph. To use the class label, you will need to place the following include statement in your
program.
#include "label.h"
This statement must precede the include for rect.h.
Notes
The textual input and output of your program should be just like the original program. The fol-
lowing two screen captures demonstrate this aspect of your program.
pf3
pf4

Partial preview of the text

Download CS 101 Homework IV: Modifying Existing Code in CS101 Course - Prof. James Cohoon and more Assignments Computer Science in PDF only on Docsity!

Homework IV

Assigned in Laboratory V

Due Start of Laboratory VII

Please perform the following activities. This assignment is unpledged. You may work with one other person. You are allowed to talk with others, but your work must be your own.

Objective

Much of software development is taking existing code and modifying it. The modifications may be to add a new feature to the software, fix some bug, improve performance, or just do things bet- ter. Because existing software is continually updated and modified, it is important that it be con- structed so that it is easy to change. In this assignment, we update the tax graph program in several ways. This should help you appreciate the difficulties of modifying existing code.

Problem

You are to modify your tax graph program. The modifications fall into two areas. First, the pro- gram is not structured very well. This was not your fault, because when you wrote the original ver- sion, you did not know about functions. Your first task is to restructure the program so that it is broken into smaller, more manageable pieces (i.e., functions). For example, it is common practice to have the input and output of the program handled by separate functions. One reason for this is that these sections of a program are the most likely to change. Therefore, it is nice to have these sections encapsulated or isolated in functions. As one part of this assignment, you should restruc- ture your program to use functions where appropriate. At a minimum, the input and the output of the program should be handled by separate functions. There are other tasks or subtasks that could and should be handled by separate functions.

Before modifying any code, it would be a good idea to sit down and break the program up into logical tasks. Once you’ve done this, you might show your proposed design to a teaching assistant for feedback. We recommend that you do this before modifying your code. Do not wait till the last minute to get feedback!

The second area of modification concerns the display of the bar graph. As currently displayed, the graph is hard to interpret. Most bar graphs of this type use a stack of segments. When displayed this way, it is easy to see what percentage of the whole each tax bracket is contributing. Addition- ally, the current graph is hard to interpret because there is no legend. It would be nice to label the graph so that what each portion represents is clear. The EzWindows API provides a class that can help us do this. Look at page 736 in your book at the class Label. We can use this class to place text at appropriate points in the window. In particular, you can use it to label the segments of the bar graph. To use the class label, you will need to place the following include statement in your program. #include "label.h"

This statement must precede the include for rect.h.

Notes

The textual input and output of your program should be just like the original program. The fol- lowing two screen captures demonstrate this aspect of your program.

your program electronically before the beginning of Laboratory VII. See your handout for how to do this. You should call your file hw04.cpp when you copy it to the CS1 server. Do not copy the project file.

You should also turn in a hard copy (print out) at the beginning of your laboratory when the pro- gram is due.

See the 101 Web page for the grading criteria for this assignment. The URL is:

http://www.cs.virginia.edu/cs101/