Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ please, Lab8A: For this part of the lab, refer to the lecture slides for a review of Bubble Sort. Practice recoding the algorithm given

C++ please,

Lab8A: For this part of the lab, refer to the lecture slides for a review of Bubble Sort. Practice recoding the algorithm given in lecture. Write a program that prompts the user to enter 10 numbers and stores the input in a 1D array of size 10. Now, use Bubble Sort to sort the arraycontinuously pushing the largest elements to the right side of the array. Every time you swap two elements in the array, you need to increment a counter. After the inner loop has completed, you need to print out the current state of the array and the total number of swaps that have occurred. Your output should look like the sample outputs shown below. User input is shown in bold. Note: Sample output #1 shows the worst case scenario because it has the maximum number of swaps possible. Sample output #2 shows the average scenario because it has approximately half the number of swaps. Your last step is to create an fstream variable for writing to a file. Call this file Ouput.csv. You need to write each value in the array to this csv file and use a comma to separate each value. Then, close your fstream. Check to make sure youve completed this part correctly by opening the csv file in Excel (or the equivalent), then take a screenshot as evidence that it is working. You will submit this screenshot as part of your lab. Refer to the Appendix for more information. Note: Pay attention to where your project is saved. By default, it will be saved in the same directory as your source code, but it may also be in the Debug directory of your project. Remember where its saved because youll need to know that for Lab8b!

image text in transcribed

Sample output #1 Enter slot 0: 10 Enter slot 1: 9 Enter slot 2: 8 Enter slot 3: 7 Enter slot 4: 6 Enter slot 5: 5 Enter slot 6: 4 Enter slot 7: 3 Enter slot 8: 2 Enter slot 9: 1 98|71615413121110 Num swaps: 9 8171615413121910Num swaps: 17 7161541312111819|10| Num swaps: 24 6541312117189110 Num swaps: 30 543211617181910 Num swaps: 35 413121516171819/10 Num swaps: 39 32141516171819/10 Num swaps: 42 21113141516171819|10| Num swaps: 44 121314151617189/10 Num swaps: 45 1121314151617181910 Num swaps: 45 Sample output #2 Enter slot 0: 5 Enter slot 1: 10 Enter slot 2: 8 Enter slot 3: 2 Enter slot 4: 1 Enter slot 5: 6 Enter slot 6: 7 Enter slot 7: 3 Enter slot 8: 9 Enter slot 9: 4 518211617139|4|10Num swaps: 8 51211617131849|10| Num swaps: 14 2115161317|489|10Num swaps: 18 11215131614171819|10Num swaps: 21 1|235|4161718 91101 Num swaps: 23 11213141516171819|10| Num swaps: 24 1121314151617181910 Num swaps: 24 11213141516171819|10| Num swaps: 24 1121314151617181 9/10 Num swaps: 24 112131415161718 9/10 Num swaps: 24

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2018 Dublin Ireland September 10 14 2018 Proceedings Part 1 Lnai 11051

Authors: Michele Berlingerio ,Francesco Bonchi ,Thomas Gartner ,Neil Hurley ,Georgiana Ifrim

1st Edition

3030109240, 978-3030109240

Students also viewed these Databases questions

Question

2. How will the team select a leader?

Answered: 1 week ago

Question

3. What may be the goal of the team?

Answered: 1 week ago