Presentation is loading. Please wait.

Presentation is loading. Please wait.

COS120 Software Development Using C++ AUBG Fall semester 2010 Ref book: Problem Solving, Abstraction and Design Using C++ Authors: Frank Friedman, Elliot.

Similar presentations


Presentation on theme: "COS120 Software Development Using C++ AUBG Fall semester 2010 Ref book: Problem Solving, Abstraction and Design Using C++ Authors: Frank Friedman, Elliot."— 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, http://www.aw.com/cssupporthttp://www.aw.com/cssupport Course lecturer: Assoc. Prof. Stoyan Bonev, PhD

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

3 3 Lecture Contents: t Software Development Method (Software Life Cycle) – reminder and further explanations; t Applying the SDM for solving problems based on linear and branch algorithms; t Introduction to loop algorithms.

4 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 5 Software Development Method – Software Life Cycle – Program Development Cycle Version 2:  Systems Analysis;  Systems Design;  Systems Implementation;  Systems Support.

6 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 7 Software Development Method t Problem Analysis - (Correct Problem) –Identify data objects –Determine Input / Output data –Constraints on the problem t Design –Decompose into smaller problems –Top-down design (Divide and Conquer) –Develop Algorithm (Desk Check)

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

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

10 10 Design Notations Three “notations” used to document algorithms: Flowchart Pseudo code Hierarchy chart

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

12 12 Exercise 3.1 Apply the SDM and build a linear algorithm: Problem: t To convert Celsius degrees to Fahrenheit degrees Fahr = 9/5 * Cel + 32 or t To convert Fahrenheit degrees to Celsius degrees Cel = 5/9 * (Fahr – 32)

13 13 Exercise 3.2 Apply the SDM and build a linear algorithm: Problem: To evaluate in dollars and cents a collection of coins using the formula TotalCents = 25*Quarters + 10*Dimes + 5*Nickels + Pennies; Dollars = TotalCents / 100; Change = TotalCents % 100; or Change = TotalCents–Dollars*100;

14 14 Exercise 3.3 Apply the SDM and build a linear algorithm: Problem: To compute the area and circumference of a circle (or 3 circles) area: s = π * rad * rad circumference: p = 2 * π * rad π constant is = 3.14 (more precisely π constant is = 3.14159265… )

15 15 Exercise 3.4 Apply the SDM and build a branch algorithm: Problem: To compute the area of a triangle using the Heron’s formula dealing with area s = ( p*(p-a)*(p-b)*(p-c) ) 1/2 where a, b and c are the triangle sides and p is half the perimeter p=(a+b+c)/2

16 16 Exercise 3.5 Apply the SDM and build a branch algorithm: Problem: To display a menu like 1. Rectangle 2. Square 3. Triangle 4. Circle Enter your choice (1-4)? and depending on the option selected to compute and display the area and perimeter of a rectangle, or a square, or a triangle, or a circle.

17 17 Repetition/Iteration/ (Intro to loop algorithms) Specific problem solving requirements: one, two or more process activities are to be executed zero, one, two or more times. How to build such an algorithm? –Exhaustively enumerating all activities OR –Using a loop algorithm

18 18 Remark t Introducing the concept of an accumulator –To save sum (result of many additions) Initial value –To save product (result of many multiplications) Initial value

19 19 Exercise 3.6 Apply the SDM and build a loop algorithm: Problem: To compute the Sum of a series of successive numbers 1, 2, 3, 4, 5 How to solve the problem? See next slide

20 20 Hint: 3 possible solutions Solution A:S = 1 + 2 + 3 + 4 + 5 ================================================================================== Solution B:. ================================================================================== Solution C:.

21 21 Hint: 3 possible solutions Solution A:S = 1 + 2 + 3 + 4 + 5 ================================================================================== Solution B:S = 0 S = S + 1 S = S + 2 S = S + 3 S = S + 4 S = S + 5 ================================================================================== Solution C:.

22 22 Hint: 3 possible solutions Solution A:S = 1 + 2 + 3 + 4 + 5 ================================================================================== Solution B:S = 0 S = S + 1 S = S + 2 S = S + 3 S = S + 4 S = S + 5 ================================================================================== Solution C:S = 0 S = S + I, where I=1,5, step +1

23 23 Exercise 3.6 Apply the SDM and build a loop algorithm: Problem: To compute the Sum of a series of successive numbers 1, 2, 3, 4, 5, … n

24 24 Exercise 3.7 Apply the SDM and build a loop algorithm: Problem: To compute the Product of a series of odd numbers 1, 3, 5, 7, … n

25 25 Exercise 3.8 Apply the SDM and build a loop algorithm: Problem: To compute 5 Pythagorean triples using two integers m and n (m>n) as input and applying following formulas to compute all the 3 sides of a right triangle: side 1 = m 2 –n 2 ;side 2 = 2*m*n; hypotenuse = m 2 +n 2

26 26 Thank You For Your Attention!


Download ppt "COS120 Software Development Using C++ AUBG Fall semester 2010 Ref book: Problem Solving, Abstraction and Design Using C++ Authors: Frank Friedman, Elliot."

Similar presentations


Ads by Google