Question
This program will prompt the user to perform one of two functions. // It will then prompt the user for a number to use for
This program will prompt the user to perform one of two functions. // It will then prompt the user for a number to use for that function // and display the results of the function
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#include #include
// display Menu function -----------------------------
void printMenu () {
printf (" Select which function to perform ");
printf (" a: Square(x) = x*x ");
printf (" b: Cube(x) = x*x*x ");
printf (" q: quit ");
}
// Square a number function -----------------------------
int Square(int inum) {
int iresults;
iresults = inum*inum;
printf (" Square(%d) = %d^2 = %d ", inum, inum, iresults);
return(iresults);
} // end function Square // Cube a number function -----------------------------
float Cube(float xnum) {
float xresults;
xresults = xnum*xnum*xnum;
printf (" Cube(%.2f) = %.2f^3 = %.2f ", xnum, xnum, xresults);
return(xresults);
} // end function Cube
// Main Program ---------------------------------------------
int main() {
char selection;
int iinum, iiresults;
float xxnum, xxresults;
bool moreCal;
moreCal = true;
while (moreCal) {
// display the menu
printMenu ();
printf (" : "); //
Prompt for menu operation
scanf (" %c", &selection);
if (selection == 'q'|| selection == 'Q'){ // Perform operation based on user selection moreCal = false;
} else if (selection == 'a' || selection == 'A') {
printf (" Enter an integer number : ");
scanf ("%d", &iinum);
iiresults = Square(iinum);
} else if (selection == 'b' || selection == 'B') {
printf (" Enter a number: ");
scanf ("%f", &xxnum);
xxresults = Cube(xxnum);
} else { printf (" *** Invalid input *** ");
} //end if
} //end while(moreCal)
printf (" ... bye ...thanks for using my program ");
return 0;
} // end main
1. Modify the original code and a new function called Welcome that displays a welcome message should be created. Add another function called MyName that displays any Name,Class,Section no., and Date. Support the experimentation with screen captures of executing the new code.
2. Modify the code and using the Square and Cube functions as models, a new function named Divide7 that will take an Integer input and returns a Float value of the input Integer divided by 7 should be created? Take care when the function is prototyped. "Pay attention to the datatypes". Add this as menu option "C" to the program to execute this function. Also include in menu option C, the same style as the first options. Make sure the datatypes are correct for the variables. Support the experimentation with screen captures of executing the new code.
3. Modify the code again and new function by choice should be created. This function should be unique and something created for this assignment. Add this as menu option D to the program to execute this function. The new function should have at least one argument input and return a calculated value to the main. Support the experimentation with screen captures of executing the new code.
4. Modify the main program so that it adds 1000 to the output from the functions and displays the new results. Support the experimentation with screen captures of executing the new code. Submit code as a separate .txt (or .c ) file that includes all four menu options.
5. A new test table with at least 3 distinct test cases listing input and expected output for the code that was created after step 2,3,and 4 should be created. Remember - one test case is one complete execution of the program.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started