1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Svetradugi [14.3K]
3 years ago
14

Write the definition of a function printAttitude, which has an int parameter and returns nothing. The function prints a message

to standard output depending on the value of its parameter. If the parameter equals 1, the function prints disagree If the parameter equals 2, the function prints no opinion If the parameter equals 3, the function prints agree In the case of other values, the function does nothing.
Computers and Technology
1 answer:
Oksana_A [137]3 years ago
4 0

Answer:

The function definition, in cpp, for the function printAttitude is given below.

void printAttitude(int n)

{

switch(n)

{

case 1: cout<<"disagree"<<endl; break;

case 2: cout<<"no opinion"<<endl; break;

case 3: cout<<"agree"<<endl; break;

default: break;

}

}

Explanation:

As seen, the method takes an integer parameter.

The method does not returns any value hence, return type is void.

The message is displayed to the console using switch statement which executes on the integer parameter, n.

The values for which output needs to be displayed are taken in cases.

The values for which no output needs to be displayed, is taken in default case.

Every case ends with break statement so that the program execution can be terminated.

This method can be used inside a program as shown.  

PROGRAM

#include <iostream>

using namespace std;

void printAttitude(int n)

{

switch(n)

{

case 1: cout<<"disagree"<<endl; break;

case 2: cout<<"no opinion"<<endl; break;

case 3: cout<<"agree"<<endl; break;

default: break;

}

}

int main() {

// variables to hold respective value

int n;

// user input taken for n

cout<<"Enter any number: ";

cin>>n;

// calling the function taking integer parameter  

printAttitude(n);

return 0;

}

OUTPUT

Enter any number: 11

1. The user input is taken for the integer parameter.

2. Inside main(), the method, printAttitude(), is then called and the user input is passed as a parameter.

3. Since the user entered value is 11 which does not satisfies any of the values in the cases, the default case is entered which does nothing and executes the break statement.

4. Hence, the program displays nothing for the value of 11.

5. When the user enters value 3, the case statement is executed since 3 satisfies one of the case values.

6. The program output for the user input of 3 is as shown below.

OUTPUT

Enter any number: 3

agree

The program ends with return statement.

You might be interested in
Which of the following is not a technology that can be used to conserve resources?
amm1812
<span>Natural gas when extracted through human industry will utilise resources to construct the necessary plant and machinery and then result in the consumption of a resource. Therefore this is the technology that cannot be seen as conserving resources.</span>
6 0
3 years ago
Read 2 more answers
if you want to have certain icons available regardless of what tab you are using you should add them to the
jarptica [38.1K]
The hotbar is what i think it is called but it is basically the bar of stuff at the bottom of the screen on windows computers.
4 0
3 years ago
When an individual user works in _____, the workstation performs all the functions of a server by storing, accessing, and proces
anyanavicka [17]
When an individual user works in stand-alone mode, the workstation performs all the functions of a server by storing, accessing, and processing data as well as providing a user interface.​
4 0
3 years ago
What is the purpose of external firewalls? to prevent users from accessing sensitive human resource or financial data to limit a
ziro4ka [17]
<span>keep out unauthorized internet users from intranet networks

All firewalls are used to control the traffic between networks to only allowed traffic.
</span>
3 0
3 years ago
When determining the statement of purpose for a database design, what is the most important question to ask?
mamaluj [8]
D how many tables will be in the database
3 0
3 years ago
Read 2 more answers
Other questions:
  • You have just been named Director of Data Administration of General Hardware Co. General Hardware maintains a large central IS o
    15·1 answer
  • Enter the answer.
    11·2 answers
  • Which is an example of an incremental approach to solving a problem?
    15·1 answer
  • horseback riders, bicyclists, and skateboarders ____ the rules of right-of-way when they use the road ?
    7·2 answers
  • Linux is a kind of software whose code is provided for use, modification, and redistribution. what kind of software is this?
    5·1 answer
  • Jiz<br>Active<br>2<br>3<br>- 2(7 - 15)<br>What is the value of<br>4​
    10·2 answers
  • Write a program that uses a while loop to calculate and print the multiples of 3 from 3 to 21. Your program should print each nu
    11·1 answer
  • Select statements about Multiprocessors that are FALSE. a. Asymmetric multiprocessors are a popular form of tightly coupled arch
    7·1 answer
  • Which of the following items can you locate in a document using the navigation pane? Choose the answer.
    10·1 answer
  • An agile team has which two characteristics? (choose two. ).
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!