answer.
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
kupik
1 month 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:
Natasha_Volkova [1K]1 month ago
4 0

Answer:

The C++ function definition for printAttitude can be seen 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:

It is notable that this method takes an int parameter.

Since it yields no value, it has a void return type.

The console displays messages based on the integer parameter, n, using a switch statement.

Output conditions are specified in different cases.

The default case takes care of values where no output is needed.

Each case concludes with a break statement to end the execution of the program.

This function can be utilized within a program as illustrated.

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 called with the user-input as a parameter.

3. If a user enters 11, which does not match any of the case values, the default case is executed, which does nothing and the break statement runs.

4. Thus, nothing is displayed for the input of 11.

5. When the user inputs 3, the corresponding case block is executed since it matches the case values.

6. The program produces the following output when the user inputs 3.

OUTPUT

Enter any number: 3

agree

The program concludes with a return statement.

You might be interested in
Find true or false. A hacker is hacking software with access in sensitive information from your computer​
Harlamova29_29 [1022]
IT'S CORRECT!! I LOOKED IT UP
7 0
2 months ago
Suppose a linked list of 20 nodes. The middle node has a data –250. Write the pseudocode to replace the middle node of the linke
oksian1 [950]
The data for the middle node shows as –250.... Please outline the pseudocode to substitute the middle node in the linked list. Assume that the head pointer is designated as Head_ptr and the entry data for the new node is defined as Entry.
4 0
2 months ago
Read 2 more answers
Access-lists pose a logical problem which often has more than one solution. Can you think of a different set of rules or placeme
maria [1035]
The question is incomplete, as it lacks a diagram of the topology and Router R1's table. I assume the user has access to both the topology and routing information. The configuration below will assist in resolving the ACL issue: Hosts within the 172.16.0.0/16 network should have unrestricted access to Server1, Server2, and Server3, which is currently not the case since L1 is unable to connect to Server2 or Server3. The suggested configuration on Cisco Router R1 will rectify the ACL issues.
6 0
1 month ago
The processing of data in a computer involves the interplay between its various hardware components.
Amiraneli [1052]

Affirmative.

Data processing entails transforming raw data and managing its flow through the Central Processing Unit and Memory to output devices. A computer's CPU contains two main parts: the Arithmetic Logic Unit (ALU) and the control unit. The ALU handles complex calculations and logical operations, while the control unit retrieves, decodes instructions, and regulates the data exchange between Memory, ALU, primary and secondary storage, along with various output devices.


8 0
1 month ago
Other questions:
  • Assume that the following variables have been properly declared and initialized.
    12·1 answer
  • 6. Write pseudo code that will perform the following. a) Read in 5 separate numbers. b) Calculate the average of the five number
    6·1 answer
  • A company requires an Ethernet connection from the north end of its office building to the south end. The distance between conne
    8·1 answer
  • When adopting and implementing a Software as a Service (SaaS) platform such as Salesforce for your business, which responsibilit
    7·1 answer
  • Write a program that prompts the user to enter three cities and displays them in ascending order. Here is a sample run: Enter th
    8·1 answer
  • What feature would be used to collect how many times users downloaded a product catalog?
    11·1 answer
  • A 2-dimensional 3x3 array of ints, has been created and assigned to tictactoe. Write an expression whose value is true if the el
    10·1 answer
  • Using the format method, fill in the gaps in the convert_distance function so that it returns the phrase "X miles equals Y km",
    12·1 answer
  • Suggest how the following requirements might be rewritten in a quantitative way. You may use any metrics you like to express the
    7·1 answer
  • Write the execution steps if the input is a lion.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!