Urgent problem

I am currently stuck at this problem assigned to me below.

Write a complete C++ program that consists of a main program and a function
solve_quadratic_equation that will find solution for a quadratic equation. Your function
will need to handle all possible exceptions that can occur with different values of a, b, and c. The
function returns false for complex solution else true for all others. Your function must
demonstrate call by value (a, b, c) and call by reference (x1, x2) formal parameters.

Here's my current code so far:

#include <iostream>
#include <cmath>
void x1(float a, float b, float c);
void x2(float a, float b, float c);
using namespace std;
int main()
{
int a, b, c;
double x1, x2;

cout << "Enter a, b, and c: ";
cin >> a, b, c;

if ((x1 < 0) && (x2 < 0))
cout << "Complex solution.";
else if ((x1 == 0) && (x2 == 0))
cout << "x1 = " << x1 &&
<< "x2 = " << x2;
else ((x1 > 0) && (x2 > 0))
cout << "x1 = " << x1 &&
<< "x2 = " << x2;


system('pause');
return 0;
}

void x1(float a, float b, float c)
{
x1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a);
}

void x2(float a, float b, float c)
{
x2 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);
}
closed account (z05DSL3A)
Write a complete C++ program that consists of a main program and a function solve_quadratic_equation that will find solution for a quadratic equation. Your function will need to handle all possible exceptions that can occur with different values of a, b, and c. The function returns false for complex solution else true for all others. Your function must demonstrate call by value (a, b, c) and call by reference (x1, x2) formal parameters.

1
2
3
4
5
6
7
8
9
10
11
12
....
bool solve_quadratic_equation(float a, float b, float c, float& x1, float& x2);

int main()
{
     ...
}

bool solve_quadratic_equation(float a, float b, float c, float& x1, float& x2)
{
    ...
}
NB: formal parameter data types should be changed to your requirements

Last edited on
Can somebody please post the entire completed program? I am doing a similar problem and have most of it completed but have nothing to compare it to.
All of the code is there. You just have to merge it together. Replace the && after the function calls with the correct parameters and it works.
Last edited on
Topic archived. No new replies allowed.