Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Software Engineering 1 (Chap. 1) Object-Centered Design."— Presentation transcript:

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

2 Problem Solving Let’s solve this temperature-conversion problem: Write a program that, given a temperature in 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)

3 Behavior A. Describe the desired behavior of the program: Our program should display a prompt for the Celsius temperature on the screen, read that temperature from the keyboard, compute the corresponding Fahrenheit temperature, and display the result, along with a descriptive label on the screen.

4 These make up the ____________ in our program. 4 Objects B. Identify the nouns in the behavioral description (other than program and user): Our program should display a prompt for the Celsius temperature on the screen, read that temperature from the keyboard, compute the corresponding Fahrenheit temperature, and display that temperature, along with a descriptive label on the screen.

5 Operations These make up the ______________ in our program. 5 B. Identify the verbs in the behavioral description: Our program should display a prompt for the Celsius temperature on the screen, read that temperature from the keyboard, compute the corresponding Fahrenheit temperature, and display that temperature, along with a descriptive label on the screen.

6 Algorithm D. Organize the objects and operations into a sequence of steps that solves the problem, called an _________________. 1. Display a prompt for the Celsius temperature on the screen. 2. Read the temperature from the keyboard. 3. Compute the Fahrenheit temperature from the Celsius temperature. 4. Display the Fahrenheit temperature, plus an informative label on the screen. 6

7 Coding Once we have designed an algorithm, the next step is to translate that algorithm into a high level language like C++. This involves figuring out how to –represent our objects, and –perform our operations, in C+ (with the aid of a book, if necessary...) 7

8 Representing Objects A. Determine a ________________________ for each object: 8

9 Performing Operations B. Identify the C++ ____________ to perform a given operation, if there is one... To compute pressure, we need to find the pressure-depth formula in a reference book... 9

10 Celsius to Fahrenheit In a reference book, we find that fahrenheit = 1.8  celsius + 32 Converting the temperature thus adds new objects and operations to our problem...

11 Objects (Revised) 11 Objects (Revised)

12 Operations (Revised) 12

13 /* temperature.cpp converts Celsius * temperatures to Fahrenheit. * * Larry Nyhoff CPSC 155X Feb. 5, 2001 * * Input: A Celsius temperature * Output: Corresponding Fahrenheit temperature */ #include // 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

14 /* temperature.cpp converts Celsius * temperatures to Fahrenheit. * * Larry Nyhoff CPSC 155X Feb. 5, 2001 * * Input: A Celsius temperature * Output: Corresponding Fahrenheit temperature */ #include // 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; } Documentation Always begin a program with an opening comment. 14

15 /* temperature.cpp converts Celsius * temperatures to Fahrenheit. * * Larry Nyhoff CPSC 155X Feb. 5, 2001 * * Input: A Celsius temperature * Output: Corresponding Fahrenheit temperature */ #include // 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; } Libraries This loads the C++ library that we need. 15

16 /* temperature.cpp converts Celsius * temperatures to Fahrenheit. * * Larry Nyhoff CPSC 155X Feb. 5, 2001 * * Input: A Celsius temperature * Output: Corresponding Fahrenheit temperature */ #include // 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

17 /* temperature.cpp converts Celsius * temperatures to Fahrenheit. * * Larry Nyhoff CPSC 155X Feb. 5, 2001 * * Input: A Celsius temperature * Output: Corresponding Fahrenheit temperature */ #include // 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

18 /* temperature.cpp converts Celsius * temperatures to Fahrenheit. * * Larry Nyhoff CPSC 155X Feb. 5, 2001 * * Input: A Celsius temperature * Output: Corresponding Fahrenheit temperature */ #include // 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

19 /* temperature.cpp converts Celsius * temperatures to Fahrenheit. * * Larry Nyhoff CPSC 155X Feb. 5, 2001 * * Input: A Celsius temperature * Output: Corresponding Fahrenheit temperature */ #include // 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

20 /* temperature.cpp converts Celsius * temperatures to Fahrenheit. * * Larry Nyhoff CPSC 155X Feb. 5, 2001 * * Input: A Celsius temperature * Output: Corresponding Fahrenheit temperature */ #include // 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

21 Testing (i) Run your program using sample data (whose correctness is easy to check): Temperature Converter!! Please enter the temperature in Celsius: 0 0 degrees Celsius is 32 degrees Fahrenheit. 21

22 Testing (ii) 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

23 Summary Writing a program consists of these steps: 1. __________ your program (using ______). 2. __________ your design. 3. __________ your program. 4. _____________________ your program as necessary. 23

24 Summary (ii) OCD is a methodology for designing programs: 1. Describe the desired _________ of the program. 2. Identify the _________ required. 3. Identify the _________ required. 4. Organize objects and operations into an ____________, refining object and operation lists as necessary. 24


Download ppt "Software Engineering 1 (Chap. 1) Object-Centered Design."

Similar presentations


Ads by Google