+ All Categories
Home > Documents > Example # 1 Draw a flowchart for calculating the area of a room: In order to calculate the area of...

Example # 1 Draw a flowchart for calculating the area of a room: In order to calculate the area of...

Date post: 18-Jan-2016
Category:
Upload: blaze-sherman-garrett
View: 228 times
Download: 0 times
Share this document with a friend
Popular Tags:
13
Example # 1 • Draw a flowchart for calculating the area of a room: • In order to calculate the area of the room, we must know firstly the length and the width of the room. Then we calculate the area by multiplying the length by width.
Transcript
Page 1: Example # 1 Draw a flowchart for calculating the area of a room: In order to calculate the area of the room, we must know firstly the length and the width.

Example # 1Example # 1

• Draw a flowchart for calculating the area of a room:

• In order to calculate the area of the room, we must know firstly the length and the width of the room. Then we calculate the area by multiplying the length by width.

Page 2: Example # 1 Draw a flowchart for calculating the area of a room: In order to calculate the area of the room, we must know firstly the length and the width.

• Goal: calculating the area of the room.• Input: length and width.• Process: area = length * width.• Output: area.

• Goal: calculating the area of the room.• Input: length and width.• Process: area = length * width.• Output: area.

Page 3: Example # 1 Draw a flowchart for calculating the area of a room: In order to calculate the area of the room, we must know firstly the length and the width.

STARTSTART

Input lengthInput length

Input widthInput width

area = length * widtharea = length * width

ENDEND

Output areaOutput area

Flowchart

Page 4: Example # 1 Draw a flowchart for calculating the area of a room: In order to calculate the area of the room, we must know firstly the length and the width.

• The following flowchart is in correct. Can you guess why?

STARTSTART

Input lengthInput length

Input widthInput width

area = length * widtharea = length * width

ENDEND

Output areaOutput area

Page 5: Example # 1 Draw a flowchart for calculating the area of a room: In order to calculate the area of the room, we must know firstly the length and the width.

• It is wrong because we cannot calculate the area of the room before knowing the length and width of the room. So, we should input the length and width of the room then calculate area.

Page 6: Example # 1 Draw a flowchart for calculating the area of a room: In order to calculate the area of the room, we must know firstly the length and the width.

Example # 2Example # 2

• Draw a flowchart which reflects the process of deciding whether a student has passed or failed . the course based on the average three exams.

Page 7: Example # 1 Draw a flowchart for calculating the area of a room: In order to calculate the area of the room, we must know firstly the length and the width.

• Goal: decide whether the student pass or failed the course.

• Input: m1, m2, m3 /*m mass mark */• Arithmetic Process:– sum = m1 + m2 + m3.– average = sum/3.

• Logical process: is the average greater or equal to 60.

• Output: passed or failed.

Page 8: Example # 1 Draw a flowchart for calculating the area of a room: In order to calculate the area of the room, we must know firstly the length and the width.

avg = sum/3avg = sum/3

Is avg>=60

Is avg>=60

STARTSTART

Input m1,m2,m3Input m1,m2,m3

sum = m1+m2+m3sum = m1+m2+m3

ENDEND

Output “failed”Output “failed”

Output “passed”Output

“passed”

Flowchart

YES NO

Page 9: Example # 1 Draw a flowchart for calculating the area of a room: In order to calculate the area of the room, we must know firstly the length and the width.

Example # 3Example # 3

• Draw a flowchart which reflects the process of calculating the sum of 5 values:– Goal: calculate the sum of 5 values.– Input: value – Process: adding the values to each other.– Output: the sum

Page 10: Example # 1 Draw a flowchart for calculating the area of a room: In order to calculate the area of the room, we must know firstly the length and the width.

C code: don’t worry about it now#include<stdio.h>void main(){ int value, sum, counter;

sum = 0;

counter = 1;

while(counter<=5){

scanf("%d",& value);

sum = sum + value;

counter = counter + 1;}

printf("%d",sum);

}

Is Counter

<=5

Is Counter

<=5

STARTSTART

ENDEND

Output sum

Output sum

Input valueInput value

counter = counter + 1counter = counter + 1

sum =sum + valuesum =sum + value

counter = 1counter = 1

Sum = 0Sum = 0

YES NO

Flowchart

Page 11: Example # 1 Draw a flowchart for calculating the area of a room: In order to calculate the area of the room, we must know firstly the length and the width.

Questions?Questions?

• What would happen if the process counter = counter +1 did not exist?

• What would happen if the process sum =0 did not exist?

Page 12: Example # 1 Draw a flowchart for calculating the area of a room: In order to calculate the area of the room, we must know firstly the length and the width.

Example # 4Example # 4

• Draw a flowchart for finding the maximum value of 10 input values.

– Goal: finding the maximum value.– Input: value – Process: comparing to find the maximum value.– Output: the maximum value

Page 13: Example # 1 Draw a flowchart for calculating the area of a room: In order to calculate the area of the room, we must know firstly the length and the width.

C code:don’t worry about it now.#include<stdio.h>void main(){ int value, max, counter;

scanf("%d", & value);max = value;

counter = 1;

while(counter<=10){

scanf("%d", &value);

if(value>max){

max = value;}counter = counter + 1;

}printf("The maximum is %d \n ",max);

}

Is Counter<=10

Is Counter<=10

STARTSTART

ENDEND

Output maxOutput max

Input valueInput value

counter = counter + 1counter = counter + 1

max = valuemax = value

counter = 1counter = 1

max = valuemax = value

Input valueInput value

Is Value>max

Is Value>max

YES

YES

NO

NO

Flowchart


Recommended