Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is the second part of Coding Problem 2. In the first part, you write your header file consisting of the following components. In this
This is the second part of Coding Problem 2. In the first part, you write your header file consisting of the following components. In this part, please implement the last three functions, that is, CalSalesPerStatel) destructArray),and CompSales). Please do your best to write syntactically correct code. For your reference, your header file is required to contain the following items: Declare an enum class or enum variable States to enumerate the 7 states: AZ, CA, CO, NV, OR, UT, and WA. Design and declare a struct Order to describe each sales order as explained above. Design and declare another struct SalesPerState to record the total sales originated from each of the 7 states. The function prototype of addOrder). This function adds this new order to the vector. The function doesn't need to return anything The function prototype of CalSalesPerState). This function has two parameters as well, which are passed in by referenca. The first one is a vector of Order objects that holds all the past orders. The second one is a pointer-based dynamic array of SalesPerState. This function calculates the total sales for each state and stores the calculated results in the array of SalesPerState. It returns the size of the SalesPerState dynamic array. More specifically, your implementation needs to check whether the second parameter holds any memory space first. If the answer is yes, deallocate the space first. Then allocate enough memory space to this dynamic array. Finally, calculate the the total sales for each state by processing the vector of orders and store the calculated results in the dynamic array. The function prototype of destructArrayl). This function receives one parameter, which is a pointer-based dynamic array of SalesPerState. Furthermore, this parameter is passed in by reference. This function deallocates the memory space held by this array. The function prototype of CompSales() that compares two SalesPerState objects based on the values of total sales. This function returns true if the first object's sales is greater than that of the second object's false, otherwise. This is the second part of Coding Problem 2. In the first part, you write your header file consisting of the following components. In this part, please implement the last three functions, that is, CalSalesPerStatel) destructArray),and CompSales). Please do your best to write syntactically correct code. For your reference, your header file is required to contain the following items: Declare an enum class or enum variable States to enumerate the 7 states: AZ, CA, CO, NV, OR, UT, and WA. Design and declare a struct Order to describe each sales order as explained above. Design and declare another struct SalesPerState to record the total sales originated from each of the 7 states. The function prototype of addOrder). This function adds this new order to the vector. The function doesn't need to return anything The function prototype of CalSalesPerState). This function has two parameters as well, which are passed in by referenca. The first one is a vector of Order objects that holds all the past orders. The second one is a pointer-based dynamic array of SalesPerState. This function calculates the total sales for each state and stores the calculated results in the array of SalesPerState. It returns the size of the SalesPerState dynamic array. More specifically, your implementation needs to check whether the second parameter holds any memory space first. If the answer is yes, deallocate the space first. Then allocate enough memory space to this dynamic array. Finally, calculate the the total sales for each state by processing the vector of orders and store the calculated results in the dynamic array. The function prototype of destructArrayl). This function receives one parameter, which is a pointer-based dynamic array of SalesPerState. Furthermore, this parameter is passed in by reference. This function deallocates the memory space held by this array. The function prototype of CompSales() that compares two SalesPerState objects based on the values of total sales. This function returns true if the first object's sales is greater than that of the second object's false, otherwise
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