Ask Computer Engineering Expert

The Quadratic Formula

In this homework you will be writing a program that finds the roots and vertex of the graph that corresponds to a quadratic equation given its coefficients.

Problem Statement:

This program will prompt the user for three integers and return the roots (as doubles) of the quadratic equation corresponding to those coefficients. In addition, the program will find and print out the x and y coordinates of the vertex of the parabola represented by the quadratic equation.

Learning Objectives

  • Integer arithmetic
  • Translating equations to valid C++ code
  • Use of library functions
  • Formatting numerical output (setprecision)

Quadratic Equations:

Quadratic equations are in the form y = ax2 + bx + c and form a parabola when graphed. For example, this is a graph of the quadratic equation y = x2 - 2x - 2:

For this assignment we have three points of interest: the two points where the graph intersects the xaxis (called the roots of the equation) and the vertex (the "bottom" point of the graph).

PART I:

The Quadratic Formula

The quadratic formula is a way to solve for the roots of equations of the form ax2 + bx + c = 0, where a, b and c are integer coefficients. The formula is as follows:

x = -5 ± √b2 - 4 * a* c/ 2 * a

or the 2 equations

Root1 = -b + √b2 - 4 * a * c/ 2 * a

Root2 = -b - √b2 - 4 * a * c/ 2 * a

These 2 equations are heart of the program you need to write.

For example, the equation x2 + 5x + 6 = 0 has the coefficients 1, 5 and 6 (corresponding to a, b and c respectively) which can be plugged into the quadratic formula:

x = -5 ± √52 - 4 * 1* 6/2 * 1

This results in two equations (one for each of the two roots). After completing the arithmetic the two roots are:

x1 = -5 - √52 - 4 * 1 * 6/2 * 1 = -2

x2 = -5 - √52 - 4 * 1 * 6/2 * 1 = -3

Note: Root1 should be the result of the equation that contains the addition ( -b + ...) and Root2 should be the result of the equation that contains the subtraction ( -b - ...).

Note: For those of you who know this might be a problem... For this assignment, the test cases in webcat will not include any inputs that would result in imaginary roots, so you do not need to worry about them in your solution. Assume all inputs will result in real roots.

Code

With the information above you should be able to write the code for Part 1 of the assignment. Make sure to match the format shown in the example output EXACTLY. Start by writing code to prompt the user for a, b and c. Then write the code that plugs those three values into the quadratic formulas. Finally, print the result out (the two roots of the equation).

Sample Output: Your program will be tested with several input sets, including the one shown here in RED. Your program must exactly match the words and format in this example. (Please copy and paste the text from these prompts into your code!

Please enter a, b and c: 1 -1 -2

Root1: 2.00

Root2: -1.00

Please enter a, b and c: 6 11 -35

Root1: 1.67

Root2: -3.50

Set Precision:

If you look at the output you'll notice that all of the answers have two decimal places. In your solution, the output should also always be formatted to exactly two decimal places. This can be achieved by using the function setprecision(). If you have not already done so, add this to your solution.

PART II:

Finding the vertex of the parabola

To find the vertex of a parabola represented by a quadratic equation there are two steps: find the xcoordinate and then the y-coordinate.

Finding the x-coordinate of a vertex

There is a simple formula for finding the x-coordinate of a parabola given the coefficents of the quadratic equation that describes it:

x = -b/2 * a

Plug in the "b" and the "a" that you used before to get the Root1 and Root2 answers

Finding the y-coordinate of a vertex

To get the y-coordinate of the parabola simply plug in the answer you got for the x-coordinate to the quadratic equation. For example, using the same a, b and c as up above (1,5 and 6). The x-coordinate would be:

x = -5/2 * 1 = 2.5

Remember that the original equation was x2 + 5x + 6. So when we plug in the x-coordinate to the equation we get:

y = (x)2 + 5 * (x) + 6

y = (-2.5)2 + 5 * (-2.5) + 6 = -0.25

Code

Using the information given above you should now be able to write the code for part 2. Start by finding the x coordinate and storing it in a variable (should be a double). Then use that variable to find the y coordinate. Finally print out the x and y coordinates in the format shown below. Here is an example of a full run of your program after part 2 has been completed:

Please enter a, b and c: 2 3 -4

Root1: 0.85

Root2: -2.35

Vertex Coordinates (x, y): (-0.75, -5.13)

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91409105
  • Price:- $80

Priced at Now at $80, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As