Ask Question

Given that a function receives three parameters a, b, c, of type double, write some code, to be included as part of the function, that determines whether the value of "b squared" - 4ac is negative. If negative, the code prints out the message "no real solutions" and returns from the function.

+1
Answers (1)
  1. 25 July, 15:00
    0
    The function, having three double parameters, for the given scenario in c+ + is given below.

    void calc (double a, double b, double c)

    {

    double res, s;

    s = b*b;

    res = s - (4*a*c);

    if (res < 0)

    cout << "no real solutions" << endl;

    }

    Explanation:

    A function is declared as follows.

    return-type function-name (parameter1, parameter2, ...)

    1. The return-type can be void or any other data type in c+ + language. Void indicates that the function does not returns anything. Other data types indicate that the function returns a value of that particular data type.

    2. Here, the return type is taken as void since question does not asks to return any value from the function.

    3. The function-name is the name of the function. The naming conventions are similar to those defined for variables in c++.

    4. The brackets following the function-name consists of the parameters. The parameters are optional and the bracket can be empty.

    5. The parameters are declared in the same way as the normal variables.

    The function executes as explained.

    1. The function calc () receives three double parameters a, b and c.

    2. No user input is taken inside the function.

    3. Two additional variables are declared which are used as given below. These variables are also declared as double.

    4. Square of value in variable b is stored in the variable, s.

    5. The final value of the expression, s - 4ac (equivalent to b squared - 4ac), is stored in the variable, res.

    6. If the value of variable res is less than 0 or negative, the function displays a message, "no real solutions" to the standard output.

    7. If the value of variable res is more than or equal to 0, the function does not display any message to the standard output.

    8. As per the question, message should be displayed only for the negative value of the expression.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Given that a function receives three parameters a, b, c, of type double, write some code, to be included as part of the function, that ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers