Question
To practice creating a complete C++ program To practice taking an algorithm that we have already implemented that involved decision making and swapping of values
To practice creating a complete C++ program To practice taking an algorithm that we have already implemented that involved decision making and swapping of values and instead of getting the values from the user we will get them from a file. Assignment Summary In this assignment, you 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. Files Referenced Smith6.cpp (yourname6.cpp) file from your computer Assignment Directions You will need to open your file Smith6.cpp and do "SaveAs" saving it as Smith9.cpp; this way you don't overwrite your Smith6.cpp assignment. If you had problems finishing assignment 6 correctly be sure to get with the instructor for help before starting on this assignment. Start up your IDE software and create your Smith9.cpp source code file. All the following is the same as assignment 6 (except for the input) and is just a reminder of what was required. Be sure you have the comment block at the top of the source code file that has all the information that applies to this assignment. In the Assumptions field and Limitations field, say "None". 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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started