0% found this document useful (0 votes)
13 views13 pages

TOPIC 3 - Flowchart and Algorithm

The document is a workbook for an Introduction to Computer Programming course, focusing on algorithms and flowcharts for various exercises. It includes exercises on calculating the friction coefficient, liquid volume in a tank, coffee temperature changes, vapor pressure of water, energy required to heat gases, and selecting dust collectors. Each exercise requires the formulation of algorithms and flowcharts to solve specific problems using given formulas and conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views13 pages

TOPIC 3 - Flowchart and Algorithm

The document is a workbook for an Introduction to Computer Programming course, focusing on algorithms and flowcharts for various exercises. It includes exercises on calculating the friction coefficient, liquid volume in a tank, coffee temperature changes, vapor pressure of water, energy required to heat gases, and selecting dust collectors. Each exercise requires the formulation of algorithms and flowcharts to solve specific problems using given formulas and conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

WORKBOOK INTRODUCTION TO COMPUTER PROGRAMMING 20192020-1

Prepared by NAY
TOPIC 3: FLOWCHART AND ALGORITHM
Exercise 1

Data of an experiment to measure the friction coefficient, Fc of a surface is shown


in Table 1. When the force F required to move a mass m is known, the coefficient
of friction can calculated by:

Fc = F / (m x g) where g = 9.81 m/s2

Formulate appropriate algorithm and flowchart to determine the friction coefficient


in each test, and the average value from all tests.

Table 1: Force at different mass

Test 1 2 3 4 5 6
Mass, m (kg) 2 4 5 10 20 50
Force, F (N) 12.5 23.5 30 61 117 294

Input: Process: Decision? Calculation?

Output:

1
WORKBOOK INTRODUCTION TO COMPUTER PROGRAMMING 20192020-1
Prepared by NAY
Algorithm: Flowchart:

2
WORKBOOK INTRODUCTION TO COMPUTER PROGRAMMING 20192020-1
Prepared by NAY
Exercise 2

Figure 1 shows a cylindrical tank with a conical base. If the liquid level is quite
low, in the conical part, the volume is simply the conical volume of liquid. If the
liquid level is midrange in the cylindrical part, the total volume of liquid includes
the filled conical part and the partially filled cylindrical part.

Formulate algorithm and flowchart of decisional structures to compute the volume


of the liquid in the tank as a function of given values of R and d. Design the
algorithm so that it returns the volume for all cases where the depth is less than
3R. Return an error message if d > 3R.

Volume of liquid in the cylinder:

𝑉𝑉 = 𝜋𝜋𝑅𝑅 2 (𝑑𝑑 − 𝑅𝑅)

Volume of liquid in the conical base:

1 3
𝑉𝑉 = 𝜋𝜋𝑅𝑅
3
1
𝑉𝑉 = 3 𝜋𝜋𝑑𝑑3 if d < R

Input: Process: Decision? Calculation?

Output

3
WORKBOOK INTRODUCTION TO COMPUTER PROGRAMMING 20192020-1
Prepared by NAY
Algorithm: Flowchart:

4
WORKBOOK INTRODUCTION TO COMPUTER PROGRAMMING 20192020-1
Prepared by NAY
Exercise 6

Initially, the temperature of a cup of coffee is very hot. The initial temperature is 75oC.
The temperature of coffee will be dropped by time. The temperature drop for every 2
minutes can be estimated by the following equation

𝑇𝑇𝑛𝑛𝑛𝑛𝑛𝑛 = 𝑇𝑇𝑜𝑜𝑜𝑜𝑜𝑜 − 2𝑘𝑘 (𝑇𝑇𝑜𝑜𝑜𝑜𝑜𝑜 – 𝑇𝑇𝑎𝑎 )

where Tnew is the new temperature, Told is the previous temperature, Ta is the ambient
temperature, 20oC and k is the proportional constant, 0.02. Develop an algorithm and
flowchart to estimate the temperature of the coffee for every 2 minutes until Tnew<25oC.
The expected output is the final temperature and time taken to reach that temperature as
shown in Figure 1.

Figure 1: Expected results

Input: Process:

Output:

5
WORKBOOK INTRODUCTION TO COMPUTER PROGRAMMING 20192020-1
Prepared by NAY

6
WORKBOOK INTRODUCTION TO COMPUTER PROGRAMMING 20192020-1
Prepared by NAY
Exercise 3

Water is placed in a closed container that can hold a maximum pressure (Pomax)
of 1000 mmHg. The initial conditions of water are 25 oC and 23.6 mmHg. Then,
water is heated to until it can reach the maximum pressure. The vapor pressure
of water can be calculated using the Antoine equation below:

𝐵𝐵
𝑃𝑃𝑜𝑜 (𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚) = exp �𝐴𝐴 − �
𝑇𝑇(𝐾𝐾) + 𝐶𝐶

Where T is any given temperature in Kelvin and A, B, and C are Antoine


coefficients: A=18.3036, B=3816.44, C= - 46.13

Formulate algorithm and flowchart of loop structures to compute the partial


pressure of water at different temperature by assuming a reasonable
increasing in temperature. Design the algorithm so that it returns the partial
pressure at different temperature where the pressure is less than maximum
pressure. Return a warning message if Po > Pomax and display the final
temperature.

Input: Process: Calculation? Decision?

Output:

7
WORKBOOK INTRODUCTION TO COMPUTER PROGRAMMING 20192020-1
Prepared by NAY

Algorithm: Flowchart:

8
WORKBOOK INTRODUCTION TO COMPUTER PROGRAMMING 20192020-1
Prepared by NAY
Exercise 5

A 300g unknown gas stored in a closed vessel. The gas was heated by heating
element to raise the temperature of the gas from T1=30oC to T2=80oC. Energy
required, Q to raise the temperature can be calculated using Equation 1.

𝑄𝑄 = 𝑚𝑚[𝑎𝑎 + 2𝑏𝑏(𝑇𝑇2 − 𝑇𝑇1 ) + 3𝑐𝑐(𝑇𝑇2 − 𝑇𝑇1 )2 ] (1)


where a, b, and c are the coefficients for four different gases and as given in Table
1.

Table 1: Coefficients for four gases


Gas a b c
Sulfur Dioxide 3.904 × 10-2 -3.105 × 10-5 8.606 × 10-9
Sulfur Trioxide 9.188 × 10-2 -8.540 × 10-5 32.40 × 10-9
Oxygen 1.158 × 10 -2
-0.6076 × 10-5 1.311 × 10-9
Nitrogen 0.2199 × 10-2 -0.5723 × 10-5 -2.871 × 10-9

Write an algorithm and flowchart for decision making to compute the energy
required to raise the temperature for each case with different gases as listed in
Table 1. Design the algorithm that gives energy value as output. Return a warning
message if gas other than listed in Table 1 is selected.

Input: Decision:

Output:

9
WORKBOOK INTRODUCTION TO COMPUTER PROGRAMMING 20192020-1
Prepared by NAY
Exercise 4

Company Z need to by equipment called dust collector. There are four types of
dust collectors, which are based on gas flowrate. Gas flowrate and purchase cost
for each type of dust collector is given in Table 3.1.

Table 3.1 Cost for each type of dust collector

Type of Gas Purchase cost, Cp (USD)


dust flowrate, FG
collector (ft3/minute)
Cyclones 200 – 𝐶𝐶𝐶𝐶 = exp [9.2227 − 0.7892 (ln(𝐹𝐹𝐺𝐺 ) + 0.08487 ln(𝐹𝐹𝐺𝐺 ))]2
100,000
Venturi 2,000 – 𝐶𝐶𝐶𝐶 = exp [9.6155 − 0.3281 (ln(𝐹𝐹𝐺𝐺 ) + 0.0500 ln(𝐹𝐹𝐺𝐺 ))]2
scrubbers 20,000
Bag filters 5,000 – 𝐶𝐶𝐶𝐶 = exp [10.258 − 0.4381(ln(𝐹𝐹𝐺𝐺 ) + 0.05563 ln(𝐹𝐹𝐺𝐺 ))]2
200,000

Develop an algorithm and flowchart to select type of dust collector and calculate
the purchase cost using decision structured programming. The example of output
from the program is given in Figure 1

Figure 1: The expected output

Input: Decision:

Output:

10
WORKBOOK INTRODUCTION TO COMPUTER PROGRAMMING 20192020-1
Prepared by NAY

Algorithm: Flowchart:

11
WORKBOOK INTRODUCTION TO COMPUTER PROGRAMMING 20192020-1
Prepared by NAY

Answer – Exercise 2

Solution 1

1. Start Start
2. Input d, R
3. Check if 0 < 𝑑𝑑 ≤ 𝑅𝑅, if yes go to _6___, else Input
4. Check if 𝑅𝑅 < 𝑑𝑑 ≤ 3𝑅𝑅, if yes go to _7__, else d,R
5. Print Error Message, then go to__9__.
1 Yes
6. Calculate 𝑉𝑉 = 𝜋𝜋𝑑𝑑3 , then go to _8___ 1
3 0 < 𝑑𝑑 ≤ 𝑅𝑅 𝑉𝑉 = 𝜋𝜋𝑑𝑑3
1 3
7. Calculate 𝑉𝑉 = 𝜋𝜋𝑅𝑅 3 + 𝜋𝜋𝑅𝑅 2 (𝑑𝑑 − 𝑅𝑅), then go
3 No
to _8__ Yes
8. Print volume, V 1
𝑅𝑅 < 𝑑𝑑 ≤ 3𝑅𝑅 𝑉𝑉 = 𝜋𝜋𝑅𝑅3 + 𝜋𝜋𝑅𝑅2 (𝑑𝑑 − 𝑅𝑅)
3
9. End
No
Display
“Error” Print
V

End

Solution 2

1. Start Start
2. Input d, R
3. Check if 𝑑𝑑 ≥ 3𝑅𝑅 & 𝑑𝑑 < 0, if yes go to 7_, else Input
4. Check if 𝑅𝑅 < 𝑑𝑑 ≤ 3𝑅𝑅, if yes go to _6_, else d,R
1
5. Calculate 𝑉𝑉 = 𝜋𝜋𝑑𝑑3 , then go to _8_
3
1 Yes Display
6. Calculate 𝑉𝑉 = 𝜋𝜋𝑅𝑅 3 + 𝜋𝜋𝑅𝑅 2 (𝑑𝑑 − 𝑅𝑅), then go 𝑑𝑑 ≥ 3𝑅𝑅, 𝑑𝑑 < 0
3 “Error”
to _8_ No
7. Print Error Message, then go to_9_. Yes
1
8. Print volume, V 𝑅𝑅 < 𝑑𝑑 ≤ 3𝑅𝑅 𝑉𝑉 = 𝜋𝜋𝑅𝑅3 + 𝜋𝜋𝑅𝑅2 (𝑑𝑑 − 𝑅𝑅)
3
9. End
No
1
𝑉𝑉 = 𝜋𝜋𝑑𝑑 3
3

Print
V

End

12
WORKBOOK INTRODUCTION TO COMPUTER PROGRAMMING 20192020-1
Prepared by NAY
Solution 3

1. Start Start
2. Input d, R
3. Check if 𝑅𝑅 < 𝑑𝑑 ≤ 3𝑅𝑅, if yes go to _6_, else Input
4. Check if 0 < 𝑑𝑑 ≤ 𝑅𝑅, if yes go to _7__, else d,R
5. Print Error Message, then go to__9__.
1 Yes
6. Calculate 𝑉𝑉 = 𝜋𝜋𝑅𝑅 3 + 𝜋𝜋𝑅𝑅 2 (𝑑𝑑 − 𝑅𝑅), then 𝑅𝑅 < 𝑑𝑑 ≤ 3𝑅𝑅
1
𝑉𝑉 = 𝜋𝜋𝑅𝑅3 + 𝜋𝜋𝑅𝑅2 (𝑑𝑑 − 𝑅𝑅)
3
3
go to _8__
1 No
7. Calculate 𝑉𝑉 = 𝜋𝜋𝑑𝑑3 , then go to _8___
3 Yes
8. Print volume, V 1
0 < 𝑑𝑑 ≤ 𝑅𝑅 𝑉𝑉 = 𝜋𝜋𝑑𝑑 3
3
9. End
No
Display
“Error” Print
V

End

13

You might also like