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

5 6 a. the logic for a program that performs arithmetic functions. Design the Cr

ID: 3865152 • Letter: 5

Question

5 6 a. the logic for a program that performs arithmetic functions. Design the Create program to contain two numeric variables, and prompt the user for values for the variables. Pass both variables to methods named sumo and difference C). Create the logic for the methods sumo and they compute the sum of and difference between the values of two arguments, respectively. Each method should perform the appropriate computation and display the results. b. Modify the program in Exercise 5a so that the two entered values are passed to a method named getChoiceO. The getChoiceo method asks the user whether addition or subtraction should be performed and then passes the two values to the appropriate method, where the result is displaye

Explanation / Answer

Solution:
5. a)

Start
declaration
num myNum1=0
num myNum2=0
num myArg1=0
num myArg2=0
num sum= sum(myNum1, myNum2);
num difference= difference(myArg1, myArg2);
output sum, difference
num sum (myNum1, myNum2)
{
num sum= myNum1+myNum2 //Numbers are added here
return sum;
}
num difference (myArg1, myArg2)
{
num difference= myArg1+myArg2 //Numbers are subtracted here
return difference;
}
5.b)
Start
declaration{
num myNum1=0
num myNum2=0
num myArg1=0
num myArg2=0
choice= getChoice();
if(choice) //Since 1 was inserted for addition and the condition in this case will be true
num sum= sum(myNum1, myNum2);
else
num difference= difference(myArg1, myArg2);
output sum, difference}
getChoice()
print Input 1 for addition and 0 for subtraction
num choice= input(); //set the input value to choice
return Choice;
num sum (myNum1, myNum2)
{
num sum= myNum1+myNum2 //Numbers are added here
return sum;
}
num difference (myArg1, myArg2)
{
num difference= myArg1+myArg2 //Numbers are subtracted here
return difference;
}
I hope this helps. Don't forget to give a thumbs up if you like this.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote