You are required to write a code that requests the user to enter three integer coefficients: a, b, and c in this order. Next, the user is requested to enter the equation degree: 1 for a linear equation and 2 for a quadratic equation. If the user enters an equation degree other than 1 or 2, the program must output Invalid. Based on the equation type, the program will process the coefficients and provide outputs as described below: First Scenario: Linear Equation When a linear equation is selected, the coefficient a is ignored and the equation format becomes: y=bx+c The program should check the slope of the line and accordingly print the values of the x-intercept, the y-intercept, and the line direction with respect to the x-axis each on a separate line. We have four possibilities: Slope is positive (i.e. b > 0): x-intercept = −cb, y-intercept = c, direction is Upward Slope is negative (i.e. b < 0): x-intercept = −cb, y-intercept = c, direction is Downward Slope is zero (i.e. b = 0) and (c = 0): x-intercept = All, y-intercept = 0, direction is Parallel Slope is zero (i.e. b = 0) and (c ≠ 0): x-intercept = None, y-intercept = c, direction is Parallel Second Scenario: Quadratic Equation When a quadratic equation is selected, the equation format is: y=ax2+bx+c The program should check the value of coefficient a then check if the equation has real roots and accordingly print the real roots values and the Parabola opening direction each on a separate line: if (a = 0): handle it as a Linear equation as described above if (a ≠ 0): (b2>=4ac): root1 = −b+b2−4ac√2a and root2 = −b−b2−4ac√2a (b2<4ac): real roots = None (a > 0): Parabola opening direction is Top (a < 0): Parabola opening direction is Bottom

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 28PE
icon
Related questions
Question
100%

You are required to write a code that requests the user to enter three integer coefficients: a, b, and c in this order. Next, the user is requested to enter the equation degree: 1 for a linear equation and 2 for a quadratic equation. If the user enters an equation degree other than 1 or 2, the program must output Invalid. Based on the equation type, the program will process the coefficients and provide outputs as described below:

First Scenario: Linear Equation

When a linear equation is selected, the coefficient a is ignored and the equation format becomes:

y=bx+c

The program should check the slope of the line and accordingly print the values of the x-intercept, the y-intercept, and the line direction with respect to the x-axis each on a separate line. We have four possibilities:

Slope is positive (i.e. b > 0): x-intercept = −cb, y-intercept = c, direction is Upward
Slope is negative (i.e. b < 0): x-intercept = −cb, y-intercept = c, direction is Downward
Slope is zero (i.e. b = 0) and (c = 0): x-intercept = All, y-intercept = 0, direction is Parallel
Slope is zero (i.e. b = 0) and (c ≠ 0): x-intercept = None, y-intercept = c, direction is Parallel
Second Scenario: Quadratic Equation

When a quadratic equation is selected, the equation format is:

y=ax2+bx+c

The program should check the value of coefficient a then check if the equation has real roots and accordingly print the real roots values and the Parabola opening direction each on a separate line:

if (a = 0): handle it as a Linear equation as described above

if (a ≠ 0):

(b2>=4ac): root1 = −b+b2−4ac√2a and root2 = −b−b2−4ac√2a
(b2<4ac): real roots = None
(a > 0): Parabola opening direction is Top
(a < 0): Parabola opening direction is Bottom

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 8 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning