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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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