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]
3 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]3 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
Xxx<br>uuuuuu<br>uuuu<br>jjnmn<br>jjh
Leviafan [203]
Answer: What’s this??
7 0
2 years ago
What function returns a line and moves the file pointer to the next line?
Aneli [31]
The goto command

for example


:start

title ""graphing calculator""

goto start
5 0
3 years ago
Sahil is making a graphic novel in which the villain plans to reduce the rate at which energy is released from the Sun. The vill
gregori [183]

i believe the answer is b

hope this helps :)

8 0
3 years ago
Read 2 more answers
What is a circular network.​
Travka [436]

Answer:

A circular network happens when you have two (or more) routes to the same controller. Typically, the routes are BACnet/IP and BACnet/Ethernet and both are communicating on both networks. This could happen with BACnet MS/TP although it is rare.

Explanation:

5 0
2 years ago
Read 2 more answers
What was bill gates first operating system he created?
vagabundo [1.1K]
Microsoft windows was his first

3 0
3 years ago
Other questions:
  • What block cipher mode of operation involves each ciphertext block being fed back into the encryption process to encrypt the nex
    12·1 answer
  • Yellow and blue light are projected on a white screen. what color will the screen appear to be?
    6·2 answers
  • Oxygen-18 has an atomic number of 8. How many neutrons are in this isotope?
    7·1 answer
  • 4. Extrusion tools in Blender® duplicate vertices while keeping the geometry connected with the original vertices. (1 point)
    7·1 answer
  • Class CTRivers describes collection of CT rivers. It has no data, and it provides the following service methods. None of the met
    13·1 answer
  • Write a complete Java method that returns an integer. The method declares a Scanner object, then prompts the user for a series o
    12·1 answer
  • What is the difference between head header and heading in HTML​
    8·1 answer
  • What's the best strategy for avoiding ATM fe
    14·1 answer
  • 27. If X and Y are int type variables,
    14·1 answer
  • I have a problem. I can't cycle between game packs on my strike pack, I've watched so many vids I'm on Xböx and I'm holding the
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!