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

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...
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...
You are to use your code from part A of this assignment and add to it....
You are to use your code from part A of this assignment and add to it. In this part of the project, you are to do the following: 1. In the count_voters function you are to add code to: • Count the number of votes for Trump • Count the number of votes for Biden • Count the number of females • Count the number of males • Count the number of Democrats • Count the number of Republicans •...
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.
No other code on this website works. Define a function drawCircle. This function should expect a...
No other code on this website works. Define a function drawCircle. This function should expect a Turtle object, the coordinates of the circle’s center point, and the circle’s radius as arguments. The function should draw the specified circle. The algorithm should draw the circle’s circumference by turning 3 degrees and moving a given distance 120 times. Calculate the distance moved with the formula 2.0 × π × radius ÷ 120.0. Define a function main that will draw a circle with...
code in c++ using the code given add a hexadecimal to binary converter and add a...
code in c++ using the code given add a hexadecimal to binary converter and add a binary to hexadecimal converter #include <iostream> #include <string> #include<cmath> #include<string> using namespace std; int main() { string again; do { int userChoice; cout << "Press 2 for Decimal to Binary"<< endl; cout << "Press 1 for Binary to Decimal: "; cin >> userChoice; if (userChoice == 1) { long n; cout << "enter binary number" << endl; cin>>n; int decnum=0, i=0, remainder; while(n!=0) {...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT