IMPORTANT NOTE - Do not add any cout statements except for the final answers as shown in the sample cases. Do not add "Enter coefficient a, b, or c", "the first root is" or any similar prompts. Also note that the grader is case-sensitive; so "invalid" is wrong but "Invalid" is correct. Do not add any unnecessary spaces.

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%

c++ code

IMPORTANT NOTE - Do not add any cout statements except for the final answers as shown in the sample cases. Do not add "Enter coefficient a, b, or c", "the first root is" or any similar prompts. Also note that the grader is case-sensitive; so "invalid" is wrong but "Invalid" is correct. Do not add any unnecessary spaces.

 

Program Input:
Four integer values for coefficients a, b. and c and the equation degree in this order.
Program Output:
For Linear equations, the output is three lines that display the x-intercept. the y-intercept, and the line direction with respect to the x-
axis.
For Quadratic equations, the outout can be one line as in Sample Test Case 4 or two lines as in Sample Test Case 3 or three lines as in
Sarmple Test Case 2.
Sarmple Test Case 0
Input:
2
1
Output:
0.5
1
Upwerd
Samale Test Case 1
Input:
-9
-2
1
Output:
None
-2
Parallel
Samale Test Cane 2
Input:
-2
4
2
Output:
-0.224745
2.22474
Bottom
Sample Test Case 3
Input:
2
Output:
Norie
Top
Samale Test Case 4
Input:
-5
Output:
Invalid
1 >
Ainelude ciostrean
2 using namespace std;
4
int main ()
6
int a, b. c, degree;
double x_intercept; //Use this variable for the x_intercept of Lincar Equetions
deuble raat1, raat?;//IRe these variahles far the real rpots of Quadratie Fquat ions
18
cin>>; // Lnter the velue of coofficiont a
11
cin>>b; //Entar the value of caeffieient b
12
cin>>c; //Enter the va lue of coefficient c
13
cin>>degree: //Enter the equation degree
14
15
/ Yeur csde st ar ts here
16
// Your code ends here
18 }
17
Transcribed Image Text:Program Input: Four integer values for coefficients a, b. and c and the equation degree in this order. Program Output: For Linear equations, the output is three lines that display the x-intercept. the y-intercept, and the line direction with respect to the x- axis. For Quadratic equations, the outout can be one line as in Sample Test Case 4 or two lines as in Sample Test Case 3 or three lines as in Sarmple Test Case 2. Sarmple Test Case 0 Input: 2 1 Output: 0.5 1 Upwerd Samale Test Case 1 Input: -9 -2 1 Output: None -2 Parallel Samale Test Cane 2 Input: -2 4 2 Output: -0.224745 2.22474 Bottom Sample Test Case 3 Input: 2 Output: Norie Top Samale Test Case 4 Input: -5 Output: Invalid 1 > Ainelude ciostrean 2 using namespace std; 4 int main () 6 int a, b. c, degree; double x_intercept; //Use this variable for the x_intercept of Lincar Equetions deuble raat1, raat?;//IRe these variahles far the real rpots of Quadratie Fquat ions 18 cin>>; // Lnter the velue of coofficiont a 11 cin>>b; //Entar the value of caeffieient b 12 cin>>c; //Enter the va lue of coefficient c 13 cin>>degree: //Enter the equation degree 14 15 / Yeur csde st ar ts here 16 // Your code ends here 18 } 17
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 = , y-intercept = c, direction is Upward
Slope is negative (i.e. b < 0): x-intercept = , 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 = ax? + 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):
-b+ Vb-4ac
-b-b-4ac
o (b? >= 4ac): root1 =
• (b? < 4ac): real roots = None
• (a > 0): Parabola opening direction is Top
• (a < 0): Parabola opening direction is Bottom
and root2 =
2a
2a
Transcribed Image Text: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 = , y-intercept = c, direction is Upward Slope is negative (i.e. b < 0): x-intercept = , 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 = ax? + 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): -b+ Vb-4ac -b-b-4ac o (b? >= 4ac): root1 = • (b? < 4ac): real roots = None • (a > 0): Parabola opening direction is Top • (a < 0): Parabola opening direction is Bottom and root2 = 2a 2a
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Types of Function
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
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr