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

Solutions to the quadratic equation Ax2 +Bx + C-: 0 may be calculated using the

ID: 3735783 • Letter: S

Question

Solutions to the quadratic equation Ax2 +Bx + C-: 0 may be calculated using the quadratic formulas: B-B2-4AC 2A or 2A These formulas may be used, of course, only if the leading coefficient, A, is not zero. The number and type of solutions is determined by the value of the expression under the radical sign, B2 4AC, known as the discriminant: value of discriminant positive zero negative number of solutions kind of solutions real re magina Your job is to write a program which will read the coefficients of a quadratic equation and, if the leading coefficient is non-zero, calculate and report the solutions. Since programming languages does not provide the imaginary type, you'll have to take appropriate steps to give imaginary results in the form shown. Just remember that every imaginary number is really determined by a pair of real numbers Several sample runs appear on the next page; user input appears in bold type. The "I" which appears in the output is simply written where necessary; the actual calculations involve only real results. You are not required to duplicate this output, but you should provide all information shown.

Explanation / Answer

#include <iostream>
#define _USE_MATH_DEFINES   // macro that support cmath in visual studio
#include <cmath>
using namespace std;

int main() {

    float a, b, c, x1, x2, discriminant, real_Part, image_part;
     cout << "This program will provide you information in form of ";
     cout<<"A*x^2 + B*x + C = 0 ";
     cout<<"where A , B and C are integers and A is not eqal to zero ";
    cout << "Enter A, B, C: ";
    cin >> a >> b >> c;
  
    // if a is zero then printing error message and terminate progrmme
    if(a == 0)
    {
        cout<<"No solution will be calculated for leading coefficient as zero ";
        return 0;
    }
  
    // calculating value by (b^2 )- (4 * a * c)
    discriminant = (b*b) - (4*a*c);
  
  
    // value is positive if solution are real
    if (discriminant > 0) {
        x1 = (-b + sqrt(discriminant)) / (2*a);
        x2 = (-b - sqrt(discriminant)) / (2*a);
   cout << "The two real solution are " << endl;
        cout << " X = " << x1 << endl;
        cout << " and X = " << x2 << endl;
    }
  
    // if discriminant is zero then have only one solution
    else if (discriminant == 0) {
        x1 = (-b + sqrt(discriminant)) / (2*a);
        cout << "The one real solution is X = " << x1 << endl;
    }

    else {
        // else dolution is complex number
        real_Part = -b/(2*a);
        image_part =sqrt(-discriminant)/(2*a);
        cout << "The two imagenory solution are " << endl;
        cout << "     X = " << real_Part << "+" << image_part << "i" << endl;
        cout << " and X = " << real_Part << "-" << image_part << "i" << endl;
    }
  
    return 0;
}


/*
OUTPUT:
----------------------------------------------------------
This program will provide you information in form of                                                                
A*x^2 + B*x + C = 0
where A , B and C are integers and A is not eqal to zero                                                            
                                                                                                                    
Enter A, B, C: 2 -5 -3                                                                                              
The two real solution are                                                                                           
                X = 3                                                                                               
        and     X = -0.5

-----------------------------------------------------------      
This program will provide you information in form of                                                                
A*x^2 + B*x + C = 0
where A , B and C are integers and A is not eqal to zero                                                            
                                                                                                                    
Enter A, B, C: 2 -5 4                                                                                               
The two imagenory solution are                                                                                      
            X = 1.25+0.661438i                                                                                      
        and X = 1.25-0.661438i      


-------------------------------------------------------------
This program will provide you information in form of                                                                
A*x^2 + B*x + C = 0                                                                                                 
where A , B and C are integers and A is not eqal to zero                                                            
                                                                                                                    
Enter A, B, C: 1 -8 16                                                                                              
The one real solution is         X = 4

----------------------------------------------------------------

This program will provide you information in form of                                                                
A*x^2 + B*x + C = 0                                                                                                 
where A , B and C are integers and A is not eqal to zero                                                            
                                                                                                                    
Enter A, B, C: 0 3 8                                                                                                
No solution will be calculated for leading coefficient as zero
------------------------------------------------------------------

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote