Question
C++ Question Hello, I basically have this program done but I need help getting the last 2 functions to do what they're supposed to do.
C++ Question
Hello, I basically have this program done but I need help getting the last 2 functions to do what they're supposed to do.
My code can be found here: https://pastebin.com/TdwAkfyQ
I need the two functions int* allocate(int rows, int cols, ifstream & inFile) and void restructure(int *array, int rows, int cols, int *&at) finished. I started both of them but if you want to start over on them, that's fine. Once finished please make sure the entire thing compiles in preferably Visual Studios. Here is what the assignment is asking:
data.dat will look something like this:
It will be numbers in an array form, but the array can be any size.
Create a program that reads from the file (data.dat) the dimension sizes and data for a dynamically allocated two dimensionn sparse matrix. The first row of the file will contain the dimension sizes and the each following row will contain the data for the row. This file (data.dat) will contain multiple arrays. This program needs to be able to read and process each array until the file is empty. The program wil dynamically allocate the array, read the values for the complete array (INCLUDING O VALUES), print out the given array and be able to transform the array (this will be shown below). (You can create data.dat however you'd like, just make sure it gives numbers to use for the matrix) Write a function to print the original matrix as entered including the zero values. Pass to the function the address of the block of memory and the size of the matrix. Write a function to dynamically allocate block of memory and store the data from the file in the block of memory. Pass to the function the dimension sizes of the matrix. Return the address of the block of memory that was allocated and filled with the data from the file Write a function to restructure the sparse matrix, create an access table, and remove the zero values from the matrix. The restructuring should take all 0 values and put them at the end (as shown down below). Move the data in the dynamically allocated block of memory so that the non-zero values occupy consecutive elements of the array beginning with element zero of the array. (DO NOT create an additional structure in which to store the non-zero values.) Create an access table where the number of elements in the table is the number of rows in the sparse matrix plus one. The last element of the access table will contain the number of elements in the dynamically allocated array (sparse matrix) after you have shifted the data (removed the zeros) in the array. Do not resize the array after you have shifted the data and do not zero out any elements of the array. Pass the address of the access table by reference to the last argument in the call statement to this function. Write a function to print the access table and sparse matrix without the zero values as shown in the example below. If a row of the sparse matrix had all zeros, do not display any values for the matrix, just print the value in the access table for that row. Print the last value in the access table as shown in the example. Align the numbers in the display Please don't use global variables It should take the matrix as given below, and be able to only take the non O numbers. It should place the O's at the end of the matrix 10011 14009 12052 10210 11101 Create a program that reads from the file (data.dat) the dimension sizes and data for a dynamically allocated two dimensionn sparse matrix. The first row of the file will contain the dimension sizes and the each following row will contain the data for the row. This file (data.dat) will contain multiple arrays. This program needs to be able to read and process each array until the file is empty. The program wil dynamically allocate the array, read the values for the complete array (INCLUDING O VALUES), print out the given array and be able to transform the array (this will be shown below). (You can create data.dat however you'd like, just make sure it gives numbers to use for the matrix) Write a function to print the original matrix as entered including the zero values. Pass to the function the address of the block of memory and the size of the matrix. Write a function to dynamically allocate block of memory and store the data from the file in the block of memory. Pass to the function the dimension sizes of the matrix. Return the address of the block of memory that was allocated and filled with the data from the file Write a function to restructure the sparse matrix, create an access table, and remove the zero values from the matrix. The restructuring should take all 0 values and put them at the end (as shown down below). Move the data in the dynamically allocated block of memory so that the non-zero values occupy consecutive elements of the array beginning with element zero of the array. (DO NOT create an additional structure in which to store the non-zero values.) Create an access table where the number of elements in the table is the number of rows in the sparse matrix plus one. The last element of the access table will contain the number of elements in the dynamically allocated array (sparse matrix) after you have shifted the data (removed the zeros) in the array. Do not resize the array after you have shifted the data and do not zero out any elements of the array. Pass the address of the access table by reference to the last argument in the call statement to this function. Write a function to print the access table and sparse matrix without the zero values as shown in the example below. If a row of the sparse matrix had all zeros, do not display any values for the matrix, just print the value in the access table for that row. Print the last value in the access table as shown in the example. Align the numbers in the display Please don't use global variables It should take the matrix as given below, and be able to only take the non O numbers. It should place the O's at the end of the matrix 10011 14009 12052 10210 11101
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