Question

1.The following pseudocode algorithm is used to calculate the average of two numbers. Perform a desk...

1.The following pseudocode algorithm is used to calculate the average of two numbers. Perform a desk check on this algorithm assuming the firstValue is 12.5 and the secondValue is 7.5. You should use a table to show your answer.

L1: Program AverageCalculator;

L2: Data firstValue as float;

L3: Data SecondValue as float;

L4: Data average as float;

L5: Output “Enter the first Number”;

L6: Input firstValue;

L7: Output “Enter the second Number”;

L8: Input secondValue;

L9: average = (firstValue+secondValue)/2;

L10: Output “the average is “, average;

L11: End AverageCalculator;

2. Produce a truth table for the following

a) A AND B

b) A OR B

c) (A AND B) OR B

d) NOT ((A AND B) OR B)

3. The table below shows some rules used in a courier company to determine the cost of delivery of a package. The cost of delivery determined by the weight of the package entered by the user.

Weight (Kg) Cost of Delivery ($) per kg
Less than 1 2
1 - 5 3
more than 5 4

Write a pseudocode algorithm that accepts a value for the weight as its input and displays the total cost of delivery for the package its output.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. The following table can be used to desk check the algorithm

firstValue secondValue average
12.5 7.5

This algorithm correctly calculates the average.

2. The Truth Tables are as follows:

a)

A B A AND B
0 0 0
0 1 0
1 0 0
1 1 1

b)

A B A OR B
0 0 0
0 1 1
1 0 1
1 1 1

c)

A B A AND B (A AND B) OR B
0 0 0 0
0 1 0 1
1 0 0 0
1 1 1 1

d)

A B A AND B (A AND B) OR B NOT ((A AND B) OR B)
0 0 0 0 1
0 1 0 1 0
1 0 0 0 1
1 1 1 1 0

3. The required pseudocode is:

costOfDelivery (weight):
if weight <1: return weight*2
else if weight<=5: return weight*3
else if weight>5: return weight*4

Add a comment
Know the answer?
Add Answer to:
1.The following pseudocode algorithm is used to calculate the average of two numbers. Perform a desk...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT