1 Programming and Problem Solving — Software Engineering (Read Chap. 2)

Slides:



Advertisements
Similar presentations
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Advertisements

Python Programming: An Introduction to Computer Science
INTRODUCTION T.Najah Al_Subaie Kingdom of Saudi Arabia Prince Norah bint Abdul Rahman University College of Computer Since and Information System CS240.
1 Lab-1 CSIT-121 Spring 2005 Lab Targets Solving problems on computer Programming in C++ Writing and Running Programs Programming Exercise.
Ch. 1: Software Development (Read) 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution.
1 Session-I & II CSIT-121 Spring 2006 Session Targets Introducing the VC++.NET Solving problems on computer Programming in C++ Writing and Running Programs.
Computer Programming 1 Problem Solving and Software Engineering.
Problem Solving and Software Engineering Chapter 1.
Computer Science 1620 Programming & Problem Solving.
1 Lab-1 CSIT-121 Fall 2004 Lab Targets Solving problems on computer Programming in C++ Writing and Running Programs Programming Exercise.
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
Software Engineering 1 (Chap. 1) Object-Centered Design.
The switch Statement Selection Revisited. Problem Using OCD, design and implement a program that allows the user to perform an arbitrary temperature conversion.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
Programming and Problem Solving — Software Engineering (Read Chap. 2) 1.
Problem Solving and Software Engineering Chapter 1.
1 C++ Loop Statements Repetition Revisited. 2 Problem Using OCD, design and implement a function that, given a menu, its first valid choice, and its last.
CS161 Topic #21 CS161 Introduction to Computer Science Topic #2.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
Software Life Cycle Requirements and problem analysis. –What exactly is this system supposed to do? Design –How will the system solve the problem? Coding.
Creating your first C++ program
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 1- 1 October 20, October 20, 2015October 20, 2015October 20,
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Controlling Function Behavior Sequence, Selection and Repetition.
1 Chapter-01 Introduction to Software Engineering.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
File I/O ifstreams and ofstreams Sections 11.1 &
C++ Loop Statements Repetition Revisited. Problem Using OCD, design and implement a function that, given a menu, its first valid choice, and its last.
Fundamental Programming: Fundamental Programming Introduction to C++
1 CS161 Introduction to Computer Science Topic #3.
1 Simple Functions Writing Reuseable Formulas. In Math Suppose f (x) = 2 x 2 +5Suppose f (x) = 2 x 2 +5 f(5)=?f(5)=? f(5) = 2* =55f(5) = 2*
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
1 Chapter-01 Introduction to Software Engineering.
File I/O 1 ifstreams and ofstreams Sections 11.1 & 11.2.
1 Ch. 1: Software Development (Read) 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution.
Basics of Most C++ Programs // Programmer: Clayton Price date: 9/4/ // File: fahr2celc.cpp 03. // Purpose:
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Software Engineering Object-Centered Design. Problem Solving Does anyone scuba dive? Let’s solve this scuba-diving problem: Write a program that, given.
Software Development Problem Analysis and Specification Design Implementation (Coding) Testing, Execution and Debugging Maintenance.
12/18/2015 CSI Chapter 1 1 Compiler + Linker = Ready to run code Compiler translates high-level language source code into an intermediate object.
Software Engineering. Acknowledgement Charles Moen Sharon White Bun Yue.
Lesson - 2. Introduction When we make a program we must follow some steps, called Programming Development Life Cycle (PDLC). Programming steps are five:
Simple Functions Writing Reuseable Formulas. Problem Using OCD, design and implement a program that computes the area and circumference of an Australian.
Today in CS161 Lecture #5 Learn about… Data types (char, int, float) Input and Output (cin, cout) Writing our First Program Write the Inches to MM Program.
The Hashemite University Computer Engineering Department
1 CS 1430: Programming in C++. 2 Input: Input ends with -1 Sentinel-Controlled Loop Input: Input begins with.
1 Chapter-01 Introduction to Software Engineering.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics.
© Peter Andreae Java Programs COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
Software Engineering (Chap. 1) Object-Centered Design When we prepare a program, the experience can be just like composing poetry or music … My claim is.
1 Objects Types, Variables, and Constants Chapter 3.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
CS 115 Lecture 5 Math library; building a project Taken from notes by Dr. Neil Moore.
Fundamental Programming Fundamental Programming Data Processing and Expressions.
Software Engineering Algorithms, Compilers, & Lifecycle.
Introduction to Computers and C++ Programming
Completing the Problem-Solving Process
Chapter 2 Assignment and Interactive Input
Lecture 2 Introduction to Programming
Writing Reuseable Formulas
solve the following problem...
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Life is Full of Alternatives
Software Development Chapter 1.
Object-Centered Design
Presentation transcript:

1 Programming and Problem Solving — Software Engineering (Read Chap. 2)

Problem Solving 5 Phases of (Simplified) Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution and Debugging Maintenance OCD (Object-Centered Design) A Temperature-conversion problem: Write a program that, given a temperature in Celsius, displays that temperature in Fahrenheit.

OCD (Object-Centered Design) 1.Describe the _____________ of the program. 2.Identify the problem’s ____________ and make a table of information about them. 3.Identify the problem’s _________________ and make a table of information about them. 4.Organize the objects and operations into a sequence of steps, called a _________________, to solve the problem. 3

Behavior Using OCD A. Describe the desired behavior of the program: Our program should display program information to the user and then 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.

These make up the ____________ in our problem. 5 Problem Objects B. Identify the nouns in the behavioral description (other than "non-behavioral" ones like program and user): Our program should display program information to the user and then 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. Using OCD

Information about Objects Determine a _______and a ________ (if necessary) for each object and whether it is a ____________ or a ______________. 6 Using OCD cout cin Problem Object Type Kind Name program informationtextconstant none prompttextconstant none Celsius temperaturereal number variable celsius screenoutputvariable keyboardinputvariable Fahrenheit temperaturereal number variable fahrenheit labeltextconstant none C++ Type ? ? double ? ? ?

Operations These make up the ______________ in our problem. 7 C. Identify the verbs in the behavioral description: Our program should display program information to the user and then 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. Using OCD

Information about Operations Identify the C++ ____________ to perform a given operation, if there is one. 8 To compute the Fahrenheit temperature, we need to know/find the Celsius to Fahrenheit conversion formula. Using OCD Operation Pre- defined? C++ Operator Library Displayyes <<iostream Readyes >>iostream Compute the Fahrenheit temperature ??????

Celsius to Fahrenheit Formula for converting Celsius to Fahrenheit: fahrenheit = 1.8  celsius + 32 Converting the temperature thus adds new objects and operations to our problem. 9 Using OCD

10 Information about Objects (Revised) Using OCD Problem Object Type Kind C++ Type Name program informationtextconstant ? none prompttextconstant ? none Celsius temperature real number variable doublecelsius screenoutputvariable ?cout keyboardinputvariable ?cin Fahrenheit temperature real number variable doublefahrenheit labeltextconstant ? none conversion factor 1.8 real number constant double none conversion factor 32 integer constant int none

11 Using OCD Information about Operations (Revised) Operation Pre- defined? C++ OperatorLibrary Displayyes <<iostream Readyes >>iostream Compute the Fahrenheit temperature: Multiply two real values (1.8 and celsius) yes * built-in Add a real value (the result above) and an integer (32) yes + built-in Store a real value (the result above) in a variable yes = built-in

Algorithm 12 Using OCD D. Organize the objects and operations into a sequence of steps that solves the problem, called an __________________. 1. Display via cout information about the program to the user. 2. Display via cout a prompt for the Celsius temperature. 3. Read the temperature from cin. 4. Compute the Fahrenheit temperature from the Celsius temperature. l. 5. Display via cout the Fahrenheit temperature and an informative label.

Coding Once we have designed an algorithm, the next step is to translate that algorithm into a high level language like C++. This involves writing instructions to — represent the objects, and — perform the operations in C++. 13

14 /* temperature.cpp converts a Celsius temperature to Fahrenheit. John Doe Lab 1 Jan. 5, 2012 CS 104X Input: A Celsius temperature Output: Corresponding Fahrenheit temperature */ #include // cin, cout, > using namespace std; int main() { // 1. Display via cout information about the // program to the user. // 2. Display via cout a prompt for the Celsius // temperature. // 3. Read the temperature from cin. // 4. Compute the Fahrenheit temperature from the // Celsius temperature. // 5. Display via cout the Fahrenheit temperature // and an informative label. } When learning to program, it is helpful to just start with the algorithm as comments in main() The Code

cout << "John Doe CS 104X -- Lab 1\n\n"; cout << "** Convert Celsius temps to Fahrenheit **\n"; cout << "Please enter a temperature in Celsius: "; 15 /* temperature.cpp converts a Celsius temperature to Fahrenheit. John Doe Lab 1 Jan. 5, 2012 CS 104X Input: A Celsius temperature Output: Corresponding Fahrenheit temperature */ #include // cin, cout, > using namespace std; int main() { // 1. Display via cout information about the // program to the user. // 2. Display via cout a prompt for the Celsius // temperature. The Code

double celsius; cin >> celsius; double fahrenheit = 1.8 * celsius + 32; cout << celsius << " degrees Celsius is " << fahrenheit << " degrees Fahrenheit.\n"; 16 // 3. Read the temperature from cin. // 4. Compute the Fahrenheit temperature from the // Celsius temperature. // 5. Display via cout the Fahrenheit temperature // and an informative label. } The Code It’s wise to echo input data to insure computer read what you intended.

17 Comments /* temperature.cpp converts a Celsius temperature to Fahrenheit. John Doe Lab 1 Jan. 5, 2012 CS 104X Input: A Celsius temperature Output: Corresponding Fahrenheit temperature */ #include // cin, cout, > using namespace std; int main() { // 1. Display via cout information about the // program to the user. cout << "John Doe CS 104X -- Lab 1\n\n"; cout << "** Convert Celsius temps to Fahrenheit **\n"; // 2. Display via cout a prompt for the Celsius // temperature. cout << "Please enter a temperature in Celsius: "; Always begin a program with opening documentation enclosed in /* and */.

/* temperature.cpp converts a Celsius temperature to Fahrenheit. John Doe Lab 1 Jan. 5, 2012 CS 104X Input: A Celsius temperature Output: Corresponding Fahrenheit temperature */ #include // cin, cout, > using namespace std; int main() { // 1. Display via cout information to the user. cout << "John Doe CS 104X -- Lab 0\n\n"; cout << "** Convert Celsius temps to Fahrenheit **\n"; // 2. Display via cout a prompt for the Celsius // temperature. cout << "Please enter a temperature in Celsius: "; 18 Libraries This loads the C++ library that we need. Lab & Proj. 1: #include

19 /* temperature.cpp converts a Celsius temperature to Fahrenheit. John Doe Lab 1 Jan. 5, 2012 CS 104X Input: A Celsius temperature Output: Corresponding Fahrenheit temperature */ #include // cin, cout, > using namespace std; int main() { // 1. Display via cout information about the // program to the user. cout << "John Doe CS 104X -- Lab 1\n\n"; cout << "** Convert Celsius temps to Fahrenheit **\n"; // 2. Display via cout a prompt for the Celsius // temperature. cout << "Please enter a temperature in Celsius: "; Each step of the algorithm is implemented by one or more C++ program statements inside main() function.

20 // 3. Read the temperature from cin. double celsius; cin >> celsius; // 4. Compute the Fahrenheit temperature from the // Celsius temperature. double fahrenheit = 1.8 * celsius + 32; // 5. Display via cout the Fahrenheit temperature // and an informative label. cout << celsius << " degrees Celsius is " << fahrenheit << " degrees Fahrenheit.\n"; } Always a good idea to echo input data Note spacing, indentation, & alignment to make program “look nice” and easier to read. This will be one criterion used in grading. Each step of the algorithm is implemented by one or more C++ program statements inside main() function.

Testing Run your program using sample data (whose correctness is easy to check): John Doe CS 104X -- Lab 1 ** Convert Celsius temps to Fahrenheit ** Please enter the temperature in Celsius: 0 0 degrees Celsius is 32 degrees Fahrenheit. 21 John Doe CS 104X -- Lab 1 ** Convert Celsius temps to Fahrenheit ** Please enter the temperature in Celsius: degrees Celsius is 212 degrees Fahrenheit.

When you are convinced that the program is correct, run it with the required data values. John Doe CS 104X -- Lab 1 ** Convert Celsius temps to Fahrenheit ** Please enter the temperature in Celsius: degrees Celsius is degrees Fahrenheit. 22

23 For a programming assignment: Lose a few points or may be lucky and the grader doesn’t catch it. For a real-world problem: Much more may be at stake: money, jobs, and even lives. Why Testing is Important: September,1999: Mars Climate Orbiter June, 1996: Ariane 5 rocket March,1991: DSC Communications February 25, 1991(Gulf War): Patriot missile Testing is never finished; it is only stopped. Testing can only show the presence of errors, not their absence. See Other Course Information (CS 104 page): Importance of Program Testing — Horror Stories Importance of Program Testing — Horror Stories

Maintenance 24 Large % of computer center budgets Large % of programmer's time Largest % of software development cost Why? Poor structure, poor documentation, poor style   less likely to catch bugs before release   fixing of bugs difficult and time-consuming   impede implementation of enhancements See Other Course Information (CS 104 page): Time Spent on Program MaintenanceTime Spent on Program Maintenance