Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ou shall create a complete C++ program that will take the program that you wrote for assignment 6 that prompted the user for three integer

ou shall create a complete C++ program that will take the program that you wrote for assignment 6 that prompted the user for three integer values that were read from the keyboard. Now we are going to do what is called maintenance (taking a working program and making changes to it). We still are going use a series of decisions to find the middle value (in ascending order) of the three integers. The three integers can each be different amounts, or two or more of them can be the same amount. But the values will come from a file "data.txt". Below is an example execution of the program. Your program should use the same wording for printing the results to the screen. The three integers from the file are: 12 530 -8 The sorted values are -8 12 530 The middle value is 12 Note: your output should still display on the screen. Do not write your output to another file. Your Approach to the Problem You be using the same approach (same code) that you used before. Once you have read in the values everything will be the same (assuming you got assignment 6 correct) except the minor change to the first output statement.

Inside the main function definition, declare four integer variables being sure to give them a descriptive name where it is easy for the reader of the code to know what is stored in each. Making one of them called temp is good as temp stands for "temporary variable" and is used when sorting the three integers.

Read in the integers from the file data.txt and store them, respectively, in three other variable names. For an example, I will use valueA, valueB, and valueC. But yours need to be more descriptive.

Implement the following sorting algorithm in sequence. When the algorithm is complete, the three integers will be sorted such that the current contents of valueA, valueB, and valueC will be in ascending order.

if valueA > valueB then swap valueA and valueB. if valueB > valueC then swap valueB and valueC. if valueA > valueB then swap valueA and valueB.

When the algorithm above says to swap the contents of two values x and y, do the following steps in this order inside a set of curly braces:

Store x in temp. Store y in x. Store temp in y.

You need to use the curly braces so that all three statements are affected by the same if statement.

Print the current values of the three integers starting with valueA, then valueB, and then valueC . Finally, print the value of the middle integer located in valueB. When printing these values, be sure to follow the format shown in the example execution of the program

Save the contents of the file of your new file

Use your IDE to compile the contents of your source code file

If any syntax errors are detected by the g++ compiler, or any warning messages appear, correct the errors, save the contents of your source code file, and recompile the file. Continue this step until all syntax errors in the program are corrected and no warning messages appear

Link the program. (The g++ compiler automatically performs this link step for you after you compile the program if your program contains no syntax errors)

Test your program by running it several times with different integer combinations to check that you have implemented the algorithm correctly. If any logical errors occur (i.e., program does not fulfill the requirements or produces incorrect output), make corrections in your source code file, save the file, compile and link the file, and run the program again. Continue to do this step until the logical errors are corrected.

Submit the softcopy of your source code file. Do NOT submit a copy of your executable file.

Design and Implementation Constraints

Follow the coding standards listed in assignment 1

Use no C++ code features in your program that have not been covered yet in the course

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions