Question
Create a Sorting Virtual Tablev in C++ by providing a set of functions that enable the virtual sorting of a table by values in a
Create a Sorting Virtual Tablev in C++ by providing a set of functions that enable the "virtual" sorting of a table by values in a column. Virtual sorting means that the table itself will remain unchanged while a different view of the table provides a sorted version. A typical solution to this problem is to use a collection of pointers that reference the rows of the table and then sort the collection based on values in the table. For example, consider the figure below:
For this assignment you will create a set of functions that read a table from a text file and enable access to the table in a sorted fashion based on values in a specific column. Your program will consist of exactly three functions plus the main (do not define others) and they must be implemented as described.
void importTable(string filepath, int** &table, int& rowCount, int& colCount); This function reads the table stored in the file at the specified location. The file is expected to have the following form
The first line consists of a single integer, R, that indicates the number of rows in the table.
The second line consists of a single integer, C, that indicates the number of columns in the table.
The remainder of the file will contain the table values. The file consists of R more lines and each of those lines with have C integers separated by spaces, potentially more than one.
No two rows will share the same initial value (think of them as unique ids)
For example,
4 6 1 5 2 34 13 1 42 9 34 11 5 -1 12 8 20 1 25 0 9 6 17 23 5 1
The function will dynamically create an appropriately sized array and place the table values from the file into the array. The row and column count (rowCount and colCount, resp.) will be updated to reflect the dimensions of the array.
void sort(int** rowReferences, int rowCount, int colCount, int sortColumn); This function sorts the row references such that the values in column number sortColumn are in ascending order. The sorting is ascending and is performed using a select sort. This function assumes 0 sortColumn
void showTable(int** table, int rowCount, int colCount); This function displays the table. There is no specific format for the output, just make the output look tidy - evenly spaced columns and such.
Your main should focus on testing the functions. Load a table, initialize a reference array that references the table rows, display the table via the reference array, sort the reference array, and display the sorted results. It doesn't have to be more involved than that but try different table sizes and columns (esp. tables with one row and/or one column!).
(GLOBAL VARIABLES MAY NOT BE USED)
Initial array Sorted on the third columnStep 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