Worksheet #5 - Writing Our Own Functions! 1) Creating a new project and adding a cpp should be easy now! Remember to compile often and to test in pieces. In this worksheet we'll be practicing writing functions to get input and do some computation! We'll be using the quadratic formula to compute the solutions to quadratic equations with some major restrictions, to ensure that our math works and that everything is solvable. A x^2 + B x + C = 0, with A,B,C as integers, A>0 and real roots 2) Write a getInteger function. This function will have a prompt argument and will get an integer from the user. It should prototype looks as follows: int getInteger(string); 3) Write a getIntegerWithMinimum function. This function will have a prompt argument and an integer argument for the minimum. It should protect against user input that is below the given minimum or that fails cin. Its prototype is: int getIntegerWithMinimum(string,int); 3) Inside, main, use your new getIntegerWithMinimum function to read an integer from the user. This integer will be the coefficient "A" in the equation above. All entries for A must be integers greater than 0. 4) Use the getInteger function to get the coefficient "B" from the equation. 5) The next step will be to read in an integer for "C". However, we'd like to ensure that the square root of the quadratic equation will always result in real roots for this particular C. To do this, we must not allow C to be larger than (b*b)/(4*a). To do this, write a new function called getIntegerWithMaximum. This function will take a prompt and a maximum. The internal loop will protect against cin failures and it will make sure that the user inputs an integer greater than the maximum. The prototype would look like this: int getIntegerwithMaximum(string, int); We then call this function in main to get C and pass in: (b*b)/(4*a) for the maximum allowed value for C. This is inclusive. So if this value results in a value of 4, then C is allowed to have a value of 4. 5) Armed with an appropriate A,B and C, we can now compute the two real roots of the equation. We know they must not be imaginary because we've constrained A and C to force things to have real roots. Output the first root: (-b + sqrt(b*b - 4ac) ) / (2a) 6) Then, output the second root: (-b - sqrt(b*b - 4ac) ) / (2a) 7) What are the roots when given the following inputs: 1 4 4 // solutions are -2 and -2 1 -4 4 // solutions are 2 and 2 1 1 0 // solutions are 0 and -1 1 11 30 // solutions are -5 and -6 1 0 -9 // solutions are -3 and 3 8) Test for incorrect inputs: 1 1 1 //this is one of the error situations -1 1 0 //another error situation 0 1 2 //another error situation 1 0 9 //another error situation ----- Final Project Worksheet #5. *** Name your cpp lastname_firstname_finalproject.cpp *** For example, ramsey_doc_finalproject.cpp Move the computation of deltaV into a function. The function should take, ISP, total mass and fuel mass as arguments and should return the deltaV given those parameters. (You may treat gravity as constant, but if you're planning to allow that to be user defined, it should also be an argument.) Optionally, you can write a getString function to get string input from the user. Write a getDoubleWithMinimum function. This function should have a prompt argument as well as a minimum value as an argument. It should prompt the user using the prompt argument, read in a double from the console and then use a while loop to protect against both cin failures and user inputs that are below the minimum value passed in as the argument. Write a getDoubleWithRange function. This function should have a prompt argument as well as both a minimum and maximum value as an argument. It should prompt the user using the prompt argument, read in a double from the console and then use a while loop to protect against both cin failures and user inputs that are below the minimum value or larger than the maximum value passed in. Write a getIntegerWithMinimum function. This function should have a prompt argument as well as a minimum value as an argument. It should prompt the user using the prompt argument, read in an integer from the console and then use a while loop to protect against both cin failures and user inputs that are below the minimum value passed in as the argument. Alter your project to take advantage of these three functions. Use getDoubleWithMinimum to get the ISP, and total mass. Use getDoubleWithRange to get the fuel mass. *** New Step *** Use getIntegerwithMinimum to ask the user how many stages their rocket will contain. (Users must have at least 1 stage, but you could consider allowing 0 here to skip the staging calculations altogether if you'd like). **************** With this value, write a for loop that allows the user to do this entry the user defined number of times. Each time through the loop will end up corresponding to a different stage of a rocket. Each stage has its own name, ISP, fuel mass and total mass. Use the deltaV function to compute the deltaV of each stage. Outside the stages for loop, use getDoubleWithMinimum to read in a payload mass, ISP and target dV. Given these, use a loop (from worksheet4) to compute the required fuel mass to reach the target dV with this ISP and payload. Use the new dV function in this loop! Lastly, write a while loop to allow the user to do it all again. (So if the user wants to do this again, they will enter all the values three more times). -craft name ex: Challenger -total mass ex: 1995806.42 -fuel mass ex: 1671487.88 -ISP ex: 269.1 -gravity a constant value at 9.80665 -dV ex: 4300.2 -target dV ex: 6500.0 -payload mass ex: 27500.1 dV = gravity * ISP * ln ( total_mass / ( total_mass - fuel_mass ) ) Remember, payload mass, total mass, fuel mass, target dV, and ISP can never be below 0. Also, total mass must be larger than fuel mass. Write down any assumptions or decisions you make when you complete this process.