Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have to write a C++ code for a program sorting numbers in descending order. Appreciate if you could help. Thanks. Your job for this

I have to write a C++ code for a program sorting numbers in descending order.

Appreciate if you could help. Thanks.

Your job for this assignment is to produce a program that sorts a list of numbers in descending order. Your program will need to read-in, from a file, a list of integers at which point you should allow the user an option to choose to sort the numbers in descending order via one of the two Sorting algorithms that we have explored (Insertion/Bubble). Your program should use the concept of Polymorphism to provide this sorting feature. As output, you will display the sorted list back to the user. A secondary task of this assignment is to provide runtime analysis of your program. You will provide in a separate text file the Big-O of the two sorting algorithms that we have implemented in this assignment. This program will be written in C++

Your program will be menu driven in which you will provide the following prompts to the user: 1. Load Integers (From File) 2. Exit Program Once the user has loaded the list of integers the following options should be provided: 1. Insertion Sort 2. Bubble Sort 3. Exit Program The text file containing integer data will be provided to you. The filename will be data.txt this file can be found (and downloaded) on Canvas. The file will contain fifty integers (50) and they will be comma separated on a single line.

You are required to implement the following items as part of this assignment: Your program must contain at-least four (4) classes. o Driver o Sort o Insertion Sort o Bubble Sort You must use the concepts of Inheritance and Polymorphism in order to complete this assignment. o Your Sort class must be a pure virtual class. o You should use proper OO approaches to implementing Inheritance. It is recommended you use stringstream to read-in and parse the data file. Your sample output must match that shown below note that in order to re-sort the list you must also re-load the data file. You are required to use an Array to store the data read-in from the file. You are required to use the Heap to store your Objects in memory. You program should have no memory leaks a memory leak will result in a deduction of points. o Make sure to run Valgrind against your submission to check for memory leaks and include this report with your submission. You are required to provide a brief (about one paragraph per algorithm) overview/analysis of the Big-O runtime of your program with respect to the two sorting algorithms we are implementing as part of this assignment we will cover this in brief overview in lecture, you will need to provide some additional external research on your own to complete this assignment.

Below is the output of what your program should display when executed: 1. Load Data (From File) 2. Exit Program Please enter your selection: 1 Unsorted Array: 39, 14, 100, 16, 93, 24, 62, 68, 52, 76, 86, 48, 15, 41, 83, 55, 18, 30, 74, 7, 31, 44, 67, 81, 70, 27, 53, 59, 61, 19, 56, 35, 88, 58, 72, 98, 38, 64, 94, 69, 50, 46, 78, 6, 57, 89, 26, 20, 79, 49 1. Insertion Sort 2. Bubble Sort 3. Exit Program Please enter your selection: 1 Insertion Sort: 100, 98, 94, 93, 89, 88, 86, 83, 81, 79, 78, 76, 74, 72, 70, 69, 68, 67, 64, 62, 61, 59, 58, 57, 56, 55, 53, 52, 50, 49, 48, 46, 44, 41, 39, 38, 35, 31, 30, 27, 26, 24, 20, 19, 18, 16, 15, 14, 7, 6 1. Load Data (From File) 2. Exit Program Please enter your selection: 1 Unsorted Array: 39, 14, 100, 16, 93, 24, 62, 68, 52, 76, 86, 48, 15, 41, 83, 55, 18, 30, 74, 7, 31, 44, 67, 81, 70, 27, 53, 59, 61, 19, 56, 35, 88, 58, 72, 98, 38, 64, 94, 69, 50, 46, 78, 6, 57, 89, 26, 20, 79, 49 1. Insertion Sort 2. Bubble Sort 3. Exit Program Please enter your selection: 2 Bubble Sort: 100, 98, 94, 93, 89, 88, 86, 83, 81, 79, 78, 76, 74, 72, 70, 69, 68, 67, 64, 62, 61, 59, 58, 57, 56, 55, 53, 52, 50, 49, 48, 46, 44, 41, 39, 38, 35, 31, 30, 27, 26, 24, 20, 19, 18, 16, 15, 14, 7, 6 1. Load Data (From File) 2. Exit Program Please enter your selection: 2 Goodbye!

data.txt :

39,14,100,16,93,24,62,68,52,76,86,48,15,41,83,55,18,30,74,7,31,44,67,81,70

,27,53,59,61,19,56,35,88,58,72,98,38,64,94,69,50,46,78,6,57,89,26,20,79,49

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions