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
Which type of password would be considered secure?
Annette [7]
A strong password obeys some password rules, such as:
- minimum length
- using characters from different classes (uppercase, lowercase, numbers, typographic characters)

Your safest bet these days is to use a password manager and have it generate one for you, so that hackers can not guess it by understanding humans' predictable mind. ;-)
6 0
3 years ago
How many people watch Anime in the world?
iren [92.7K]
3 to 4 billion people.

7 0
3 years ago
Read 2 more answers
Which are types of online resources that students can use for help? Check all that apply. simulated labs web-based educational g
Korvikt [17]

Answer:

Simulated Labs

Web-Based Educational Games

Discussion Forums

Explanation:

Did a test with the same question.

3 0
3 years ago
Read 2 more answers
Which of these is a Microsoft certification CCIE PMP PRINCE2 MCSE
Angelina_Jolie [31]

MCSE is a Microsoft Certified Solutions Expert.

6 0
3 years ago
Add code to this loop, to pick up all of the radios, with only seven blocks.
Goshia [24]

Answer:

umm

Explanation:

what do you mean by that

4 0
2 years ago
Other questions:
  • In every organization, workers receive and sendinformation daily. The flow of this information should be____________.upward and
    11·1 answer
  • The relational database is the primary method for organizing and maintaining data today in information systems. It organizes dat
    9·1 answer
  • When you're working with a word processing document and you press the DEL Key what happens
    7·2 answers
  • the front desk of the Nocete's Hotel will comlute the total room sales (TRS) of Room 101.The room was occupied three times and t
    6·1 answer
  • The names of the governing body or organizationds that creates rules for information technology and information communication te
    9·1 answer
  • 1. Which sentence best expresses the main idea
    12·1 answer
  • What kind of skill is persuasion?
    7·1 answer
  • A. Why are the data known as raw facts? Explain.​
    14·2 answers
  • Why Use LinkedIn AI Automation Tools to Grow Your Sales Pipeline?
    7·1 answer
  • reagan's firm has not had to make large investments in computer or networking hardware or in personnel to maintain the hardware
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!