4.2 Flowcharts and Algorithms

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the difference between Assignments and Equalities?

During assignment, the result of the calculation on the right side of an equals sign is assigned to a variable on the left of the equals sign. Equality is a logical test that evaluates whether two values are equivalent.

implementation-independent

Flowcharts can be created that are implementation-independent. That is, they can describe physical or logical processes in such a way that the logic is expressed independently of any particular programming language or implementation method

Three types of outputs for flowcharts

Display, Print, and Prompt.

If-Then-Null-Else

An Else action is not required for every If-Then statement. If the logical test is true, then the do-if-true action should be taken otherwise no action is taken. example: For example, if a sales person exceeds a sales goal, then calculate a bonus; otherwise, do not calculate a bonus.

Nested selection

Depending on how the first decision is answered, the flow can go to additional decisions. Programming with this type of structure can be much more efficient than doing the same thing with a series of nested conditional (if-then-else) statements.

If-Then-Else

If a condition is true, then perform an action; else perform a different action.

Until loop

Similar but opposite to the while loop rather than loop while a condition is false it loops until a condition is false However, rather than loop while a condition is false it loops until a condition is false. While and until loops are interchangeable by reversing the condition. For example, "loop while x > 0" is conceptually the same as "loop until x = 0".

5 Fundamental parts of any flowchart process

Start Input data Perform the algorithm (logic and calculations) Output the results End it is also essential that the value of variables be correct as the algorithm executes.

Order of Flowcharts

Top to bottom, left to right

test of equality

VERY different than assignment a logical test that evaluates whether two values are equivalent tests of equality return either true or false. if what is on the left and right side of the equal symbol are equal, the equality returns true; otherwise, it returns false. Tests of equality are part of conditional logic. EXAMPLE: If Today = "Friday", Then Balance = Balance - 50. In this case, we check to see if the value of the Today variable is equal to "Friday". If it is, we take 50 away from our Balance and then assign that new value into our Balance variable. LEFT SIDE: "If" portion -test of equality RIGHT SIDE: "Then" portion a value assignment

Why flowchart?

a picture is worth a thousand words independent of implementation -physical or logical processes -supports any programming environment Works well for technical and non technical

Algorithm

a set of steps for completing a task that can be written down and implemented. Algorithms are made up of actions/steps, decisions, inputs, and outputs. For example, a cake recipe can be thought of as an algorithm for making cake. An algorithm prepared for a computer program describes how to take known inputs and convert them into specific outputs by following a set of specific actions.

loop (repetition flow control) pattern

allows one or more actions to be repeated until a condition is met. (a step or set of steps is repeated until a certain condition is met.) example: ordering at mcdonalds

flowchart

an efficient way to express algorithms in a succinct and precise manner. Flowcharts can be valuable when conceptualizing a process, analyzing requirements, and training workers and users. Another benefit of flowcharts is that they can be used by both technical and non-technical people. Flowcharts are commonly used by managers, engineers, and software developers; so, it is good to develop skill in the proper and correct design of flowcharts.

Why only one input and one output?

because it provides the benefit that it is easy to locate the entry point and exit point of each construct. This makes each piece of a program easy to understand and maintain.

Inputs

can come from two sources 1. users 2. data stored in a setup section Values stored in setup storage can reduce the need to re-input values each time the program is run. For example, if shipping rates rarely change for a shipping office, these rates could be stored in a setup section so that the user does not need to enter this data each time the application is run. When designing a flowchart, the designer should determine which inputs should be entered every time and which, if any, should be stored in setup storage. As shown in Figure 7, when regular inputs are required, the "Input" word should be used. When input from setup is required, the "Input-from-Setup" phrase should be used.

sequence pattern

one step is completed followed by a next step and so on.

Where does flowcharting fit in SDLC?

planning, analysis, design, development, testing, implementation, maintenance ALLL OF THE STEPS.

three fundamental flow control patterns:

sequence, selection, and repetition

selection pattern

the answer to a question causes a branch in the process. Thus, some steps are skipped under certain circumstances. As we define a decision, it will return either true or false. Thus, if the decision returns true, one branch is taken. If the decision returns false, the other branch is taken.

While Loop

the most common type of repetition structure. tests a condition first. If the test returns false, then a process is executed. Then the flow loops back to the decision again. Each time the test returns false, the process is done again. If the test returns true, the algorithm exits the loop. The While loop can be thought of as a repeating If-Then-Else statement. example" For instance, assume a host offers you one cookie at a time until you tell the host you have had enough. If it is true that you have had enough, the loop terminates. Otherwise, you are given a cookie. Then the loop returns to the decision. Each time "Had enough?" is false (you want another cookie), you are given a cookie; and the loop returns to the decision again. If the decision (Had enough?) returns true, the loop terminates

Assignments

the result of the calculation on the right side of an equals sign is assigned to a variable on the left of the equals sign. EXAMPLE: consider the assignment "Pay = Hours * Rate". In this assignment, Hours is multiplied by Rate, and the result of this calculation is assigned to the Pay variable on the left of the equals sign. Assignments always go from right to left.

Prompt

used when it is necessary to ask the user for some specific input after the program has begun.

Print

used when output is sent to a printer.

Display

used when output is sent to the computer screen.

Flowchart symbols/ variable names

you should use short variable names in flowchart symbols to keep flowcharts compact and easy to draw Variable names should not be separated by spaces because computer programs think of variables as a single entity and will interpret a space as the end of a variable name. For example, NP, Net_Pay, and netPay are fine as variable names but "Net Pay" is not.


Ensembles d'études connexes

CSCS Chapter 14 - Warm Up and Flexibility Training

View Set

Combo with "computer forensics - quiz 1" and 7 others

View Set

Chapter 2 International business

View Set

chapter nine chronic illness and disease

View Set

Segment 8: The Mortgage Loan Application

View Set