Software errors:

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
[http://www.softwareqatest.com/qatfa
q1.html].
Do you like horror stories?
http://www.cs.tau.ac.il/~nachumd/horr
or.html
Therac-25 Incident:
Error in radiation doses to cancer
patients.
[http://courses.cs.vt.edu/cs3604/lib/Th
erac_25/Therac_1.html]
Also p. 202.
Chapter 22 Design
Software Life Cycle
Analysis (Requirements)
Design
Implementation
Testing
Deployment
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
change.
True problem solving often occurs
after flaws are discovered!
Examples:
• 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
people).
• 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
characters
......
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
[http://www.ie.inf.uc3m.es/grupo/doce
ncia/reglada/psii/SwEng2/Unit4.pdf]
 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
development.
 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
iteration.
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
proof”.
OO Design
Discover classes
Determine class’ responsibilities
Describe relationships among classes.
Some things to bear in mind:
Cohesion
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.
Coupling:
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:
Inheritance.
You’ve seen it and we’ll cover later.
Dependency:
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.
Aggregation
 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
aggregation.
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
employees.
 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
class
3. Describe relationships between
classes
Do the case study starting on page
839.
Example: Model the NCAA basketball
tournament.
Display the scores of all games in a
given round.
Display the scores of all the games in a
region.
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
Java
Both are case sensitive.
Both have similar syntax. Often
causing some to think the
languages are similar. THEY ARE
NOT!
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
faster.
Major differences in parameter
passing.
Java:
primitives are pass by value, objects are
pass by reference
C++:
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
types.
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
application.
Also see Appendix I and
[http://www.dickbaldwin.com/java/Jav
a008.htm].
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. [http://msdn.microsoft.com/enus/magazine/cc163681.aspx]
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.
[http://www.developer.com/net/cplus/print.php/219
7621]
http://social.msdn.microsoft.com/Forums/en/xnaga
mestudioexpress/thread/effcca73-b4f2-4a74-91e3cb92d2008a29
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
C++Code.
Select C++ file under Visual Studio Installed
Templates.
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
directory).
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;
cin.get();
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
ViewtoolBox.
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
form)
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);
t++;
textBox1->Clear();
textBox1->AppendText(t.ToString());
We will NOT do much with GUI
interfaces.
Software often follows a 3-tier design
as below. This course focuses on the
middle tier.
Interface
(GUI or
console)
Program
logic
Data (files
or
database)