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
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
What is the impact of VR on Educational Learning rather than games?​
nekit [7.7K]

Answer : Candice

Explanation: Candice penis fit in your mouth

3 0
2 years ago
Tyler wants to upgrade his very old operating system to the latest mac or microsoft operating system, but he cannot seem to inst
nordsb [41]
Every program has minimum system requirement, so at least His CPU is not good, or the amount of his RAM is too short to run the new version of OS.
6 0
2 years ago
To be a successful computer systems engineer, you must be proficient in programming languages and operating systems. Similarly,
Maslowich

Collectively, skills like the ones listed above are Technical skills. These skills refer to the Knowledge and ability to perform specific tasks. However, Soft skills are also important, because they relate to the ability to interact and communicate effectively with people.

6 0
2 years ago
Read 2 more answers
Use the drop-down menus to complete each sentence about the layers of the atmosphere.
REY [17]

Answer

Use the drop-down menus to complete each sentence about the layers of the atmosphere.  

If the Mesosphere did not exist, Earth might be destroyed by chunks of rock from space.

The Stratosphere is located 12 to 50 kilometers from Earth’s surface.

Both the Mesosphere and Troposphere get colder as altitude increases.

The ozone in the Stratosphere protects people from ultraviolet (UV) radiation.

The Themosphere has the highest temperature of any layer in Earth’s atmosphere.

u welcome

6 0
2 years ago
Read 2 more answers
Which phrase best describes a scenario in Excel 2016?
Airida [17]

Answer:

what are the phrases?

Explanation:

6 0
2 years ago
Other questions:
  • Enter a formula in cell G5 that calculates the difference between the attendance totals for 2018 and 2017. Copy the formula to t
    6·1 answer
  • George and Miguel are considering opening up a shoe store but first need to do market research. Which one of these is NOT part o
    13·2 answers
  • Becky is preparing a document for her environmental studies project. She wants to check her document for spelling and grammar er
    5·2 answers
  • Mel is skilled in identifying the technical, economic, and organizational feasibility of software. In which phase of SDLC should
    13·1 answer
  • 10) What is the BEST way to rewrite sentence (1) to make it more
    5·2 answers
  • You have configured your firewall to authenticate a group of 100 users who are in your company. You set up the database of users
    14·1 answer
  • Use the following data definitions data myBytes BYTE 10h,20h,30h,40h myWords WORD 3 DUP(?),2000h myString BYTE "ABCDE" What will
    9·1 answer
  • Which change signaled a musical progression toward rock and roll?
    14·1 answer
  • Given num_rows and num_cols, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print
    7·1 answer
  • Explain working principle of computer?​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!