Download presentation
Presentation is loading. Please wait.
1
Reference :Understanding Computers
Lecture 5 Flow Charts Reference :Understanding Computers Chapter 13
2
Definitions Flowchart: is a diagrammatic representation that illustrates the sequence of operations to be performed to get the solution of a problem.
3
Standard Symbols Used ? A A1 Start Print Results Calculate Variables
Start Or Stop Process Start Print Results Input/Output A On-Page Connector ? Yes No Condition Calculate Variables Process Rectangle A1 Off-page Connector
4
How to Write a Program? Start Define Problem to Solve
Think of an Algorithm Think of a Technique for the Solution Write Solution on a Piece of Paper If not Finished Repeat Steps 4 and 5 Write Code and Program Debug and Test If not Finished Repeat Steps 7 and 8 Stop
5
How to Write a Program ?(flowchart)
Start Job Done? No Define Problem to Solve Think of an Algorithm (Technique for the solution) Yes Write Code and Program Idea!!!! Debug and Test Think of a Technique for the solution Job Done? No Yes Stop Write it down on a piece of paper (before you forget it!!!)
6
Definitions An Algorithm A computer program makes use of algorithms.
is a complete step-by-step procedure for solving a problem or accomplishing a task.
7
Example of Flow Charts
8
Basic Flow Chart Operations
All computer instructions are based on four basic processing patterns: Simple Sequence Selection Pattern Loop Pattern
9
1.Simple Sequence Logic involves executing instructions one statement after another, in the order presented by the program. This is the simplest and most-used pattern. The computer assumes that all instructions are to be executed in this order unless the program presents other instructions.
10
Read Names Compare with Criteria Print Eligible Names
Basic Operations of Flow Charts (Simple Sequence) Read Names Compare with Criteria Basic Operations of Flow Charts (Simple Sequence) Print Eligible Names
11
Programs Write a flowchart to read three integer numbers and find their average.
12
Example Write a flowchart to ask you for the temperature in Fahrenheit and then convert it to Celsius. Given: C= 5/9 (F-32) Write a program to ask you for the temperature in Celsius and then convert it to Fahrenheit.
13
Examples Write a program to ask the user for the width and length of a piece of land and then tell him how many orange trees he can grow on it. Given that each orange tree requires 4 m2.
14
Examples Write a program to ask the user for the radius of a circle, and then display its area and circumference.
15
2. Selection Pattern Requires that the computer make a choice among two or more items. Each choice is based on one of two comparisons a computer can make: true or false (Yes or No).
16
Basic Operations of Flow Charts (Selection Pattern)
Honour Student? List under Student Loan Yes Scholarships No
17
Example Write a program to ask a student for his grades in 3 exams ( each out of 50 ) , get their total and inform the student whether he passed or failed the course.
18
If--Else for a mail order
Write a program to calculate the total price of a certain purchase. There is a discount and shipping cost: The discount rate is 25% and the shipping is if purchase is over Otherwise, The discount rate is 15% and the shipping is 5.00 pounds.
19
Example The Air Force has asked you to write a program to label aircrafts as military or civilian. Your program input is the plane’s speed and its estimated length. For planes traveling faster than 1100 km/hr, you will label those shorter than 52 m “military”, and longer as “Civilian”. For planes traveling less than 1100, you will issue an “aircraft unknown” statement.
20
Writing Nested if Statements
Display one word to describe the int value of number as “Positive”, “Negative”, or “Zero” Your city classifies a pollution index less than 35 as “Pleasant”, 35 through 60 as “Unpleasant”, and above 60 as “Health Hazard.” Display the correct description of the pollution index value.
21
Write a C program that calculates bills for the Electricity company
Write a C program that calculates bills for the Electricity company. There are 3 types of customers: residential (code R) , commercial (code C) , and Industrial (code I). - For a code R customer, the bill is $10 plus $0.05 for each kilowatt used. - For a code C customer, the bill is $1000 for the first 2000 kilowatt, and $0.005 for each additional kilowatt used. - For a code I customer, the bill is $1000 if he used less than 4000 kilowatt, $2000 if he used between 4000 and kilowatt, or $3000 if he used more than kilowatt. The inputs of the program should be the type of customer ( R C or I) and the kilowatts used. The output should be the amount of money the customer has to pay.
22
Case Study - 1 A certain Company gives each of its sales people $1,000 at the beginning of each month to cover travel, lodging, and food expenses. At the end of the month, a salesperson must total his/her expense receipts. If the amount is less than $1,000 then the difference must be returned to the company. Case Study - 1
23
Case Study - 3 Draw a flowchart to find the largest of three numbers A,B, and C.
24
Case Study - 3 Start Read A, B, C ? B > C ? A > B ? A > C Yes
No Yes Yes No No Print B Print C Print C Print A Stop
25
Case Study – 3 - (Solutions)
Consider four input cases: 1. A = ; B = ; C = 3 2. A = ; B = ; C = 7 3. A = ; B = ; C = 7 4. A = ; B = ; C = 3
26
Case Study – 3 (Solution 1)
Start B = 7 Read A, B, C C = 3 ? B > C ? A > B ? A > C Yes No Yes Yes No No Print B Print C Print C Print A Stop
27
Case Study – 3 (Solution 2)
Start B = 6 Read A, B, C C = 7 ? B > C ? A > B ? A > C Yes No Yes Yes No No Print B Print C Print C Print A Stop
28
Case Study – 3 (Solution 3)
Start B = 3 Read A, B, C C = 7 ? B > C ? A > B ? A > C Yes No Yes Yes No No Print B Print C Print C Print A Stop
29
Case Study – 3 (Solution 4)
Start B = 3 Read A, B, C C = 3 ? B > C ? A > B ? A > C Yes No Yes Yes No No Print B Print C Print C Print A Stop
30
3. Loop Pattern Directs the computer to loop back to a previous statement in the program, repeating the same sequence over again, usually with new data. By looping, the programmer avoids having to repeat the same set of instructions over and over
31
Basic Operations of Flow Charts (Loop Pattern)
More Names? No Yes Compare with Criteria Print Eligible Names
32
Uses of Flow Charts Flowcharts play a vital role in the programming of a problem and are quite helpful in understanding the logic of complicated and lengthy problems. Once the flowchart is drawn, it becomes easy to write the program in any high level language. Often we see how flowcharts are helpful in explaining the program to others. Hence, it is correct to say that a flowchart is a must for the better documentation of a complex program.
33
Uses of Flow Charts……. Flow Charts document processes and interrelationships of process steps Flow Charts identify actual and ideal paths where any product or process flows Flow Charts are used to identify problems and potential improvements Flow Charts can be completed on entire processes assemblies with all components, one person or component through a process, combinations of people and machines, transactions following forms or other documents, etc.
34
Advantages of Flow Charts
Communication: Flowcharts are better way of communicating the logic of a system to all concerned. Effective Analysis: With the help of flowchart, problem can be analysed in more effective way. Proper Documentation: Program flowcharts serve as a good program documentation, which is needed for various purposes.
35
Advantages of Flow Charts….
Efficient Coding: The flowcharts act as a guide or blueprint during the systems analysis and program development phase. Proper Debugging: The flowchart helps in debugging process. Efficient Program Maintenance: The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part.
36
Disadvantages of Flow Charts
Complex Logic: Sometimes, the program logic is quite complicated. In that case, flowchart becomes complex and clumsy. Alterations and Modifications: If alterations are required the flowchart may require re-drawing completely. Reproduction: As the flowchart symbols cannot be typed, reproduction of flowchart becomes a problem. The Essentials of what Is Done can easily be lost in the technical details of how it is done.
37
Example Assume you put 1000 pounds in a projects that returns a profit of about 5% per year. How long will it take for your money to double ? Assume you put 5000 pounds in a projects that returns a profit of about 10% per year. How much money will you have in 5 years ?
38
Example A. Mathematics B. Economics C. Programming D. Physics
Write a program that does a survey on a certain question. The question has four possible answers. Run the survey on 20 people and then display the number of people who chose each answer. Example: What is your favorite subject? A. Mathematics B. Economics C. Programming D. Physics
39
Example Write a program to display all the numbers divisible by 5 in the range 0 to 5000.
40
Example write a program that reads in the grades of 50 students in a course (out of 100 points each ) and then count the number of A students ( grade > 85 ) and the number of B students (grade > 75 ).
41
Case Study - 1 A certain Company gives each of its sales people $1,000 at the beginning of each month to cover travel, lodging, and food expenses. At the end of the month, a salesperson must total his/her expense receipts. If the amount is less than $1,000 then the difference must be returned to the company. Case Study - 1
42
Case Study – 1 (Solution)
Here is an algorithm for figuring how much money, if any, must be returned: 1-Total the expense receipts for the month. 2. Subtract the amount of the expense receipts from 1,000. 3. If the remainder is more than 0, return that amount to the company.
43
Case Study – 1 (Flow Chart)
Start Input Expenses E Yes E<1000? Subtract Expenses R <= 1000-E No Print You Owe $0 Case Study – 1 (Flow Chart) Print You Owe $R Stop
44
Assume the Employee has Spent
Case Study – 1 (Solution 1) Assume the Employee has Spent $1250 What would be the amount to return to the company in this case?
45
Case Study – 1 (Solution 1)
Start Input Expenses E<1000 ? Yes E=$1250 Subtract Expenses R <= 1000-E No Print You Owe $0 R= $0 Print You Owe $R Stop
46
Case Study – 1 (Solution 2)
Now Assume the Employee has Spent $950 What would be the amount to return to the company in this case?
47
Case Study – 1 (Solution 2)
Start Input Expenses E<1000? E=$950 R = E = $950 Yes Subtract Expenses R = 1000-E No R= $50 Print You Owe $0 Print You Owe $R Stop
48
Basic Guidelines for Flow Charting
In drawing a proper flowchart, all necessary requirements should be listed out in logical order. The flowchart should be clear, neat and easy to follow. There should not be any room for ambiguity in understanding the flowchart. The usual direction of the flow of a procedure or system is from left to right or top to bottom
49
Basic Guidelines for Flow Charting(Cont.)
Only one flow line should come out from a process symbol.
50
Basic Guidelines for Flow Charting (Cont.)
Only one flow line should enter a decision symbol, but two or three flow lines, one for each possible answer, should leave the decision symbol. Y N ? < = ? >
51
Basic Guidelines for Flow Charting (Cont.)
Only one flow line is used in conjunction with terminal symbol. Stop Start
52
Basic Guidelines for Flow Charting (Cont.)
Write within standard symbols briefly. As necessary, you can use the annotation symbol to describe data or computational steps more clearly. If the flowchart becomes complex, it is better to use connector symbols to reduce the number of flow lines. Avoid the intersection of flow lines if you want to make it more effective and better way of communication. Basic Guidelines for Flow Charting (Cont.)
53
Basic Guidelines for Flow Charting (Cont.)
Ensure that the flowchart has a logical start and finish. It is useful to test the validity of the flowchart by passing through it with a simple test data Basic Guidelines for Flow Charting (Cont.)
54
Case Study - 2 Draw a flowchart to find the sum of first 5 natural numbers.
55
Start Sum = 0 N Sum N = 0 N = N + 1 1 1 Sum = Sum + N 2 3 ? N = 5 3 6 No 4 10 Yes 5 15 Print Sum Stop
56
Case Study - 4 Draw a flowchart for computing factorial N (N!). Where N! = 1 ´ 2 ´ 3 ´ …… N . Test the program for N = 5
57
Case Study – 4 N i Fact 5 1 1 1 2 2 3 6 4 24 5 120 Start Read N
1 i = 0 1 1 i = i + 1 2 2 Fact = Fact * i 3 6 ? i >= N 4 24 No 5 120 Yes Print Fact Stop
58
5TH QUIZ
59
1 1. Which of the following is hardware Database Spreadsheet Mouse
Operating system 2. The speed of CPU is measured in Mega hertz Hectares Revolutions per minute Bits per second
60
2 3. How many bits in one byte 2 8 16 1024
4. Which one of the following is not operating system UNIX WINDOWS MS WORD MS DOS
61
3 5. Which of the following is input device Monitor. Printer.
Joystick. Speaker 6. The first instructions that a computer follows when it is turned on are stored in: ROM RAM SIMM Cache
62
4 7. Which of the following is output device Touch pad. Speaker.
Keyboard. Mouse. 8. Which of the following computer is used in home Super Computer Network computer Desktop computer Mainframe
63
5 9. The purpose of software is to convert information into data. True
False 10. Which of the following programs is most important to use a computer Database. Spreadsheet. Word Processor. Operating system
64
6 11. Freeware programs are Software that you can try free of charge before buying Software that you do not have to pay for Old versions of software that are out of date Software that will run under any operating system 12. The ability of operating system to allow one user to run two or more programs at the same time is called Spooling Program swapping Time-sharing Multitasking Virtual memory
65
7 The first step in design and execute a new program is
The plan to test the system. Design the system files. Diagram of data flow Problem analysis process An alternative to the flowchart that uses English-like statements is Reusable code iteration - Algorithm structure chart information analysis
66
8 Coding involves planning the solution to a problem
creating a program in a programming language. flowcharting pseudocode. drawing a structure chart. (It includes all of the above.)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.