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

Design a function that will display which operations were executed (option K in

ID: 3859093 • Letter: D

Question

Design a function that will display which operations were executed (option K in the menu). For this "extra" part you should indicate where your process does this and provide the "combination" ofexecution operations that resulted in this output (use the summary table to indicate and comments in your code) DISPLAYING FUNCTION EXECUTION Addition Execution Success Subtraction Execution Success Multiplication Execution Success Division Execution Success Execution Success Roots Execution Success Power Percentage Execution Success LCM Execution Success Execution Success GCD Modulus Execution Failure If the function was not executed the status for that function would appear as "Execution Failure". For example, if function Roots and Addition were the only ones not executed. DISPLAYING FUNCTION EXECUTION Addition Execution Failure subtraction Execution Success Multiplication Execution Success Division Execution Success Roots Execution Failure Execution Success Power Percentage Execution Success LCM Execution Success GCD Execution Success Modulus Execution Success

Explanation / Answer

The question can be solved by declaring an array int executed[10], initialise all elements to 0, and do executed[k-1]=1 (assuming the menu starts from k=1) each time a function is executed.

int executed[10];

for( int i=0; i<10; i++) // Initialises all values of the variable to 0 (Hasn't been executed yet)

executed[i]=0;

// Part where you read the option choice, let's say in variable choice

cin >> choice;

execute[choice-1]=1; // When the function is executed, change its state to 1

// At the end when you have to display the output

for( int i=0; i<10; i++ )

{

switch(i)

{

case 0: cout << "Addition - ";

break;

case 1: cout << "Subtraction - ";

break;

// and the list continues upto 10

case 9: cout << "Modulus - ";

}

if( executed[i]==0) // The function has not been used yet, so FAILURE

cout << "Execution Failure ";

else // As executed[i]==1, it means the function has been called, i.e. SUCCESS

cout << "Execution Success ";

}

This way you can solve the problem by declaring an array and changing the corresponding value in the array to 1 when the function is executed. 1 denotes SUCCESS and 0 denotes FAILURE.

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