24
Software Engineering Software Engineering 1 (Chap. 1) Object-Centered Design

Software Engineering 1 (Chap. 1) Object-Centered Design

Embed Size (px)

Citation preview

Page 1: Software Engineering 1 (Chap. 1) Object-Centered Design

Software EngineeringSoftware Engineering

1

(Chap. 1)

Object-Centered Design

Page 2: Software Engineering 1 (Chap. 1) Object-Centered Design

Problem SolvingProblem Solving

Let’s solve this Let’s solve this temperature-conversion problemtemperature-conversion problem::

Write a program that, given a temperature in Write a program that, given a temperature in Celsius, displays that temperature in Fahrenheit. Celsius, displays that temperature in Fahrenheit.

5 Phases of Software Life Cycle:•Problem Analysis and Specification•Design•Implementation (Coding)•Testing, Execution and Debugging•Maintenance

OCD (Object-Centered Design)

Page 3: Software Engineering 1 (Chap. 1) Object-Centered Design

BehaviorBehavior

A. Describe the desired behavior of the program:A. Describe the desired behavior of the program:

Our program should display a prompt for the Celsius Our program should display a prompt for the Celsius temperature on the screen, read that temperature temperature on the screen, read that temperature from the keyboard, compute the corresponding from the keyboard, compute the corresponding Fahrenheit temperature, and display the result, along Fahrenheit temperature, and display the result, along with a descriptive label on the screen.with a descriptive label on the screen.

Page 4: Software Engineering 1 (Chap. 1) Object-Centered Design

These make up the ____________ in our program.These make up the ____________ in our program.

4

ObjectsObjectsB. Identify the B. Identify the nounsnouns in the behavioral description in the behavioral description

(other than program and user):(other than program and user):

Our program should display a prompt for the Our program should display a prompt for the Celsius temperature on the screen, read thatCelsius temperature on the screen, read thattemperature from the keyboard, compute thetemperature from the keyboard, compute thecorresponding Fahrenheit temperature, and corresponding Fahrenheit temperature, and display that temperature, along with a descriptive display that temperature, along with a descriptive label on the screen.label on the screen.

Page 5: Software Engineering 1 (Chap. 1) Object-Centered Design

OperationsOperations

These make up the ______________ in our These make up the ______________ in our program.program.

5

B. Identify the B. Identify the verbsverbs in the behavioral description: in the behavioral description:

Our program should display a prompt for the Our program should display a prompt for the Celsius temperature on the screen, read thatCelsius temperature on the screen, read thattemperature from the keyboard, compute thetemperature from the keyboard, compute thecorresponding Fahrenheit temperature, and corresponding Fahrenheit temperature, and display that temperature, along with a descriptive display that temperature, along with a descriptive label on the screen.label on the screen.

Page 6: Software Engineering 1 (Chap. 1) Object-Centered Design

AlgorithmAlgorithm

D. Organize the objects and operations into a D. Organize the objects and operations into a sequence of steps that solves the problem, sequence of steps that solves the problem, called an _________________. called an _________________.

11. Display . Display a prompta prompt for for the Celsius temperaturethe Celsius temperature on on the screenthe screen..

22. Read . Read the temperaturethe temperature from from thethe keyboardkeyboard..

33. Compute . Compute the Fahrenheit temperaturethe Fahrenheit temperature from from the the Celsius temperatureCelsius temperature..

44. Display . Display the Fahrenheit temperaturethe Fahrenheit temperature, plus an , plus an informative labelinformative label on on thethe screenscreen..

6

Page 7: Software Engineering 1 (Chap. 1) Object-Centered Design

CodingCoding

Once we have designed an algorithm, the Once we have designed an algorithm, the next step is to translate that algorithm next step is to translate that algorithm into a high level language like C++.into a high level language like C++.

This involves figuring out how to This involves figuring out how to – represent our objects, andrepresent our objects, and

– perform our operations,perform our operations,

in C+ in C+ (with the aid of a book, if (with the aid of a book, if necessary...)necessary...)

7

Page 8: Software Engineering 1 (Chap. 1) Object-Centered Design

Representing ObjectsRepresenting Objects

A. Determine a ________________________A. Determine a ________________________ for each object: for each object:

8

Object C++ Type Name

a promptthe Celsius temp.the screenthe keyboardthe Fahrenheit temp.a label

stringdoubleostreamistreamdoublestring

--celsiuscoutcinfahrenheit--

Page 9: Software Engineering 1 (Chap. 1) Object-Centered Design

Performing OperationsPerforming Operations

B. Identify the C++ ____________ to perform B. Identify the C++ ____________ to perform a given operation, if there is one... a given operation, if there is one...

To compute pressure, we need to find the To compute pressure, we need to find the pressure-depth formula in a reference book...pressure-depth formula in a reference book...

9

Operation Library? Name

Display a stringRead a doubleCompute fahrenheitDisplay a double

iostreamiostream--iostream

<<>>--<<

Page 10: Software Engineering 1 (Chap. 1) Object-Centered Design

Celsius to FahrenheitCelsius to Fahrenheit

In a reference book, we find thatIn a reference book, we find that

fahrenheit = 1.8celsius + 32

Converting the temperature thus adds Converting the temperature thus adds new objects and operations to our new objects and operations to our problem...problem...

Page 11: Software Engineering 1 (Chap. 1) Object-Centered Design

Objects (Revised)Objects (Revised)

11

Objects (Revised)Objects (Revised)

Object C++ Type Name

a promptthe celsius temp.the screenthe keyboardthe fahrenheit temp.a labelconversion factor 1.8conversion factor 32

stringdoubleostreamistreamdoublestringdoubleint

--celsiuscoutcinfahrenheit------

Page 12: Software Engineering 1 (Chap. 1) Object-Centered Design

Operations (Revised)Operations (Revised)

12

Operation Library? Name

Display a stringRead a doubleCompute fahrenheit

Multiply two doublesAdd double & int

Display a double

iostreamiostream

built-inbuilt-in

iostream

<<>>

*+

<<

Page 13: Software Engineering 1 (Chap. 1) Object-Centered Design

/* temperature.cpp converts Celsius * temperatures to Fahrenheit. * * Larry Nyhoff CPSC 155X Feb. 5, 2001 * * Input: A Celsius temperature * Output: Corresponding Fahrenheit temperature */

#include <iostream> // cin, cout, <<, >>using namespace std;

int main(){ cout << "Temperature Converter!!" << endl << "Please enter the temperature in Celsius: "; double celsius; cin >> celsius; double fahrenheit = 1.8 * celsius + 32; cout << endl << celsius << " degrees Celsius is " << fahrenheit << " degrees Fahrenheit." << endl;}

The Code

13

Page 14: Software Engineering 1 (Chap. 1) Object-Centered Design

/* temperature.cpp converts Celsius * temperatures to Fahrenheit. * * Larry Nyhoff CPSC 155X Feb. 5, 2001 * * Input: A Celsius temperature * Output: Corresponding Fahrenheit temperature */

#include <iostream> // cin, cout, <<, >>using namespace std;

int main(){ cout << "Temperature Converter!!" << endl << "Please enter the temperature in Celsius: "; double celsius; cin >> celsius; double fahrenheit = 1.8 * celsius + 32; cout << endl << celsius << " degrees Celsius is " << fahrenheit << " degrees Fahrenheit." << endl;}

DocumentationAlways begin a program with an opening comment.

14

Page 15: Software Engineering 1 (Chap. 1) Object-Centered Design

/* temperature.cpp converts Celsius * temperatures to Fahrenheit. * * Larry Nyhoff CPSC 155X Feb. 5, 2001 * * Input: A Celsius temperature * Output: Corresponding Fahrenheit temperature */

#include <iostream> // cin, cout, <<, >>using namespace std;

int main(){ cout << "Temperature Converter!!" << endl << "Please enter the temperature in Celsius: "; double celsius; cin >> celsius; double fahrenheit = 1.8 * celsius + 32; cout << endl << celsius << " degrees Celsius is " << fahrenheit << " degrees Fahrenheit." << endl;}

LibrariesThis loads the C++ library that we need.

15

Page 16: Software Engineering 1 (Chap. 1) Object-Centered Design

/* temperature.cpp converts Celsius * temperatures to Fahrenheit. * * Larry Nyhoff CPSC 155X Feb. 5, 2001 * * Input: A Celsius temperature * Output: Corresponding Fahrenheit temperature */

#include <iostream> // cin, cout, <<, >>using namespace std;

int main(){ cout << "Temperature Converter!!" << endl << "Please enter the temperature in Celsius: "; double celsius; cin >> celsius; double fahrenheit = 1.8 * celsius + 32; cout << endl << celsius << " degrees Celsius is " << fahrenheit << " degrees Fahrenheit." << endl;}

main()All C++ programs

have a main function.

16

Page 17: Software Engineering 1 (Chap. 1) Object-Centered Design

/* temperature.cpp converts Celsius * temperatures to Fahrenheit. * * Larry Nyhoff CPSC 155X Feb. 5, 2001 * * Input: A Celsius temperature * Output: Corresponding Fahrenheit temperature */

#include <iostream> // cin, cout, <<, >>using namespace std;

int main(){ cout << "Temperature Converter!!" << endl << "Please enter the temperature in Celsius: "; double celsius; cin >> celsius; double fahrenheit = 1.8 * celsius + 32; cout << endl << celsius << " degrees Celsius is " << fahrenheit << " degrees Fahrenheit." << endl;}

Step 1:Print introductory message.

17

Page 18: Software Engineering 1 (Chap. 1) Object-Centered Design

/* temperature.cpp converts Celsius * temperatures to Fahrenheit. * * Larry Nyhoff CPSC 155X Feb. 5, 2001 * * Input: A Celsius temperature * Output: Corresponding Fahrenheit temperature */

#include <iostream> // cin, cout, <<, >>using namespace std;

int main(){ cout << "Temperature Converter!!" << endl << "Please enter the temperature in Celsius: "; double celsius; cin >> celsius; double fahrenheit = 1.8 * celsius + 32; cout << endl << celsius << " degrees Celsius is " << fahrenheit << " degrees Fahrenheit." << endl;}

Step 2:Read the Celsius

temperature.

18

Page 19: Software Engineering 1 (Chap. 1) Object-Centered Design

/* temperature.cpp converts Celsius * temperatures to Fahrenheit. * * Larry Nyhoff CPSC 155X Feb. 5, 2001 * * Input: A Celsius temperature * Output: Corresponding Fahrenheit temperature */

#include <iostream> // cin, cout, <<, >>using namespace std;

int main(){ cout << "Temperature Converter!!" << endl << "Please enter the temperature in Celsius: "; double celsius; cin >> celsius; double fahrenheit = 1.8 * celsius + 32; cout << endl << celsius << " degrees Celsius is " << fahrenheit << " degrees Fahrenheit." << endl;}

Step 3:Calculate the

Fahrenheit temperature.

19

Page 20: Software Engineering 1 (Chap. 1) Object-Centered Design

/* temperature.cpp converts Celsius * temperatures to Fahrenheit. * * Larry Nyhoff CPSC 155X Feb. 5, 2001 * * Input: A Celsius temperature * Output: Corresponding Fahrenheit temperature */

#include <iostream> // cin, cout, <<, >>using namespace std;

int main(){ cout << "Temperature Converter!!" << endl << "Please enter the temperature in Celsius: "; double celsius; cin >> celsius; double fahrenheit = 1.8 * celsius + 32; cout << endl << celsius << " degrees Celsius is " << fahrenheit << " degrees Fahrenheit." << endl;}

Step 4:Display the results.

20

Page 21: Software Engineering 1 (Chap. 1) Object-Centered Design

Testing (i)Testing (i)Run your program using sample data (whose correctness is Run your program using sample data (whose correctness is

easy to check):easy to check):

Temperature Converter!!Please enter the temperature in Celsius: 0

0 degrees Celsius is 32 degrees Fahrenheit.

21

Page 22: Software Engineering 1 (Chap. 1) Object-Centered Design

Testing (ii)Testing (ii)

Do many tests on “interesting” data points.Do many tests on “interesting” data points.

Temperature Converter!!Please enter the temperature in Celsius: -17.78

-17.78 degrees Celsius is -0.004 degrees Fahrenheit.

22

Page 23: Software Engineering 1 (Chap. 1) Object-Centered Design

SummarySummary

Writing a program consists of these steps:Writing a program consists of these steps:

1. __________ your program (using ______).1. __________ your program (using ______).

2. __________ your design.2. __________ your design.

3. __________ your program.3. __________ your program.

4. _____________________ your program as 4. _____________________ your program as necessary.necessary.

23

Page 24: Software Engineering 1 (Chap. 1) Object-Centered Design

Summary (ii)Summary (ii)

OCD is a methodology for designing OCD is a methodology for designing programs:programs:

1. Describe the desired 1. Describe the desired __________________ of the of the program.program.

2. Identify the 2. Identify the __________________ required. required.

3. Identify the 3. Identify the __________________ required. required.

4. Organize objects and operations into an 4. Organize objects and operations into an ________________________ , refining object and operation , refining object and operation lists as necessary.lists as necessary. 24