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
Subratract 11100 from 1011 by using 1's complement method step by step​
tia_tia [17]
10089 is gonna be your anwser
7 0
3 years ago
Antonio’s computer is hung up. which trio of keys should he press to restart his computer?
IgorLugansk [536]

Ctrl + Alt + Delete is the keys used by some PCs to reboot frozen computers by using task manager to kill any nonresponding applications. Another way to do this on some other is Ctrl + Shift + Esc.

6 0
3 years ago
Read 2 more answers
What are the responsibilities of the DBA and the database designers?
Ratling [72]

Answer:

Explanation:

DBA's main responsibility is making sure that there is enough CPU, disk, memory, and network bandwidth available, as well as making backups every so often. Meanwhile, the database designers/developers are responsible for investigating and implementing what the end-user needs and making sure that the database holds all of the information that the end-user will be using.

3 0
3 years ago
You should always buy the biggest camera bag that you can find for extra equipment
zysi [14]
False bbfderaddfdffffgfgdhgft
5 0
4 years ago
Read 2 more answers
How to reduce hard drive failure data loss?
malfutka [58]
<span>Regularly schedule "fire drills" to restore information from backup
Keep it away from Dusty areas
Have a battery back up system
P</span><span>rotect equipment from static electricity that can erase data or damage components.
Hope that answers your question

</span>
7 0
3 years ago
Other questions:
  • 3k means about 3 thousand bytes. how would you express two hundred million bytes? .
    8·1 answer
  • Array is special variable that can handle more than one value.
    6·1 answer
  • Write a function (funception) that takes in another function func_a and a number start and returns a function (func_b) that will
    7·1 answer
  • Jeffery wants to locate reliable academic information on the effects of global warming and ways to conserve energy. What is the
    5·1 answer
  • A developer has been asked to create code that will meet the following requirements: Receives input of: Map, List Performs a pot
    13·1 answer
  • If you have an equipment failure while driving on an expressway, you should
    8·1 answer
  • How are gems and precious metals similar?
    6·2 answers
  • What is the difference between a 13 column abacus and 5 column abacus?
    10·1 answer
  • You are a network administrator for a company that has two buildings. You are setting up a wireless network so users can maintai
    8·1 answer
  • While storms could be a cause, power______ are more likely to be caused by disturbances from high-demand equipment in a home or
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!