In: Computer Science
Modify the original code and add an additional function of your choice. The function should be unique and something you created for this assignment. Support your experimentation with screen captures of executing the new code. Prepare a test table with at least 3 distinct test cases listing input and expected output for your unique function.
#include <stdio.h>
void printHelp () {
printf ("\n");
printf ("a: a(x) = x*x\n");
printf ("b: b(x) = x*x*x\n");
printf ("c: c(x) = x^2 + 2*x + 7\n");
printf ("q: quit\n");
}
void a(float x) {
float v = x*x;
printf (" a(%.2f) = %.2f^2 = %.2f\n", x, x, v);
} // end function a
void b(float x) {
float v = x*x*x;
printf (" b(%.2f) = %.2f^3 = %.2f\n", x, x, v);
} // end function b
void c(float x) {
float v = x*x + 2*x + 7;
printf (" c(%.2f) = %.2f^2 + 2*%.2f + 7 = %.2f\n",
x, x, x, v);
} // end function c
int menu () {
char selection;
float x;
printHelp ();
scanf ("%s", &selection);
if (selection == 'q') return 1;
scanf ("%f", &x);
if (selection == 'a') a(x);
if (selection == 'b') b(x);
if (selection == 'c') c(x);
return 0;
} // end function menu
int main() {
while (menu() == 0);
printf ("... bye ...\n");
return 0;
} // end main
#include <stdio.h> void printHelp () { printf ("\n"); printf ("a: a(x) = x*x\n"); printf ("b: b(x) = x*x*x\n"); printf ("c: c(x) = x^2 + 2*x + 7\n"); printf ("d: c(x) = 2*x^2 - 2*x\n"); printf ("q: quit\n"); } void a(float x) { float v = x*x; printf (" a(%.2f) = %.2f^2 = %.2f\n", x, x, v); } // end function a void b(float x) { float v = x*x*x; printf (" b(%.2f) = %.2f^3 = %.2f\n", x, x, v); } // end function b void c(float x) { float v = x*x + 2*x + 7; printf (" c(%.2f) = %.2f^2 + 2*%.2f + 7 = %.2f\n", x, x, x, v); } // end function c void d(float x) { float v = 2*x*x - 2*x; printf (" d(%.2f) = 2*%.2f^2 - 2*%.2f = %.2f\n", x, x, x, v); } // end function d int menu () { char selection; float x; printHelp (); scanf ("%s", &selection); if (selection == 'q') return 1; scanf ("%f", &x); if (selection == 'a') a(x); if (selection == 'b') b(x); if (selection == 'c') c(x); if (selection == 'd') d(x); return 0; } // end function menu int main() { while (menu() == 0); printf ("... bye ...\n"); return 0; } // end main
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.