Problem Solving with the Sequential Logic Structure. Chapter 5. Review. Recall that the: Algorithm: set of instructions telling the computer how to process a module in a solution. A flowchart: visual illustration of an algorithm. In this chapter you will learn how to:
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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Review • Recall that the: • Algorithm: set of instructions telling the computer how to process a module in a solution. • A flowchart: visual illustration of an algorithm. • In this chapter you will learn how to: • Write an algorithm for each module in a program. • Draw a flowchart to accompany in each algorithm.
Exit is used to end a subordinate module if there is no return value . • Return is used when the module is to be processed within an expression . average = sum ( num1 , num2) / 2
Sequential Logic Structure • The most commonly used and the simplest logic structure . • all problem use the sequential structure . • most problem problems use it in conjunction with one or more of the other logic structure .
Sequential Logic Structure • The form of the algorithm looks like this : module name ( list of parameters) 1. instruction 2. instruction 3. ….. … x x.End,Exit,or Return (variable )
Example: The algorithm and flowchart to enter a name and age into computer and print it on the screen. ( ) Notice that the algorithm instructions are numbered starting with the first instruction after the name of module
solution development • The problem analysis chart. • The interactivity chart . • The IPO chart . • The coupling diagram and the data dictionary . • The algorithms . • The flowcharts . • The seventh step in solving the problem is to test the solution to catch any errors in logic or calculation .
The Problem • Marry smith is looking for the bank that will give the most return on her money over the next five years. She has $2,000 to put into a savings account. • The standard equation to calculate principal plus interest at the end of a period of time is: Amount = p * (1+I/M)^(N*M) 12
The Problem • Amount = p * (1+I/M)^(N*M) • p= principal ( amount of money to invest) • I = interest ( percentage rate the bank pays to the invested) • N = number of years ( time for which the principle is invested ) • M = compound interval ( the number of times per year the interest is calculated and added to the principal )
Data Dictionary • in this problem all variables are local . • All coupling will be done through parameters .