Page 1 of 1

Problem 3 [20 points] Multi-dimensional Arrays A data cube is first implemented using a static 3D array as shown in "dat

Posted: Thu May 26, 2022 9:26 am
by answerhappygod
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 1
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 1 (55.73 KiB) Viewed 15 times
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 2
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 2 (55.73 KiB) Viewed 15 times
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 3
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 3 (48.7 KiB) Viewed 15 times
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 4
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 4 (52.25 KiB) Viewed 15 times
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 5
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 5 (54.58 KiB) Viewed 15 times
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 6
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 6 (48.7 KiB) Viewed 15 times
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 7
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 7 (87.19 KiB) Viewed 15 times
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 8
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 8 (63.02 KiB) Viewed 15 times
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 9
Problem 3 20 Points Multi Dimensional Arrays A Data Cube Is First Implemented Using A Static 3d Array As Shown In Dat 9 (49.54 KiB) Viewed 15 times
Problem 3 [20 points] Multi-dimensional Arrays A data cube is first implemented using a static 3D array as shown in "data cube.h": /File: data cube. */ #include <iostream> #include <cstring> using namespace std; const int NUM MONTH - 12; const int NUM SHOP = 5: const int NUM PRODUCT = 3; const NUM_CHAR = 10; struct data cube { char arr_month [NUM_MONTH] [NUM_CHAR]; char arr shop [NUM SHOP] [NUM_CHAR]: char arr product [NUM PRODUCT] [NUM CHAR]: int data [NUM_MONTH] [NUM SHOP] [NUM PRODUCT]; }; // Functions using a data_cube object void read_data_cube (data_cubek); int search sales (const data_cubek, const char[], const char , const char[]); int total sales_shop(const data cube, const char []); A data cube object records the sales data in the 3D array declared in the struct which the three dimensions are related to Products. Months and Shops
watconst data cubek, const char[]), const char), const char[]); int total sales_shop(const data cubes, const char[]): A data cube object records the sales data in the 3D array declared in the struct data_cube, in which the three dimensions are related to Products. Months and Shops. The following diagram shows the concept. For example, we can find out in the shop Cecial, how many cans of coke are sold in Jan. egg apple coke Products December Sales Data apple Cindy Cecial Shops cecia2 January Sales Data dec Gary Wilfred Months jan In this question, we use a data_cube object to record the sales quantity (in integers) of a product at a shop in a month. A set of functions are implemented to compute required information from the sales data. The dimensional information (i.e. Products. Shops, Months) are stored in the following three 1D char arrays as shown in struct data cube: ecc coke
A data cube object records the sales data in the 3D array declared in the struct data_cube, in which the three dimensions are related to Products, Months and Shops. The following diagram shows the concept. For example, we can find out in the shop Cecia1, how many cans of coke are sold in Jan. egz apple coke Products December Sales Data Cindy Cecial Shops cecia2 January Sales Data dec Gary Wilfred Months jan In this question, we use a data_cube object to record the sales quantity (in integers) of a product at a shop in a month. A set of functions are implemented to compute required information from the sales data. The dimensional information (i.e. Products, Shops, Months) are stored in the following three 1D char arrays as shown in struct data_cube: char arr_month [NUM_MONTH] [NUM_CHAR); which stores the month names. e.g. "jan", "feb", "mar": "apr", "may", "jun", "jul", "aug" "sep", "oct", "nov", "dec". egg apple coke
required information from the sales data. compute The dimensional information (i.e. Products. Shops, Months) are stored in the following three 1D char arrays as shown in struct data_cube: . char arr_month [NUM_MONTH] [NUM_CHAR]; which stores the month names, e.g. "jan", "feb, "mar", "apr", may" "jun", "jul", "aug": "sep", "oct", "nov", "dec". . char arr_shop [NUM_SHOP] [NUM_CHAR]: which stores the shop names. e.g. "Cindy", "Cecia1". "Cecia2". "Gary" "Wilfred" char arr product [NUM_PRODUCT] [NUM_CHAR]: . which stores the product names, e.g. "egg", "apple". "coke". In the main(), we first call the function void read_data_cube (data_cube &) to construct a data_cube object by reading the sales data in the monthly files (i.e. jan.txt, feb.txt..... dec.txt), each integer means the quantity of a product sold (Le. column order of product names are defined in arz product) by a shop (i.e. row order of shop names are defined in arr_shop). Then, we can use the functions. void search sales (const data_cubes, const char(), const char[], const char[]) and int total_sales_shop (const data_cubes, const char[]).to compute the required information from the sales data. #include "data_cube.h /File: main.cpp/ 10s main() ( data cube salesdata;

*52), to compare two given C strings s1 and s2. It returns zero if the two strings are the same. (a) [4 points) Search sales data using a month name, a shop name and a product name as parameters. We search and output the sales quantity for an input of a month name, a product name and a shop name. See the "Test case for Part (a)" for using the function. You may assume the input parameters have no error. (b) [4 points] Compute the total sales of a given shop. We compute the total sales of all the products and all the months by a given shop name. See the "Test case for Part (b) for using the function. If the input shop name does not exist, you should just return a zero integer. (c) [12 points] Change from static array to dynamic array for storing the sales data. We now remove the line of declaring the static array in the struct data_cube. The following statement in the struct is deleted. int data [NUM_MONTH] [NUM_SHOP] [NUM_PRODUCT]; We then replace the above line with a dynamic array declaration as follows: int" data; This change only affects main () but not other functions. You are required to write the code for the following two new functions and modify the original main () due to the change. (1) [5 points] Allocate memory space for the dynamic array and output the following message after the allocation is done: "Dynamic 3D array data is
int data[NUM MONTH] [NUM SHOP][NUM_PRODUCT]; We then replace the above line with a dynamic array declaration as follows: int*** data; This change only affects main () but not other functions. You are required to write the code for the following two new functions and modify the original main () due to the change. (i) (5 points) Allocate memory space for the dynamic array and output the following message after the allocation is done: "Dynamic 3D array data is created!" Write the code for the new function: void allocate dynamic data (data_cubes); (ii) (5 points) Deallocate memory space for this array and output the following message after the deallocation is done: "Dynamic 3D array data is destructed!". Write the code for the new function: void deallocate_dynamic_data (data_cubes); (ili) (2 points] Add appropriate statements to main () so the dynamic array can be used. Add your code under Steps 1 and 2 in the main function, int main() in: main() data cube salesdato: /* Step 1: Add your code bere / // Populate the array read data, cube (anlmadata);
(ii) [5 points] Deallocate memory space for this array and output the following message after the deallocation is done: "Dynamic 3D array data is destructed!". Write the code for the new function: veid deallocate dynamic data (data cubes); (iii) [2 points] Add appropriate statements to main () so the dynamic array can be used. Add your code under Steps 1 and 2 in the main function, int main() int main() data_cube salendata: Step 1: Add your code here / // Populate the array read_data_cube (salesdata); // Teat case for Part (4): char shop:[] = "Cecial": char monthl] - "jan"; char product10] - coke: cout <<search sales(salesdata, nonthi, shopi, product1) << endl; // Tess case for Part (b): char nane20] - "Gary": cout << total_sales_shop(salendata, cane2) << endl; / Stop 21 Add your code here /