Software errors:
Software bugs in a Soviet early-warning
monitoring system nearly brought on nuclear war
in 1983, according to news reports in early 1999.
The software was supposed to filter out false
missile detections caused by Soviet satellites
picking up sunlight reflections off cloud-tops, but
failed to do so. Disaster was averted when a
Soviet commander, based on what he said was a
'...funny feeling in my gut', decided the apparent
missile attack was a false alarm. The filtering
software code was rewritten
Designing and testing is critical.
See Software QA and Testing faq at
Do you like horror stories?
Therac-25 Incident:
Error in radiation doses to cancer
Also p. 202.
Chapter 22 Design
Software Life Cycle
Analysis (Requirements)
Waterfall Model (p. 827)
Appears logical but does not work
very well in practice when problems
are extremely complex.
Not realistic to assume complex
processes flow linearly.
Imagine designing and building a
home this way – with no option for
True problem solving often occurs
after flaws are discovered!
• Often difficult to state all requirements
exactly prior to the design phase.
• Perhaps there were inconsistent
requirements (not unusual when
requirements are generated by many
• Seeing results can change
requirement expectations.
Imagine the following requirements
(among hundreds) for a game.
Requirement 14.
Only basic food staples shall be carried by game
Requirement 223.
Every game character shall carry water.
Requirement 497.
Flour, butter, milk and salt shall be considered the
only basic food staples.
Reference for the preceding slide,
and other examples, at
 Requirements are often changing (new
rules or regulations).
 A design may be sound in theory, but not in
practice due to finite limits on computers
(Reason for algorithm analysis).
 Bug fixes sometimes require a redesign.
 Customers might not like the final product
(even though it was designed to their
specs). They may have changed their mind
or had a change in thinking.
 Spiral model (p. 828).
Iterative approach to software
 Can be more responsive to changes or
inexperienced customers.
 Can lead to inefficiencies (or sloppiness)
because developers know there is
another iteration in the process and may
not be as complete in the current
Much of this falls into the category of
Systems Analysis or Project
Management and is covered in depth
in CS460.
Ultimately, software should be “idiot
OO Design
Discover classes
Determine class’ responsibilities
Describe relationships among classes.
Some things to bear in mind:
Interface features should be closely related
to a single concept the class represents.
See example on p. 834
If you account for half-dollars or silver
dollars, you must change the
CashRegister class.
This is what you want to avoid.
Measure of the extent to which classes
depend on other classes. Note: dependency
relationship on p. 835.
Maximize cohesion and remove
unnecessary coupling.
Class relationships:
You’ve seen it and we’ll cover later.
Class A depends on class B if any
of A’s methods use an object of
type B in any way.
Page 834-5: The CashRegister
class depends on the Coin class.
 If an object of one class contains
objects of another class then the first
class aggregates the other.
 stronger form of dependency.
 If a class “is made up of” elements
from another class, it may be an
Based on the information provided we
don’t know if the CashRegister class
aggregates the Coin class or just
depends on it.
Does the CashRegister class contain
a list of coins or just the total value of
the coins.
It could be designed either way,
though the first is probably best.
 Strictly an interpretation of the realities of
the model you’re dealing with.
 A department is “made up of” employees,
so a department may aggregate
 That is, the department class probably
contains employee objects.
 The book makes a reference to pointers.
Forget about that for now.
See side bar on page 837
Go through example of using
inheritance vs aggregation.
Multiplicity of an aggregation.
See page 839.
CRC Cards (Classes,
Responsibilities, Collaborators).
1. Discover classes
2. Determine Responsibilities of each
3. Describe relationships between
Do the case study starting on page
Example: Model the NCAA basketball
Display the scores of all games in a
given round.
Display the scores of all the games in a
Display the scores of all games played
by a given team.
Display points scored by each player in
each game played.
Comparisons between C++ and
Both are case sensitive.
Both have similar syntax. Often
causing some to think the
languages are similar. THEY ARE
Java is pure object oriented, C++ is
not. C++ can have functions that
are not members of a class.
This can be an advantage but may
also allow sloppy design.
Java compilers typically generate byte
code, standard C++ compilers
generate machine code (.exe) file.
Can run simply by double clicking on
the .exe file or by specifying the file
name in the run command.
Byte code usually results in better
portability; .exe files generally run
Major differences in parameter
primitives are pass by value, objects are
pass by reference
can specify how to pass parameters.
C++ supports pointer variables and
addresses, Java does not.
C++ supports preprocessing and
macros (code expansion).
C++ allows you to define your own
Java has automatic garbage
collection, standard C++ does not.
Java hides more specific machine
details from the programmer.
Can be good or bad, depending on the
Also see Appendix I and
Can also search google using key
words differences Java C++.
Visual Studio .NET Specifics:
Distinction between Managed
(C++/CLI) and Unmanaged (standard
C++) applications. This is not
important for the course goals
(primarily standard C++), but it can
NOT be avoided entirely. In addition,
it's important to note that the old
Visual studio 2003 and 2005 versions
of managed code are quite different.
Some differences:
C++/CLI (Common Language Infrastructure)
Microsoft's extension to C++ for the .NET
environment. []
Compiles to an Intermediate Language and runs in
a virtual machine environment.
Has access to both managed and unmanaged
data. To oversimplify, managed provides some
garbage collection abilities as in Java.
Standard C++
Well established language.
Code may still be portable; it would just
have to be recompiled.
Compiles to machine code.
Programmers have to do their own
garbage collection.
We’ll deal just with standard C++ and
design. Managed code adds little to
the goals of this course. We’ll
distinguish ONLY when we have to.
Creating your first unmanaged C++ program
in Microsoft Visual Studio .NET 2008
Start Microsoft Visual Studio .NET.
You can close the Start page if it appears.
Make sure the Solution Explorer pane is visible by
selecting ViewSolution Explorer.
Select FileNewProject.
Select the name of the project and the location in
which it will be store. A folder will be created with
this name at that location.
Under Project Types select Visual C++WIN32.
Also select WIN32 Console Application under
Visual Studio installed templates.
Specify a name and location for your project.
Clear the checkbox associated with Create
directory for solution next to the Solution name
textbox. Checking it creates a subdirectory inside
the one you are already creating. It’s not
necessary for this course.
Click OK.
The WIN32 Application Wizard will appear. When
it does, click on the Application Settings link.
Select the Console Application radio button.
Select the Empty Project textbox.
Click the Finish button.
You now have a project with no
associated code and the Solution
Explorer pane should contain three
items (Header files, Resource files,
and Source files) under the name of
your project. In this course you will
need to be concerned only with the
header and source files.
In the Solution Explorer pane, right click on
Source files and select AddNew Item.
In the Categories pane, select Visual
Select C++ file under Visual Studio Installed
Enter a name for the file in the textbox provided
(You do not need to specify .cpp in the name).
Leave the location as it is (your solution
Click the Add button.
A window will appear in which you can enter
some C++ code.
Enter the C++ Code in the window
associated with the file you just created.
For example, enter the code below
#include <iostream>
using namespace std;
int main()
cout << "Hello: This is your first C++ Program" << endl;
return 0;
Press the F5 key to run the program. A console
window will appear with the message above.
Press the Enter key to exit the program.
At this point you can exit Visual Studio .NET,
saving your files.
To restart Visual Studio .NET and run the same
program, double click on the solution file (File with
the ”sln” extension) in the solution folder.
To run this program without entering the Visual
Studio .NET environment, double click on the
“exe” file found in the Debug folder.
Creating a C++ Program in Microsoft
Visual Studio .NET with a simple user
interface (optional).
Proceed as describe previously except
Under Project Types select Visual C++CLR
Also select Windows Form Application under
Visual Studio installed templates.
You may have to specify “C" drive location to
avoid a trusted user warning.
A blank form will appear allowing you to drag
gui elements onto it.
Make the toolbox visible by selecting
Use the toolbox to drag and drop various gui
elements onto the form
Example: Create one button and textbox:
Put textBox1->Text = "0" in the form_load method. (You
can get to this method by double clicking on the blank
Put the following in the button_click method. (You can get
to this method by double clicking on the button)
int t = Int32::Parse(textBox1->Text);
We will NOT do much with GUI
Software often follows a 3-tier design
as below. This course focuses on the
middle tier.
(GUI or
Data (files

Comparisons between C++ and Java (Appendix I)