Ask Question

Write the definition of a function printAttitude, which hasan int parameter and returns nothing. The function prints amessage to standard output depending on the value of itsparameter. a. If the parameter equals 1, the function prints disagree. b. If the parameter equals 2, the function prints no opinion. c. If the parameter equals 3, the function prints agree. d. In the case of other values, the function does nothing.

+1
Answers (1)
  1. 7 September, 20:02
    0
    The function definition to this question can be given as:

    Function definition:

    void printAttitude (int x1) / /define function printAttitude.

    {

    //nested else-if statements

    if (x1==1)

    //if block

    cout<<"disagree"<
    //message

    else if (x1==2)

    //else if block

    cout<<"no opinion"<
    //message

    else if (x1==3)

    //else if block

    cout<<"agree"<
    //message

    else

    cout<<" ";

    }

    Explanation:

    In the above method definition firstly, we define a method that is "printAttitude". In this method, we pass an integer variable that is "x1". This function does not return any value because its return type is void. In this method, we use nested else-if statements. The description of these conditions can be given as:

    In the if block we check the variable x1 value is equal to 1 If this condition is true. It will print "disagree" otherwise it will go to else-if block. In the else-if block, we check the variable x1 value is equal to 2 if the condition is true. It will print "no opinion". otherwise, we will go to another else-if block. In this block, we check the variable x1 value is equal to 3 if this condition is true. It will print "agree". otherwise it will go to else block. In the else block it will print nothing.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write the definition of a function printAttitude, which hasan int parameter and returns nothing. The function prints amessage to standard ...” 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