C Plus Data Structure
C Plus Data Structure
C Plus Data Structure
Nell Dale
David Teague
Chapter 1
Software Engineering Principles
4
Goals of Quality Software
• It works.
• It can be modified.
5
Detailed Program Specification
• Is written documentation
about the program.
6
Detailed Program Specification
Includes
• Inputs
• Outputs
• Processing requirements
• Assumptions
7
Abstraction
8
Information Hiding
9
Two Approaches to Building Manageable
Modules
FUNCTIONAL OBJECT-ORIENTED
DECOMPOSITION DESIGN
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
>> <<
ignore
12
More about OOD
l Languages supporting OOD include: C++, Java,
Smalltalk, Eiffel, and Object-Pascal.
13
Procedural vs. Object-Oriented Code
“Read the specification of the
software you want to build.
Underline the verbs if you are after
procedural code, the nouns if you
aim for an object-oriented program.”
14
Program Verification
• Program Verification is the process of
determining the degree to which a
software product fulfills its specifications.
SPECIFICATIONS
Inputs
Outputs
Processing
Requirements
PROGRAM
Assumptions
15
Verification vs. Validation
Program verification asks,
“Are we doing the job right?”
16
Program Testing
• Testing is the process of executing a
program with various data sets
designed to discover errors.
DATA SET 1
DATA SET 2
DATA SET 3
DATA SET 4
...
17
Keyboard and Screen I/O
#include <iostream>
using namespace std;
input data output data
executing
Keyboard program Screen
cin cout
18
namespace
• In slides that follow, assume the
statement:
using namespace std;
19
<iostream> is header file
• for a library that defines 3 objects
20
Insertion Operator ( << )
• The insertion operator << takes 2
operands.
23
#include <iostream>
using namespace std;
int main( )
{ // USES KEYBOARD AND SCREEN I/O
int partNumber;
float unitPrice;
cout << “Enter part number followed by return : “
<< endl ; // prompt
cin >> partNumber ;
cout << “Enter unit price followed by return : “
<< endl ;
cin >> unitPrice ;
cout << “Part # “ << partNumber // echo
<< “at Unit Cost: $ “ << unitPrice << endl ;
return 0;
} 24
Disk files for I/O
#include <fstream>
input data output data
28
#include <fstream>
using namespace std
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 >> partNumber ;
inFile >> unitPrice ;
outFile << “Part # “ << partNumber // echo
<< “at Unit Cost: $ “ << unitPrice << endl ;
return 0;
} 29
Stream Failure
• When a stream enters the fail state, further I/O
operations using that stream are ignored. But the
computer does not automatically halt the program or
give any error message.
30
#include <fstream>
#include <iostream>
using namespace std
int main( )
{ // CHECKS FOR STREAM FAIL STATE
ifstream inFile;
inFile.open(“input.dat”); // try to open file
if ( !inFile )
{
cout << “File input.dat could not be opened.”;
return 1;
}
...
return 0;
} 31
Various Types of Errors
32
Robustness
33
An Assertion
• Is a logical proposition that is either true or
false (not necessarily in C++ code).
EXAMPLES
studentCount is greater than 0
sum is assigned && count > 0
response has value ‘y’ or ‘n’
partNumber == 5467
34
Preconditions and Postconditions
list.ResetList();
length = list.LengthIs();
for (int counter = 1; counter <= length; counter++)
{
list.GetNextItem(item);
item.Print(dataFile);
}
36
}
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
{
using namespace std;
float temp;
temp = b * b - 4.0 * a * c;
Root1 = (-b + sqrt(temp) ) / ( 2.0 * a );
38
Tasks within each test case:
39
Integration Testing
Print Heading
40
Integration Testing Approaches
TOP-DOWN
BOTTOM-UP