Problem regarding the quadratic formula

Assignment Help Computer Engineering
Reference no: EM13839284

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)

Reference no: EM13839284

Questions Cloud

How many extra bits per second does the sender send : In a digital transmission, the sender clock is 0.2 percent faster than the receiver clock. How many extra bits per second does the sender send if the data rate is 1 Mbps?
Analyse and evaluate risks and security concerns : Analyse and evaluate risks and security concerns with cloud computing discuss strategies for addressing them
What microorganism causes disease : What microorganism causes this disease. What is your best diagnosis of this case. What features are critical to your diagnosis. What further steps should be taken to clear up the problem
What existing information might need to be reviewed : Explain why you think it is necessary to constantly look for ways to improve cost management? What existing information might need to be reviewed, analysed and improved?
Problem regarding 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.
Which design strategy would you recommend : Assume that you are developing a new system for a local real estate agency. The agency wants to keep a database of its own property listing and also wants to have access to the city wide multiple listing service used by all real estate agency. Which ..
Analyse the dataset that has the two variables : Data sets and analysis ?the datasets are given in the feedback of a moodle quiz, this will give different students different numbers. What is the variable on the y axis - what is a suitable title for the graph and If the turnitin match is high can ..
Discuss why ethical writing and research : Discuss why ethical writing and research is important to the Criminal Justice discipline. Be creative with your answer. 500Word response 2 cited sources
What production issues are not included in the data : Monczka-Trent has two options: (1) its standard 2-day shipment or (2) a subcontractor who will team drive overnight with an effective delivery of 1 day. The extra driver costs $175. Handfields's holding cost is 35% annually for this kind of inventory..

Reviews

Write a Review

Computer Engineering Questions & Answers

  New orleans continues to suffer the aftermath of hurricane

new orleans continues to suffer the aftermath of hurricane katrina. the city has recently been experiencing a wave of

  Why captured in organizational standards

Discuss how standards can be used to capture organizational wisdom about efficetive methods of software development.

  Write down an interactive web page named swap.html

Write an interactive Web page named swap.html that contains two text boxes and a button. When the user clicks the button, the contents of the two text boxes should be swapped.

  Create user - itstaff with local administrator privileges

The hospital needs to display a HIPPA warning reminding employees of patient confidentiality requirements to all employees when they log on.

  Write down a four to five 4-5 page paper in which you

most operating systems use a virtual memory manager vmm whose responsibility is to manage the relationship between the

  What is the network

explain the main types of networks.

  Explain the role of us-cert in protecting the nations

write a three to four page paper in which youexplain the role of us-cert in protecting the nations industrial systems

  Modify the inventory program by adding a button to the gui

modify the inventory program by adding a button to the gui that allows the user to move to the first item the previous

  Explain the z-transform of the following system transfer

Discrete Time Systems, 1. a) Find the z-transform of the following system transfer function assuming the input is a unit staircase (i.e. zero order held). The sampling rate is T=0.2.

  Demonstrate three multimedia applications

The seminar mentions that many tools already exist for deployment of multimedia applications such like (Camtasia, Blender and Paint.NET). Select such a tool, present its uses, advantages and limitations. Demonstrate three multimedia applications t..

  Convert csv file into html file

Convert CSV file into HTML file

  Developing the project

In your new position at the XYZ Corporation, you have been asked to lead the risk assessment team.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd