In this module, a file is provided for you — SortableBag.hPreview the document — that implements a simple
“bag” (unsorted collection of numbers) structure with array storage.
Part 1
Starting with the above template, add a public sort() member function, with these requirements:
It should not return any values or accept any parameters (‘void’ return type)
When called, the function should sort the bag in ascending order with no other changes.
You can use any algorithm from the Ch. 11 readings — your choice (selection, bubble, insertion, merge,
quick or radix sort).
Part 2
To test your new method, write some test driver code (with a new .cpp file) that does the following:
Makes an array of 100 random integers in a range (0-100 or any other reasonable value). Use
srand(time(0)) to seed the random number generator.
Inserts the integers into the bag.
Requests a sort of the bag with your new sort() method from Part 1.s the bag is sorted. First, convert the bag to a vector with the provided toVector() method. Then verify
that v[i] <= v[i + 1] for all elements of the vector v. Outputs the starting array, the ending array, and the result of the test (pass or fail). You can use either a recursive or iterative version of the sort function. Your new .cpp file should #include the provided SortableBag.h with your additions for new method. If you prefer you can put the SortableBag template at the top of your main.cpp and submit a single file. Example Output Your output does not need to be exactly like this, but should contain the same information. Requesting sort... The bag contains 100 items: 4 41 8 32 74 1 14 61 35 13 72 92 11 58 28 65 57 83 15 22 14 77 70 16 11 30 37 17 19 54 64 23 48 24 7 22 78 74 84 13 39 8 57 50 66 86 67 75 21 82 97 35 11 20 3 23 2 40 40 21 46 56 96 46 33 56 69 11 30 5 24 69 13 33 71 32 71 90 7 92 25 57 79 36 77 34 59 79 26 51 52 25 8 48 71 93 56 92 4 86 Here's the new bag... The bag contains 100 items: 1 2 3 4 4 5 7 7 8 8 8 11 11 11 11 13 13 13 14 14 15 16 17 19 20 21 21 22 22 23 23 24 24 25 25 26 28 30 30 32 32 33 33 34 35 35 36 37 39 40 40 41 46 46 48 48 50 51 52 54 56 56 56 57 57 57 58 59 61 64 65 66 67 69 69 70 71 71 71 72 74 74 75 77 77 78 79 79 82 83 84 86 86 90 92 92 92 93 96 97 Sorting verification passed. What to Submit To complete this lab, submit one or two files: 1) The modified SortableBag.h, with your sort method added (from Part 1). 2) The .cpp file of your test driver (from Part 2). If you prefer, you can submit a single file that includes both the class template and main().

Essay Mill

Share
Published by
Essay Mill

Recent Posts

Childbirth

For this short paper activity, you will learn about the three delays model, which explains…

2 months ago

Literature

 This is a short essay that compares a common theme or motif in two works…

2 months ago

Hospital Adult Medical Surgical Collaboration Area

Topic : Hospital adult medical surgical collaboration area a. Current Menu Analysis (5 points/5%) Analyze…

2 months ago

Predictive and Qualitative Analysis Report

As a sales manager, you will use statistical methods to support actionable business decisions for Pastas R Us,…

2 months ago

Business Intelligence

Read the business intelligence articles: Getting to Know the World of Business Intelligence Business intelligence…

2 months ago

Alcohol Abuse

The behaviors of a population can put it at risk for specific health conditions. Studies…

2 months ago