Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

help please Do Programming Exercise 4.1 from pages 120- 121 Have your program: D

ID: 3756491 • Letter: H

Question

help please

Do Programming Exercise 4.1 from pages 120- 121 Have your program: D Begin with a program description comment 0 Break the program off into sections for each main action (use section comments and blank lines between sections) 0 Use meaningful (descriptive) variable names D Declare a variable for the discriminant (b- 4ac) 1 Use an if elif else statement to catch every case 0 Begin with a test for a0. Why? D Then test if the discriminant is less than zero. Why? 0 Round the output to two decimal places- you will need to use format for this (see page 77) 0 Display the prompt and output similar to the example on page 121 0 Run your program using the following 7 input test cases. Include test cases for any optional additional cases you code (infinite solutions if a, b, and c are all 0, or no solution if a and b are 0 but c is not 0, or complex roos, eg, #7 below formulas roots 1.0 1.0 -6.0 2. x2 15x 1.0 -15.0 0.0

Explanation / Answer

Writing in C++ (as no language specified)

#include <iostream>
#include <iomanip>

using namespace std;


int main()
{
int a,b,c;
float det;

cout<<"Enter values for a,b,c ";
cin>>a>>b>>c;

if(a==0&&b==0&&c==0){
cout<<"Many solutions as all a,b and c are zero ";
}
else if(a==0&&b==0&&c!=0){
cout<<"No solution ";
}else
if(a==0){
cout<<"Not a Quadratic equation";

}else{
det = b*b -4*a*c;
if(det<0){
cout<<"Roots are Complex as det is less then zero ";
}
else if(det==0){
cout<<"Roots are equal and are "<<setprecision(3)<<(float)(-b)/(2*a)<<endl;
}
else
cout<<"Roots are "<<setprecision(3)<<float(-b+det)/(2*a) <<" and "<<setprecision(3)<<float(-b-det)/(2*a);
}
return 0;
}