Question

In: Computer Science

Modify the original code and add an additional function of your choice. The function should be...

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

Solutions

Expert Solution

#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.


Related Solutions

MODIFY your code to: add a new point, locationx, that has 3 dimensions, and are set...
MODIFY your code to: add a new point, locationx, that has 3 dimensions, and are set by PASSING IN the arguments for the X and Y coordinates. The Z coordinate can be hard-coded (extra credit if it is passed in too). ADD CODE to print the new point location, and note to the user it is the new point using input arguments Add 2 new methods to the Point3d class, each accepting 3 values as input. pAdd(a1, a2, a3) will...
JAVA programming language Please add or modify base on the given code Adding functionality Add functionality...
JAVA programming language Please add or modify base on the given code Adding functionality Add functionality for multiplication (*) Adding JUnit tests Add one appropriately-named method to test some valid values for tryParseInt You will use an assertEquals You'll check that tryParseInt returns the expected value The values to test: "-2" "-1" "0" "1" "2" Hint: You will need to cast the return value from tryParseInt to an int e.g., (int) ValidationHelper.tryParseInt("1") Add one appropriately-named method to test some invalid...
The following is the original code, (add, t1, 3, 5) (assign, a, t1) (add, t2, 3,...
The following is the original code, (add, t1, 3, 5) (assign, a, t1) (add, t2, 3, 5) (sub, t3, t2, z) (assign, b, t3) Constant folding is applied to give the following, (assign, t1, 8) (assign, a, t1) (assign, t2, 8) (sub, t3, t2, z) (assign, b, t3) After the constant folding is applied, the (assign, t2, 8) becomes redundant. What optimizations should take place in order to remove this redundancy in the constant folded code? Also show the optimized...
Modify the code below to support specifying additional dice type in addition to a 6 sided...
Modify the code below to support specifying additional dice type in addition to a 6 sided dice. For example, the program could support six-sided, eight-sided, 10 sided die. HINTS: You will need to Create an enum type for the dice type and values Modify the parameter passing of some of the functions to pass the die type Adjust the actual code that simulates the die roll to generate a range of values appropriate to the user's selected die type. Think...
Modify the DetailedClockPane.java class in your detailed clock program, to add animation to this class. Be...
Modify the DetailedClockPane.java class in your detailed clock program, to add animation to this class. Be sure to include start() and stop() methods to start and stop the clock, respectively.Then write a program that lets the user control the clock with the start and stop buttons.
When preparing a budget to buy a new home, you should add an additional ____ percent...
When preparing a budget to buy a new home, you should add an additional ____ percent to the monthly payment on the loan for such things as homeowner's insurance, property taxes, maintenance, and upkeep.
make multiply function with ‘add’ command, Convert to mips code Don’t use ‘mult’ Use 'add' multiple...
make multiply function with ‘add’ command, Convert to mips code Don’t use ‘mult’ Use 'add' multiple times Get input from key-board and display the result in the console window
2. Specification - Given the following code base, add the appropriate function that will give the...
2. Specification - Given the following code base, add the appropriate function that will give the correct results/output. CODE: # TODO : Add Two Missing Functions HERE mlist = [(" Orange ", 10 , 0.25) ,( " Apple ", 5 , .20) , (" Banana ", 2 , 0.3) ,(" Kiwi ", 1 , 0.5)] addFruit (10 ," Lemon " ,0.1) displayFruitList ( mlist ) OUTPUT: Orange --- $ 2.50 Apple --- $ 1.00 Banana --- $ 0.60 Kiwi ---...
in java code Modify your program as follows: Ask the user for the number of hours...
in java code Modify your program as follows: Ask the user for the number of hours worked in a week and the number of dependents as input, and then print out the same information as in the initial payroll assignment. Perform input validation to make sure the numbers entered by the user are reasonable (non-negative, not unusually large, etc). Let the calculations repeat for several employees until the user wishes to quit the program. Remember: Use variables or named constants...
Write a Matlab function called: lin_interp. The function should have three inputs: the two original data...
Write a Matlab function called: lin_interp. The function should have three inputs: the two original data arrays (call them x and f), and the array you would like to interpolate to (call it xstar). The function should have one output: the interpolated array ( call it fstar). The function should be able to interpolate x and f onto xstar using linear interpolation and give the result as fstar. The function may not use any intrinsic functions except length.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT