C++ Plus Data Structures: Nell Dale Software Engineering Principles
C++ Plus Data Structures: Nell Dale Software Engineering Principles
Structures
Nell Dale
Chapter 1
Software Engineering Principles
Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus
1
Problem analysis
Requirements definition
Implementation of design
code it
Maintenance
Software Engineering
An Algorithm Is . . .
It works.
It can be modified.
Detailed Program
Specification
Tells
Is
written documentation
about the program.
Detailed Program
Specification Includes
Inputs
Outputs
Processing
requirements
Assumptions
7
Abstraction
Information Hiding
Building Manageable
Modules
FUNCTIONAL
DECOMPOSITION
OBJECT-ORIENTED
DESIGN
Identifies various
objects composed of
data and operations,
that can be used
together to solve
the problem.
Functional Design
Modules
Main
Prepare
File for
Reading
Get Data
Print Data
Find
Weighted
Average
Print
Weighted
Average
Print Heading
11
Object-Oriented Design
A technique for developing a program in which
the solution is expressed in terms of objects -self- contained entities composed of data and
operations on that data.
cin
cout
<<
>>
get
.
.
.
Private data
setf
.
.
.
Private data
ignore
12
13
Program Verification
PROGRAM
Processing
Requirements
Assumptions
15
Verification vs.
Validation
Program verification asks,
Are we doing the job right?
Program validation asks,
Are we doing the right job?
B. W. Boehm, Software Engineering
Economics, 1981.
16
Program Testing
...
17
output data
input data
executing
program
Keyboard
cin
(of type istream)
Screen
cout
(of type ostream)
18
<iostream.h> is header
file
Insertion Operator
( << )
Extraction Operator
( >> )
#include <iostream.h>
int main( )
{
// USES KEYBOARD AND SCREEN I/O
int
partNumber;
float unitPrice;
cout
<<
cin
cout
<<
cin
cout
output data
disk file
A:\myInfile.dat
executing
program
your variable
(of type ifstream)
disk file
A:\myOut.dat
your variable
(of type ofstream)
24
// declarations
// close files
26
#include <fstream.h>
int main( )
{ // USES FILE I/O
int
partNumber;
float
unitPrice;
ifstream inFile;// declare file variables
ofstream outFile;
inFile.open(input.dat);
//open files
outFile.open(output.dat);
inFile
inFile
outFile
>>
>>
<<
<<
partNumber ;
unitPrice ;
Part # << partNumber
// echo
at Unit Cost: $ << unitPrice << endl ;
return 0;
}
28
Stream Failure
#include <fstream.h>
#include <iostream.h>
int main( )
{ // CHECKS FOR STREAM FAIL STATE
ifstream inFile;
inFile.open(input.dat);
if ( !inFile )
{
cout << File input.dat could not be opened.;
return 1;
}
...
return 0;
}
30
Robustness
32
An Assertion
Preconditions and
Postconditions
Another Example
void GetRoots (float a, float b, float c,
float& Root1, float& Root2 )
// Pre: a, b, and c are assigned.
// a is non-zero, b*b - 4*a*c is non-zero.
// Post: Root1 and Root2 are assigned
//
Root1 and Root2 are roots of quadratic with coefficients a, b, c
{
float temp;
temp = b * b - 4.0 * a * c;
Root1 = (-b + sqrt(temp) ) / ( 2.0 * a );
Root2 = (-b - sqrt(temp) ) / ( 2.0 * a );
return;
}
36
A Walk-Through
37
Integration Testing
Prepare
File for
Reading
Get Data
Print Data
Find
Weighted
Average
Print
Weighted
Average
Print Heading
39
Integration Testing
Approaches
TOP-DOWN
BOTTOM-UP
USES: placeholder
module stubs to test
the order of calls.