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
Viefleur [7K]
2 years ago
15

In this lab, you complete a C++ program that swaps values stored in three int variables and determines maximum and minimum value

s. The C++ file provided for this lab contains the necessary variable declarations, as well as the input and output statements. You want to end up with the smallest value stored in the variable named first and the largest value stored in the variable named third. You need to write the statements that compare the values and swap them if appropriate. Comments included in the code tell you where to write your statements.InstructionsEnsure the Swap.cpp file is open in your editor.Write the statements that test the first two integers, and swap them if necessary.Write the statements that test the second and third integer, and swap them if necessary.Write the statements that test the first and second integers again, and swap them if necessary.Execute the program by clicking the "Run Code" button at the bottom of the screen using the following sets of input values.101 22 -23630 1500 921 2 2Provided code:// Swap.cpp - This program determines the minimum and maximum of three values input by// the user and performs necessary swaps.// Input: Three int values.// Output: The numbers in numerical order.#include using namespace std;int main(){ // Declare variables int first = 0; // First number int second = 0; // Second number int third = 0; // Third number int temp; // Used to swap numbers const string SENTINEL = "done"; // Named constant for sentinel value string repeat; bool notDone = true; //loop control // Get user input cout << "Enter first number: "; cin >> first; cout << "Enter second number: "; cin >> second; cout << "Enter third number: "; cin >> third; while(notDone == true){ // Test to see if the first number is greater than the second number // Test to see if the second number is greater than the third number // Test to see if the first number is greater than the second number again // Print numbers in numerical order cout << "Smallest: " << first << endl; cout << "Next smallest: " << second << endl; cout << "Largest: " << third << endl; cout << "Enter any letter to continue or done to quit: "; cin >> repeat; if (repeat == SENTINEL){ notDone = false; } else { cout << "Enter first number: "; cin >> first; cout << "Enter second number: "; cin >> second; cout << "Enter third number: "; cin >> third; } return 0;} // End of main function
Computers and Technology
1 answer:
Sergio039 [100]2 years ago
6 0

Answer:

Following are the code to the given question:

#include <iostream>//header file

using namespace std;

int main()//main method

{

int first = 0,second = 0,third = 0;//defining integer variable  

int temp; //defining integer variable

const string SENTINEL = "done"; // defining a string variable as constant  

string repeat;// defining a string variable  

bool notDone = true; //defining bool variable

cout << "Enter first number: ";//print message

cin >> first;//input value

cout << "Enter second number: ";//print message

cin >> second;//input value

cout << "Enter third number: ";//print message

cin >> third;//input value

while(notDone == true)//defining a loop to check the value  

{

if(first > second)//use if to compare first and second value

{

int temp = first;//defining temp to hold first value

first = second;//holding second value in first variable

second = temp;//holding temp value in second variable

}

if(second > third)//use if to compare second and third value

{

int temp = second;//defining temp to hold second value

second = third;//holding second value in third variable

third = temp;//holding temp value in third variable

}

cout << "Smallest: " << first << endl;//print smallest value

cout << "Next smallest: " << second << endl;//print Next smallest value

cout << "Largest: " << third << endl;////print Largest value

cout << "Enter any letter to continue or done to quit: ";//print message

cin >> repeat;//holding string value

if (repeat == SENTINEL)

{

notDone = false;//holding bool value

}  

else //else block

{

cout << "Enter first number: ";//print message

cin >> first;//input value

cout << "Enter second number: ";//print message

cin >> second;//input value

cout << "Enter third number: ";//print message

cin >> third;//input value

}

return 0;

}

}

Output:

Please find the attached file.

Explanation:

  • Inside the main method Four integer variable "first, second, third, and temp" is declared in which first three variable is used for input value and temp is used to compare value.
  • In thew next step, two string variable "SENTINEL and repeat" is declared in which "SENTINEL" is constant and a bool variable "notDone" is declared.
  • After input the value from the user-end a loop is declared that compare and swap value and print its value.

You might be interested in
Drag each tile to the correct box.
garri49 [273]
I think select the video insert select the movie option under illustrations resize the video player then select the insert tab i’m not 100 percent sure tho
8 0
3 years ago
Read 2 more answers
Nadeen runs a website on vegan lifestyle. She wants to spread the word and make more people visit her site to read her recipes a
pashok25 [27]

What Nadeen needs to do to get people to engage with her web site is to regularly post new content and regularly respond to user comments and questions (options A and C).

<h3>What should Nadeen do to increase visits to her website?</h3>

Currently, social networks and pages have become tools to share information and create a community of people around a topic.

From this trend, many people have developed their own web pages to share their knowledge and experience with other people so that knowledge becomes public and help those who do not have as much knowledge.

However, for a page to have high interactions and visits from the public, the owner of the page must ensure that they comply with some recommendations that will increase the traffic of their page, such as:

  • Post frequently: This is because people are constantly looking for information and like to be up to date with the latest.
  • Respond to user comments and questions: This creates a link between the page owner and their visitors that makes them feel comfortable with this page. This also helps the owner create a community where everyone participates by contributing knowledge.

Note: This question is incomplete because the options are missing. Here are the options:

A. She must post new content on her website regularly.

B. She must increase the number of pay-per-click advertisements on her website.

C. She must regularly respond to user comments and questions.

D. She must use a secure payment gateway.

Learn more about vegan in: brainly.com/question/8708517

3 0
1 year ago
how could environmental and energy problem Kenya faces as far computer installations are concerned be avoided​
ipn [44]

The environmental and energy problem Kenya faces as far computer installations are concerned can be avoided​ by

  • Knowing and finding out the key aspect of ICT strength.
  • Create an holistic judgements in the assessment of ICT capability. Promote the use of solar power.

<h3>How can we overcome ICT challenges?</h3>

There are a lot of Energy Challenges in terms of ICT  in Kenyan and it is good the government and the people work towards energy in terms of sustainable ICT.

Therefore, The environmental and energy problem Kenya faces as far computer installations are concerned can be avoided​ by

  • Knowing and finding out the key aspect of ICT strength.
  • Create an holistic judgements in the assessment of ICT capability. Promote the use of solar power.

Learn more about computer installations from

brainly.com/question/11430725

#SPJ1

7 0
1 year ago
PLEASE HELP ASAP I WILL GIVE BRAINLIEST TO CORRECT ANSWER
salantis [7]
The correct answer is letter b
8 0
3 years ago
Read 2 more answers
What is an icon or animation used to represent aparticipant in an internet chat referred to as?
Veronika [31]
Emoji is an icon or animation used to represent a participant in an internet chat.
8 0
3 years ago
Other questions:
  • What will be displayed after the following statements have been executed? int x = 15, y = 26, z = 32; x = x + 12; y = y/6; z -=
    15·1 answer
  • Headphones are an example of _____.
    6·2 answers
  • Instructions
    12·1 answer
  • What are 7 good facts on Computer Viruses?
    10·1 answer
  • Which of the following variable names is not valid? 1price 1 price price 1 price1
    15·2 answers
  • What do the groups in professional networking sites allow you to do?
    10·1 answer
  • HELP ME?!!?!?!?!?!?
    9·2 answers
  • Please please help I don’t understand this
    6·1 answer
  • Do you want my hero academia?<br><br><br><br><br><br> if so, who's your favorite character :&gt;
    5·2 answers
  • Algorithm to eat orange<br><br>​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!