1 / 24

Software Engineering

Software Engineering. (Chap. 1) Object-Centered Design. 1. OCD (Object-Centered Design). 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:

garson
Download Presentation

Software Engineering

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. OCD (Object-Centered Design) 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

  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. 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 thattemperature from the keyboard, compute thecorresponding Fahrenheit temperature, and display that temperature, along with a descriptive label on the screen. These make up the ____________ in our program. 4

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

  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 thekeyboard. 3. Compute the Fahrenheit temperature from the Celsius temperature. 4. Display the Fahrenheit temperature, plus an informative label on thescreen. 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) Objects (Revised) 11

  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 <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

  14. /* 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; } Documentation Always begin a program with an openingcomment. 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 <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; } 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 <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

  17. /* 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

  18. /* 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

  19. /* 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

  20. /* 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

  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

More Related