Problem Solving Practise Quest Answers-PSP

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Problem solving and programming- Practise problems week 4

Q1)
a) IPO chart

Input Process output


number Count_variable=i table

b) Designing a solution algorithm

Mult_table of 7
1. Set number=7
2. For i=1 to 10
Display result=i*number

End for

3. Display result as table to screen

c) Checking the algorithm

Input data
Number dataset
7

Expected result
result 1*7=7
2*7=14
3*7=21
4*7=28
5*7=35
6*7=41
7*7=49
8*7=56
9*7=63
10*7=70

Testing
Statement number count result output
no
1 7
2 1 7 1*7=7
3 2 14 2*7=14
4 3 21 3*7=21
4 28 4*7=28
3.2 5 35 5*7=35
6 41 6*7=41
7 49 7*7=49
8 56 8*7=56
9 63 9*7=63
10 70 10*7=70

Yes, the expected result for each set of data matches the calculated result.

Q2)

a) IPO chart

Input Process output


number Number
Square
cube

b) Designing a solution algorithm


Calculate_sum_and_cube
1. Prompt integer number
2. Get number
3. Repeat while number=1 to 20
Square=number*number
Cube=number*number*number

End while

4. Display number, square, cube to screen

c) Checking the algorithm


Input data
Input First dataset Second dataset
number 1 2

Expected result
First dataset Second dataset
square 1 4
cube 1 8

Testing
Statement number Square cube
no
First pass
1,2 1
3 1
4 1
5 Output Output output
6 2
7 4
8 8
9 Output Output output

Yes, the expected result for each set of data matches the calculated result.
Q3)

a) IPO chart

Input Process output


Payroll_amt Total_payroll

b) CA table

Condition Action

Payroll_amt<>999 Total_payroll= Total_payroll+payroll_amt

c) Designing a solution algorithm

Calculate_totalpayroll
1. Prompt operator for payroll_amt
2. Get payroll_amt
3. Set Total_payroll=0
4. repeat while payroll_amt not equal to 999
5. Total_payroll= Total_payroll+payroll_amt
6. Get payroll_amt
END while
7. Display total_payroll to the screen
q
d) Checking the algorithm
Input data
Input First Second
dataset dataset
payroll_amt 525 999
Expected result
First Second
dataset dataset
result 525 999

Testing
Statement Payroll_amt Total_payroll
no
First pass
1,2 525
3 0
4
5 525
6 200
7 725
8 999
9 725
10 output
Yes, the expected result for each set of data matches the calculated result.
Q5)

IPO chart

Input Process output


Hour Hour
minute Minute
Format

CA table

Condition Action

If hour<12 Format=”AM”

If hour=12 Format=”AM”

If hour>12 Hour=hour-12
Format=”PM”

Designing a solution algorithm

Convert_timeformat
1. Prompt operator for hour, minute
2. Get hour,minute
3. Repeat While hour=!99 and minute=!99
a. If hour<12
Format=”AM”
b. Else if hour=12
Format=”AM”
c. Else if hour>12
Hour=hour-12
Format=”PM”

End while

4. Display hour, minutes to the screen

Checking the algorithm

Input data
Input First dataset Second dataset
hour 13 10
minute 10 00

Expected result
First dataset Second dataset
hour 01 10
minute 10 00
Format PM AM

Testing
Statement hour minute format
no
First pass
1,2 13 10
3
3a
3b
3c 01 10 PM
4 output Output Output
Second pass
1,2 10 00
3
3a 10 00 AM
4 output Output Output
Yes, the expected result for each set of data matches the calculated result.

You might also like