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
What is a good coding site
Helga [31]

Sratch.com

-Agarvated

6 0
3 years ago
True or false a weighted inventory system is often tied into player advancement
alekssr [168]

Answer:tayfana

Explanation:true

7 0
2 years ago
To close a tab, click the ____ button in the web page thumbnail on the tab switcher.
slavikrds [6]
Tabs are rectangular boxes found on top of your we browser. At the right of each of those tabs, you see a symbol written in 'x' (as shown in the picture). This is the one you should click to close an existing tab.

3 0
3 years ago
Which criterion can be used to select the appropriate type of network media for a network?
OverLord2011 [107]

There are various kinds of network media and each one of them has different features and benefits. Some have different characteristics and not all of them are meant to perform the same purpose. While choosing network media, a number of criteria must be met. These criteria include:

The distance the selected medium can successfully carry a signal.

The environment where the selected medium is to be installed

Explanation:

The distance the selected medium can successfully carry a signal – The type of network media you choose depends on the distance it can cover before you install signal boosters or repeaters. Repeaters are used to regenerate signals that are required to cover greater distances. A UTP cable as compared to fiber is more prone to interference like noise and the distance it covers before a signal repeater is installed is shorter. Fiber cable is considered the best for distances as it can cover longer distances.

Environment should also be considered when choosing network media - If your network is setup in a place where there is too much electromagnetic field being generated, then you may be required to purchase fiber optic cables. Fiber optics are immune to such interference.

Learn about network media

brainly.com/question/9279069

#LearnWithBrainly

3 0
3 years ago
I need help lol if you can do this for me that would be amazing. its long and 20 Q.
Ksivusya [100]

Answer: A,C,D,B,D,C,C,A,D,B,D,D,B,A,C,D

Explanation:

7 0
3 years ago
Other questions:
  • What does CPL stand for
    9·2 answers
  • Two different names that refer to the same data item best defines:
    12·1 answer
  • Carson's supervisor has asked him to review a variety of portable computers for possible purchase for their company's employees.
    13·1 answer
  • The icons to insert footnotes and endnotes in a document are located in the _____ tab.
    8·1 answer
  • What was the effect of the norman conquest on the language of britain?
    11·1 answer
  • 6. Python indexes lists beginning with the number 1.<br> True<br><br> False
    15·1 answer
  • How many comparisons will be done to find 8 in this list using a linear search?
    8·1 answer
  • Enthusiasm codehs 7.6.4 Write a function called add_enthusiasm that takes a string and returns that string in all uppercase with
    15·1 answer
  • HURRY please!!!!
    13·1 answer
  • What do conditions do for programs?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!