Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

In this lab, you complete a C++ program that swaps values stored in three int variables and determines maximum and minimum values. 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.

1. Open the source code file named Swap.cpp using the text editor of your choice.

2. Write the statements that test the first two integers, and swap them if necessary.

3. Write the statements that test the second and third integer, and swap them if necessary.

4. Write the statements that test the first and second integers again, and swap them if necessary.

5. Save this source code file in a directory of your choice, and then make that directory your working directory.

6. Compile the source code file Swap.cpp.

7. Execute the program using the following sets of input values, and record the output:

101 630 21 -23 1500

Here is the Swap.cpp file information:

// 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

// Get user input

cout

cin >> first;

cout

cin >> second;

cout

cin >> third;

// 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

cout

cout

return 0;

} // End of main function

SECOND LAB:

Lab 9-1: Writing Functions with No Parameters

In this lab, you complete a partially prewritten C++ program that includes functions with no parameters. The program asks the user if he or she has preregistered for tickets to an art show. If the user has preregistered, the program should call a function named discount() that displays the message, "You are preregistered and qualify for a 5 percent discount." If the user has not preregistered, the program should call a function named noDiscount() that displays the message, "Sorry, you did not preregister and do not qualify for a 5 percent discount." The source code file provided for this lab includes the necessary variable declarations and the input statement. Comments are included in the file to help you write the remainder of the program.

1. Open the source code file named ArtShowDiscount.cpp using Notepad or the text editor of your choice.

2. Write the C++ statements as indicated by the comments.

3. Save this source code file in a directory of your choice, and then make that directory your working directory.

4. Compile the source code file, ArtShowDiscount.cpp.

5. Execute the program.

Here is the ArtShowDiscount.cpp file information:

// ArtShowDiscount.cpp - This program determines if an art show attendee gets a 5% discount for preregistering.

// Input: Interactive

// Output: A statement telling the user if they get a discount or no discount.

#include

#include

using namespace std;

void discount();

void noDiscount();

int main()

{

string registerString;

cout

cin >> registerString;

// Test here. If = Y, call discount(), else call noDiscount().

return 0;

} // End of main function

// Write discount function here

// Write noDiscount function here

101 630 21 22 1500 2 -23 9 2

Step by Step Solution

3.40 Rating (150 Votes )

There are 3 Steps involved in it

Step: 1

include include include include include include using namespace std int main Swapcpp This program de... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Chemistry The Central Science

Authors: Theodore Brown, Eugene LeMay, Bruce Bursten, Catherine Murphy, Patrick Woodward

12th edition

321696727, 978-0132175081, 978-0321696724

More Books

Students also viewed these Programming questions

Question

In a system with light damping (c Answered: 1 week ago

Answered: 1 week ago

Question

22. Why is tPA not helpful in cases of hemorrhagepg109

Answered: 1 week ago