02 FirstProgramStructure - CSCI1205
02 FirstProgramStructure - CSCI1205
Lecture 02
Aleksandar Zoranic
University of New Orleans
http://computer.howstuffworks.com/routing-algorithm3.htm 3
Software Life Cycle
6 stages
1. Analysis and specification of the task
(problem definition)
2. Design of the software
(object and algorithm design)
3. Implementation (coding)
4. Testing
5. Maintenance and evolution of the system
6. Obsolescence
4
Program Design
Programming is a creative
process
No complete set of rules for
creating a program
5
Problem Solving Phase
Be certain the task is
completely specified
What is the input?
What information is in the
output?
What error conditions can
arise?
How can I test easily and
comprehensively?
What output am I returning?
Testing:
Run the program on sample data,
test harness
Verify correctness of results
Characteristics
Encapsulation
Information hiding
Objects contain their own data and algorithms
Inheritance
Writing reusable code
Objects can inherit characteristics from other
objects
Polymorphism
A single name can have multiple meanings
depending
on its context Picture from Zeegee software
9
Introduction to C++
Where did C++ come from?
Derived from the C language
C was derived from the B language
B was derived from the BCPL language
10
C++ History
C developed by Dennis Ritchie at AT&T
Bell Labs in the 1970s.
Used to maintain UNIX systems
Many commercial applications written in c
C++ developed by Bjarne Stroustrup at AT&T
Bell Labs in the 1980s.
Overcame several shortcomings of C
Incorporated object oriented programming
C remains a subset of C++
11
A Sample C++ Program
A simple C++ program begins this way
#include <iostream>
using namespace std;
int main()
{
return 0;
}
Display 1.8
12
Explanation of code (1/5)
Variable declaration line
13
Explanation of code (2/5)
Program statement
14
Explanation of code (3/5)
Program statement
is stored
15
Explanation of code (4/5)
Program statement
total_peas = number_of_pods *
peas_per_pod;
Performs a computation
‘*’ is used for multiplication
‘=‘ causes total_peas to get a new value based
on the calculation shown on the right of the equal sign
16
Explanation of code (5/5)
Program statement
17
Program Layout (1/3)
18
Program Layout (2/3)
Variables are declared before they are used
Typically variables are declared at the beginning of
the program
Statements (not always lines) end with a semi-colon
Include Directives
#include <iostream>
Tells compiler where to find information about items
used in the program
iostream is a library containing definitions of cin
and cout
19
Program Layout (3/3)
using namespace std;
Tells the compiler to use names in iostream in
a “standard” way
20
Running a C++ Program
C++ source code is written with a text
editor
21
Run a Program
Obtain code in Display 1.10 Display 1.10
Compile the code
Fix any errors the compiler indicates and
re-compile the code
Run the program
Now you know how to run a program on
your system
22
Section 1.3 Conclusion
Can you…
24
Example of Software Failures
March 31, 1986: Mexicana 1991 Gulf War, failure of a Patriot
Airline, Boeing 727 crashed missile system to track an Iraqi
into a mountain Scud missile, killed 28 American
soldiers
March-June 1986: Therac 25
October 26, 1992, the ambulance
radiation therapy machines
dispatch system in London failed
overdosed cancer patients
after installation
November 2-4, 1988: Morris June 4, 1996, ESA’s Ariane 5
Computer virus rocket exploded 40 seconds after
September 17, 1991: A power liftoff
outage at AT&T switching December 10, 1990, Space Shuttle
facility in NYC interrupted Columbia was forced to land early
service to 10 million phone September 1999, Mars Climate
users for 9 hours Orbiter exploded on entry
27