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]
2 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]2 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 technologies is the best choice to convey urgent and highly sensitive information? telephone fax letter e
snow_lady [41]
Using e-mail to send messages is the best choice to convey urgent and highly sensitive information. E-mail is just a conversation between you and the recipient. So it is the best when it comes to when you are sending a highly sensitive information. While telephone fax letter and dispatch radio may need to use a mediator to transfer messages which violates the confidentiality of the information.
3 0
3 years ago
Hurrryyyy it’s either a or c
Veseljchak [2.6K]

Answer and Explanation:

I believe its A. Modularity enables multiple programmers to work on a program at the same time..

Let me know if I'm wrong..

4 0
3 years ago
Which of the following ensures that dropped packets are resent?
Agata [3.3K]

Answer:

TCP

Explanation:

Transmission control protocol ensures packets loss and performs retransmission

TCP works with Internet Protocol (IP)

TCP/IP defines how computers send data packets to each other.

TCP allows transmission of information in both the direction.

Bit rate :defines the rate at which bits are transferred from one place to another

7 0
3 years ago
Which of the following cools the air in a household refrigerator?
Ivanshal [37]

The following cools the air in a household refrigerator: Absorption of the heat from the air due to evaporation of the liquid refrigerant . Correct answer:B

The function of the refrigerator is to absorb heat into the refrigeration system. The evaporator is placed in the area to be cooled. The refrigerant vaporizes from the heat it absorbs heat in the evaporator.

4 0
2 years ago
Read 2 more answers
Suppose that sales is a two-dimensional array of 10 rows and 7 columns wherein each component is of the type int , and sum and j
Deffense [45]

According to the given question, sales is a two-dimensional array and contains 10 rows and 7 columns wherein each component is of type integer and the variables sum and j are also of integer type.

<u>Explanation:</u>

In order to find the sum of the elements of the fifth row of sales, the correct piece of code should be:

sum=0;

for(j=0;j<7;j++)

sum=sum+sales[4][j];  

The indexing in an array always starts from zero, therefore, to calculate the sum of the fifth row, the user has to write 4 in the index to point to the fifth row.

3 0
3 years ago
Other questions:
  • What kind of memory modules include registers between the system’s memory controller and the module’s memory chips, registers th
    7·2 answers
  • Which actions help to protect a computer and keep it running properly? Check all that apply.
    10·1 answer
  • What does %d, , %c, %s mean and what's their difference?
    12·1 answer
  • Explain the difference between the legal protections a security officer enjoys and the legal protections a police officer receiv
    12·2 answers
  • If you give an actual answer I'll give brainliest​
    13·2 answers
  • Please help with coding assignment.
    11·1 answer
  • How to make a Java GUI application? Discuss each step needed.
    13·1 answer
  • How can structure of a table change in sql. What general types of changes are possible
    8·1 answer
  • rapid prototyping could be an advantageous methodology for developing innovative computer-based instruction. Software engineers
    6·1 answer
  • A(n) ____ describes the structure, content, and access controls of a physical data store or database.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!