188k views
3 votes
Define a function called hasRealSolution that takes three parameters containing integer values: a, b, and c. If "b squared" minus 4ac is negative, the function returns False otherwise, it returns True.

User Saarah
by
4.6k points

1 Answer

7 votes

Answer:

Following are the function in C++ Programming language

bool hasRealSolution(int a,int b,int c) // function definition

{

if ((b*b)-(4*a*c)<0) // check condition

return false;

else

return true;

}

Step-by-step explanation:

Following are the program of this question

#include <iostream> // header file

using namespace std; // namespace

bool hasRealSolution(int a,int b,int c); // prototype

bool hasRealSolution(int a,int b,int c) // function definition

{

if ((b*b)-(4*a*c)<0) // check condition

return false;

else

return true;

}

int main() // main function

{

bool x=hasRealSolution(1,2,4); // calling

cout<<x; // display the return value

return 0;

}

Output:

0

Following are the description of code:

  • We declared a function i.e "hasRealSolution " of "bool" type.In this function there are three parameter is pass "a","b" and "c" of "int "type.
  • In the if block we check the condition i.e if "b squared" minus 4ac is negative then it returns the false bool value otherwise it returns the true bool value.
  • In the main function we call the function "hasRealSolution " by passing three integer values into that function and store their value in variable "x" of the bool type.
  • Finally we print the value x in the main function.

User Counsellorben
by
5.3k points