Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming Logic and Design 5a. Create the logic for a program that performs ar

ID: 3685141 • Letter: P

Question

Programming Logic and Design

5a. Create the logic for a program that performs arithmetic functions. Design the program to contain two numeric variables, and prompt th user for values for the variable. Pass both variables to methods named sum() and diifference(). Create the logic for the methods sum() and difference(); they compute the sum of and difference between the values and two arguments, respectively. Each methos should poerform the appropriate computation and display the results.

5b. Modify the program above in 5a so that the two entered values are passed to a method named getChoice(). The getChoice() method asks the uer whether addition or subtraction should be performed and then passes the two values to the appropriate methiod, where the result is displayed.

Explanation / Answer

PseudoCode with Comments


function getChoice():

# Choice Variables value = 1, if addition else subtraction
Integer Choice
# Take Value of Choice From User
Input Choice;
return Choice;

function print(C):
display C

function sum(A,B):
Integer C = A+B;
print(C)


function difference(A,B):
Integer C = A-B;
print(C)

function main():
# Two Variables A and B of Integer Type
Integer A, B;
# Take Value of A and B From User
Input A
Input B
ch = getChoice();
if (ch == 1)
sum(A,B);
else
difference(A,B)
end

main()