Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am doing C++ Programming workshops from udemy and while I do understand the basic theory being taught, I am having trouble working on this
I am doing C++ Programming workshops from udemy and while I do understand the basic theory being taught, I am having trouble working on this lab with the online submitter:
Here is a pastebin with the program so far, I have made the structures and the main body but the fill ins I am stuck with: https://pastebin.com/NuAjut6q
I am NOT allowed to use any other libraries other than the ones listed for this C++ Program
LAB Execution example Records were retrieved successfully Data records were grouped by the user id successfully User id, timeinhours, Fctime, Fwifitime, Package Name 0,1.49325,369926,5005762, com. tencent.mm 0,1.35947,172756,4721320, com. tencent.mm 0,1.66986,1221,6010276, com. UCMobile 5,1.60287,5722288,48042, com.sina.weibo 5,1.92426,260011,6667309, com.tencent.mm 5,1.47877,2089902,3233672, com. UcMobile 9,1.02618,288007,3406229, com. digiplex.game 9,1.23554,59991,4387945, com.tencent.mm 9,12.9425,2190642,44402341, com.tencent.mm 9,1.21251,2544077,1820967, com.tencent.qqmusic Data was successfully printed Dynamically allocated memory was successfully deallocated The Code The structure holding the customers' records is designed as follows: struct Customers \{ char* Package_Name; int user_id; double timeinhours; int dayofyear; int Fwifitime; int Fctime; char dayofweek; \}; In addition to holding the customer records in an dynamically allocated array of Customers, each Package's name is also held in a dynamically allocated Cstring in the Customer structure. dayofweek, user_id, timeinhours, dayofyear, Fwifitime, Fctime, Package_Name The Program Modules There are three modules in the program: Tools, Package and main Tools Module The following three functions are already implemented in the Tools module: 1. openFile_r Opens the data file for reading 2. closefile Closes the data file 3. noOfTraces Returns an integer that is the number of records in the opened and read file; use this function in the Package module to determine the size of the dynamic array of customers. Your coding tasks in the Tools module: Implement 4 overloads of a function called read 1. read function for the Package name: When success, returns a Cstring argument to send back the name of the Package. Use the following fscanf function to read the name of the Package from the file. 2. read function for the user_id, dayofyear, Fwifitime and Fctime: When success, returns a reference argument to an integer to pass back the user id, dayofyear,Fwifitime and Fctime. Use the following fscanf function to read the user_id, dayofyear, Fwifitime and Fctime from the file and return true if it returns 1. fscanf(fp, "\%d,"....... 3. read function for the timeinhours: When success, returns a reference argument to a doubler number to pass back the timeinhours. Use the following fscanf function to read the timeinhours from the file. fs 4. read function for the dayofweek: When success, returns a reference argument to a char to pass back the dayofweek. Use the following fscanf function to read the dayofweek from the file. \[ \text { fscanf(fp, "\%[^ } \backslash t \backslash n \backslash r \backslash v \backslash f,{ }^{*} \%^{*} c^{*}, \ldots \ldots \] Package Module The Package Module has two global variables: 1. int no_of_traces; no_of_traces should hold the number of records read from the file and thus it should be used later to allocate the dynamic array of Customers. 2. Customers* users; This Customers pointer should point to the dynamic array of users. Functions The following function is already implemented in the Package module: grouptTraces() This function groups the records in the dynamic array of users based on the user_id in ascending order. Complete the implementation of the following two functions: 1. loadTraces This overload of the loadTraces function returns a bool and receives a Customers reference. In a local array of 50 characters, it will try to read the Package name from the file. If successful it will find the actual length of the Package name using the strlen function and then add one to the length (for null termination) and allocate the same amount of characters in the name of the Customers reference. Then it will copy the read name (from the local character array) into the newly allocated name of the Customers reference using strcpy. If all the reads were successful, it will return true, otherwise false. 2. loadTraces This overload of the loadTraces function loads all the users records into the Customers array and returns a bool for success and has no arguments. First open the data file. Then set the number of users to the number of records in the file and then allocate a dynamic array of users pointed by the global Customers pointer; "users" to the number of the records in the file. Then load the users one by one from the file into the dynamic array of users. If the number of read records does not match the number of records, display the following error message and return false. Error reading the records, Check the data file. Implement the following two functions: 1. display This function does not receive or return anything. This function displays customer records one by one (each record in a new row) based on the following condition: (timeinhours >1.0 and dayofweek = = 'F'). See the sample output. 2. deallocateMemory This function does not return or receive anything. In a loop go through all the elements of the users array and deallocate the dynamic Package_Name of each user. Then deallocate the whole users array. main Module. Please do not modify the main Module
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