Question

In: Computer Science

*Please give the answers in pseudo code 1) Design an algorithm that will receive two integer...

*Please give the answers in pseudo code

1) Design an algorithm that will receive two integer items from a terminal operator, and display to the screen their sum, difference, product and quotient. Note that the quotient calculation (first integer divided by second integer) is only to be performed if the second integer does not equal zero.


2) Design an algorithm that will read two numbers and an integer code from the screen. The value of the integer code should be 1, 2, 3 or 4. If the value of the code is 1, compute the sum of the two numbers. If the code is 2, compute the difference (first minus second). If the code is 3, compute the product of the two numbers. If the code is 4, and the second number is not zero, compute the quotient (first divided by second). If the code is not equal to 1, 2, 3 or 4, display an error message. The program is then to display the two numbers, the integer code and the computed result to the screen.


3) Design an algorithm that will receive the weight of a parcel and determine the delivery charge for that parcel. Charges are calculated as follows:
Parcel weight (kg)
Cost per kg ($)
<2.5
$3.50 per kg
2.5-5 kg
$2.85 per kg
>5 kg
$2.45 per kg

Solutions

Expert Solution

#Here's the python psedu code for the question

1)

# Take inputs

int1 = raw_input("Enter first number:")

int2 = raw_input("Enter second number:")

# Try summing the inputs; if inputs are not numbers the program will throw error saying the input are not numbers

try:

   sum = int(int1) + int(int2)

except:

   print ("Enter valid integer inputs")

# Print output sum

print("Sum:" + str(sum_no))

# Now repeat the same block for subtraction and multiplication

# For division check if the denominator is zero or not with if-else condition

if (int(int2) == 0):

   print("Denominator for division is zero, division cant be performed)

else:

print ("Division:" + str(int(int1)/int(int2))

2 )

#The answer to second question is similar to the first only with the difference that now you are giving option to user what operation he has to perform instead of printing out all the operations. This can be accomplished by a simple if-else statements.

#So after taking inputs from raw_input function of python check what is the input given like :

if(int(input1) == 1):

# perform addition like in the first part

elif (int(input1) ==2):

#perform subtraction

elif( int(input1) == 3):

#perform multiplication

elif (int(input1) == 4):

#perform division with a non-zero check on denominator

else:

print("Non-valid input given")

3)

# Take input weight

weight = raw_input("Enter weight in kg:")

# calculate cost with simple if-elif-else blocks by multiplying the input weight with cost per kg

if( float(weight) < 2.5):

cost = float(weight) * 3.5

print ("Cost in dollars:" + str(cost))

elif( float(weight) >= 2.5 and float(weight) < 5):

cost = float(weight) * 2.85

print ("Cost in dollars:" + str(cost))

# Like-wise take decision about cost per kg multiplier based on the range of the input


Related Solutions

In pseudo-code, design an algorithm for finding baking a cake.
In pseudo-code, design an algorithm for finding baking a cake.
Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java...
Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java program.
Write a pseudo code for an O (n7log3n) algorithm. Please write in C++.
Write a pseudo code for an O (n7log3n) algorithm. Please write in C++.
Please post all code in Pseudo code. Please post ORIGINAL answers do not copy from similar...
Please post all code in Pseudo code. Please post ORIGINAL answers do not copy from similar questions. Please post in a format that can be directly copied. Reasoning on answers would be most helpful but not required. Thank you in advance for your help. 1. List the following functions according to their order of growth from the lowest to the highest: (n−2)!, 5lg(n+100)10, 22n, 0.001n4 +3n3 +1, ln2 n, √3 n, 3n. 2. The range of afinite nonempty set of...
Write a recursive algorithm in pseudo-code to compute the “power list” of a given list of...
Write a recursive algorithm in pseudo-code to compute the “power list” of a given list of integers. Assume that the List type has members: int List.length returns the length of the list. void List.push(T n) pushes an element n to the front of the list T List.pop() pops an element from the front of the list. List$$ List$$.concat(List$$ other) returns the concatenation of this list with other. Explain in plain English the reasoning behind your algorithm. Power Lists should be...
/*Design and code and test a class MaxMin that has the following properties * two integer...
/*Design and code and test a class MaxMin that has the following properties * two integer member variables, min and max where min is smaller or equal than max at all times * A default constructor that sets both min and max to 0 * A constructor that accepts one integer and sets both min and max to that integer * A constructor that accepts two integers and sets min the smallest and max the largest * * Setters and...
(a) Design an algorithm that reveals some secret integer number from the set {1, 2, ......
(a) Design an algorithm that reveals some secret integer number from the set {1, 2, ... , n} by guessing random numbers within the given range until the secret number has been guessed. Numbers should be replaced after being guessed such that ​it is possible to guess 2 and then 2 again​, assuming 2 is in the given range. The algorithm should return both the secret number as well as the number of guesses taken. (b) If possible, calculate the...
Describe in pseudo-code, a linear-time algorithm for reversing a queue Q. To access the queue, you...
Describe in pseudo-code, a linear-time algorithm for reversing a queue Q. To access the queue, you are only allowed to use the basic functions of the queue ADT defined as follows (Hint: Using a stack, the basic stack functions defined in the textbook and in the class). class Queue { public: int size(); bool isEmpty(); Object front(); void enqueue(Object o); Object dequeue(); };
Give the algorithms in pseudo code of the enqueue and dequeue procedures. Constraint: the structure implementing...
Give the algorithms in pseudo code of the enqueue and dequeue procedures. Constraint: the structure implementing the queue must only be pointed to by a single field (example: head, tail or number of elements, etc.)
Design in pseudo code a multiple recursive version of Tetranacci calculators. Tetranacci numbers are a more...
Design in pseudo code a multiple recursive version of Tetranacci calculators. Tetranacci numbers are a more general version of Fibonacci numbers and start with four predetermined terms, each term afterwards being the sum of the preceding four terms. The first few Tetranacci numbers are: 0, 0, 0, 1, 1, 2, 4, 8, 15, 29, 56, 108, 208, 401, 773, 1490, …
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT