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...
1. Write an algorithm to calculate the Matrix multiplication (or write with pseudo code) 2. Write...
1. Write an algorithm to calculate the Matrix multiplication (or write with pseudo code) 2. Write an algorithm to calculate the recursive Matrix multiplication (or write with pseudo code) 3. Find the time complexity of your pseudo code and analyze the differences
Write an algorithm in pseudo code to find one element and delete it in a doubly...
Write an algorithm in pseudo code to find one element and delete it in a doubly linked list. Your algorithm will print the original list, request the user to put in an element to be deleted, then print the final list after the deletion is done. If the element doesn’t exist in the list, print "XXX is not in the list" where "XXX" should be the one you received from the user. Use the following as your test cases to...
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. ListList 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...
a) Design in pseudocode an algorithm that gets as input an integer k, and a list...
a) Design in pseudocode an algorithm that gets as input an integer k, and a list of k integers N1, .., Nk, as well as a special value SUM. Your algorithm must locate a pair of values in the list that sum to the value SUM. For example, if your list of values is 3, 8, 13, 2, 17, 18, 10, and the value of SUM is 20, then your algorithm should output "either" the two values 2 and 18,...
/*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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT