Presentation is loading. Please wait.

Presentation is loading. Please wait.

COS120 Software Development Using C++ AUBG Fall semester 2010

Similar presentations


Presentation on theme: "COS120 Software Development Using C++ AUBG Fall semester 2010"— Presentation transcript:

1 COS120 Software Development Using C++ AUBG Fall semester 2010
Ref book: Problem Solving, Abstraction and Design Using C++ Authors: Frank Friedman, Elliot Koffman, Course lecturer: Assoc. Prof. Stoyan Bonev, PhD

2 Lecture 2: Introduction to Computers, Problem Solving and Programming (continued)

3 Lecture Contents: Software Development Method (Software Life Cycle) – reminder and further explanations; Illustration of applying IPO model of computing process; Applying the SDM for solving problems based on linear and branch algorithms

4 Software Development Method – Software Life Cycle – Program Development Cycle
Version 1: ·        Specify the problem requirements; ·        Analyze the problem; ·        Design the algorithm to solve the problem; ·        Implement the algorithm; ·        Test and verify the completed program; ·        Maintain and update the program. 

5 Software Development Method – Software Life Cycle – Program Development Cycle
 Version 2: ·        Systems Analysis; ·        Systems Design; ·        Systems Implementation; ·        Systems Support.

6 Software Development Method – Software Life Cycle – Program Development Cycle
Version 3: Analyze: Define the problem Design: Plan the solution to the problem Choose the interface: Select text boxes, buttons, etc Code: Translate the algorithm into a Prog Lan like C/C++ or C# or Java or VBasic Test & Debug: Locate and remove any errors in program Complete Documentation: Organize program description

7 Software Development Method – Software Life Cycle – Program Development Cycle
Simplified Version 4 (as in E.Petroutsos, pp28): Decide what the application will do and how it will interact with the user. Design the application’s user interface according to requirements of step 1. Write the actual code behind the events you want to handle.

8 Software Development Method
Problem Analysis - (Correct Problem) Identify data objects Determine Input/Output data Constraints on the problem Design Decompose into smaller problems Top-down design (divide and conquer) Develop Algorithm (Desk check)

9 Software Development Method
Implementation Writing the algorithm Testing Verify the program meets requirements System and Unit test Documentation Key part in the development process

10 Algorithm definitions
Definition 1: A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time Definition 2: A procedure for solving a problem in terms of 1.   the actions to be executed, and 2.  the order in which these actions are to be executed is called an algorithm. Definition 3: An algorithm is a list of steps for solving a problem.

11 How to document algorithms?
Three “notations” used to document algorithms: • Flowchart • Pseudo code • Hierarchy chart

12 Flowchart Also named a control-flow diagram
Graphically depicts the logical steps to carry out a task and show how the steps relate to each other. Uses a set of graphic symbols to indicate what should happen at any stage in the algorithm.

13 Flowchart symbols

14 Flowchart symbols

15 Flowchart example

16 Pseudo code Uses English-like phrases with some C/C++ terms to outline the program

17 Hierarchy charts Show how the different parts of a program relate to each other Hierarchy charts may also be called: Structure charts HIPO (Hierarchy plus Input-Process-Output) charts Top-Down charts VTOC (Visual Table of Contents) charts

18 Comments When tracing a flow chart, start at the start symbol and follow the flow lines to the end symbol. Testing an algorithm at the design stage is known as desk checking. Flowcharts, pseudo code, and hierarchy charts are program planning tools that are not dependent on the programming language being used.

19 Applying the Software Development Method
Stage: Analyze the Problem Stage: Design the algorithm IPO model of a computing process I - Input P - Process O - Output

20 Applying the Software Development Method
Attention: Analyze the problem and design the algorithm: It is helpful to underline phrases in the problem statement that identify input and output. See the example below: Problem: Compute and display the total cost of apples given the number of kilos of apples purchased and the cost per kilogram of apples.

21 Applying the Software Development Method
Problem: Compute and display the total cost of apples (output) given the number of kilos of apples purchased and the cost per kilogram of apples.

22 Applying the Software Development Method
Problem: Compute and display the total cost of apples (output) given the number of kilos of apples (input-1) purchased and the cost per kilogram of apples.

23 Applying the Software Development Method
Problem: Compute and display the total cost of apples (output) given the number of kilos of apples (input-1) purchased and the cost per kilogram of apples (input-2).

24 Applying the Software Development Method
Problem: Compute and display the total cost of apples (output) given the number of kilos of apples (input-1) purchased and the cost per kilogram of apples (input-2).

25 Applying the Software Development Method (cont.)
Problem input: quantity of apples purchased (in kg) cost per kilo of apples (in $ or in BGN) Problem output:     total cost of apples (in $ or in BGN) After specifying inputs and outputs, develop list of formulas, giving relationship between input and output. Abstract form: Total cost = Unit cost * Number of units Detailed, concrete form: Total_cost_of_apples = Cost_per_kg * Kilos_of_apples

26 Abstract form of the algorithm
. Begin Enter Input Data Apply formula or a list of formulas Display Result End

27 Abstract form of the algorithm
0. Naming memory locations to store input data, intermediate values and final results Begin Enter Input Data Apply formula or a list of formulas Display Result End

28 Concrete form of an algorithm
0. We need three memory cells: to store two input values and one for the result. We’ll use names QantityOfApples, CostPerKilo, and TotalCost Begin Enter data and store in QuantityOfApples, CostPerKilo TotalCost = QuantityOfApples * CostPerKilo; Display contents of TotalCost End

29 Applying the Software Development Method
Case Study:Converting Miles to Kilometers Problem  Your job requires you to study some maps that give distances in kilometers and some that use miles. You prefer to deal in metric measurements. Write a program that performs the necessary conversion.

30 Applying the Software Development Method
Analysis  The first step in solving this problem is to determine what you are asked to do. You must convert from one system of measurement to another, but are you supposed to convert from kilometers to miles, or vice versa? The problem states that you prefer to deal in metric measurements, so you must convert distance measurements in miles to kilometers.

31 Applying the Software Development Method
Design  The next step is to formulate the algorithm that solves the problem. Begin by listing the three major steps, or sub problems of the algorithm. Implementation  To implement the solution, you must write the algorithm as a C++ program. Testing  How do you know the sample run is correct?

32 Problem: Converting Miles to Kilometers
Problem formulated: Design an algorithm and develop a program to convert miles to kilometers.

33 Problem: Converting Miles to Kilometers
Underline phrases to identify input and output Design an algorithm and develop a program to convert miles (input) to kilometers (output). Input: miles Output: kilometers

34 Problem: Converting Miles to Kilometers
Develop a formula or a list of formulas, giving relationship between input and output 1 mile is equivalent to 1,609 kilometers 1 mile = km const float KMS_PER_MILE = 1.609; #define KMS_PER_MILE

35 Problem: Converting Miles to Kilometers
Reminder: Abstract form of the algorithm 0. Naming memory locations to store input data, intermediate values and final results Begin Enter Input Data Apply formula or a list of formulas Display Output Result End

36 Problem: Converting Miles to Kilometers
Reminder: Abstract form of the algorithm 0. Naming memory locations to store input data, intermediate values and final results Begin Enter Input Data Apply formula or a list of formulas Display Output Result End Applying naming conventions: we need 2 mnemonic names (identifiers): For the input data we’ll use name miles. For the result value we’ll use name kms.

37 Problem: Converting Miles to Kilometers
Final version of the concrete algorithm 0. Naming conventions: miles for miles, kms for kilometers Begin Enter value for miles (store input data into miles). Calculate kilometers multiplying miles by and save result (store into kms) Apply formula: kms = * miles; Output Result (contents of kms displayed on screen). End

38 Problem: Converting Miles to Kilometers
Describe the algorithm Converting miles to kilometers using a flowchart Also named a control-flow diagram

39 Problem: Converting Miles to Kilometers

40 Problem: Converting Miles to Kilometers
Describe the algorithm Converting miles to kilometers using pseudo code Uses English-like phrases with some C/C++ terms to outline the program

41 Problem: Converting Miles to Kilometers
1. Read the number of miles 2. Set the number of kilometers to * miles 3. Display the number of kilometers

42 Problem: Converting Miles to Kilometers
Describe the algorithm Converting miles to kilometers using a hierarchy chart Show how the different parts of a program relate to each other

43 Problem: Converting Miles to Kilometers

44 The source text of a C++ program Implementing algorithm
Open the handout file: look at page 2 The source text of a C++ program Implementing algorithm CONVERT MILES TO KILOMETERS

45 Exercise 2.1 Apply the SDM and build a linear algorithm: Problem:
Converting feet and inches to meters

46 Exercise 2.2 Apply the SDM and build a linear algorithm: Problem:
To add, subtract, multiply and divide two numeric values

47 Exercise 2.3 Apply the SDM and build a branch algorithm:
Problem:  Root (solution) of a linear equation bx + c = 0

48 Exercise 2.3 Apply the SDM and build a branch algorithm:
Problem:  Root (solution) of a linear equation bx + c = 0 (single solution x = -c/b, infinite number of solutions, no solution);

49 Exercise 2.4 Apply the SDM and build a branch algorithm:
Problem: Roots (solution) of a quadratic equation ax2 + bx + c = 0 (two distinct solutions, two identical solutions, no real solutions).

50 Friedman/Koffman, Chapter 01
Before lecture end Lecture: Problem Solving More to read: Friedman/Koffman, Chapter 01 Or Coming approx. 10 slides

51 Chapter 1: Introduction to Computers, Problem Solving, and Programming
Abstraction, and Design using C++ 5e by Frank L. Friedman and Elliot B. Koffman

52 1.5 Software Development Method
Problem Analysis Identify data objects Determine Input / Output data Constraints on the problem Design Decompose into smaller problems Top-down design (divide and conquer) Develop Algorithm (Desk check) Algorithm refinement

53 Software Development Method
Implementation Converting the algorithm into programming language Testing Verify the program meets requirements System and Unit test Maintenance All programs undergo change over time

54 1.6 Applying the Software Development Method
Case Study: Converting Miles to Kilometers Problem  Your summer surveying job requires you to study some maps that give distances in kilometers and some that use miles. You and your coworkers prefer to deal in metric measurements. Write a program that performs the necessary conversion.

55 Data Requirements Problem Input miles distance in miles Problem Output
kms the distance in kilometers Relevant Formula 1 mile = kilometers

56 Design Formulate the algorithm that solves the problem. Algorithm
1. Get the distance in miles. 2. Convert the distance to kilometers. 3. Display the distance in kilometers. Algorithm Refinement 2.1 The distance in kilometers is the distance in miles Desk check!

57 Listing 1.2 Miles to kilometers

58 Implementation #include <iostream> using namespace std;
int main( ) { const float KM_PER_MILE = 1.609; float miles, kms; cout << “Enter the distance in miles: “; cin >> miles; kms = KM_PER_MILE * miles; cout << “The distance in kilometers is “ << kms << endl; return 0; }

59 Testing Test with input data for which you can easily determine the expected results E.g. 10 miles should convert to kilometers

60 Thank You For Your Attention


Download ppt "COS120 Software Development Using C++ AUBG Fall semester 2010"

Similar presentations


Ads by Google