Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Must be written in C++ Please following instructions carefully Must contain the following main.cpp, Package.cpp, Package.h, Tools.cpp and Tools.h file Correct Output Part 1 -

Must be written in C++

Please following instructions carefully

Must contain the following main.cpp, Package.cpp, Package.h, Tools.cpp and Tools.h file

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Correct Output

image text in transcribed

Part 1 - LAB (50\%) Customers ' main report is a program that reads records of behavioral profiles of using Android applications of a number of Customers from a file and holds these records in a dynamically allocated array of Customers. (Each record holds the app's identifier (Package_name), The user's identifier (user_id), spent time in hours (timeinhours) , day of the year (dayofyear), spent foreground Wi-Fi network connection time(ms)(Fwifitime), and day of week (dayofweek), spent foreground cellular network connection time(ms) (Fctime), in a .csv file format.) After loading all the information into a dynamic array of Customers, the program will groups the records based on the user_id in ascending order LAB Execution example Records were retrieved successfully Data records were grouped by the user id successfully User id, timeinhours, Fctime, Fwifitime, Package Name This program is partially developed, and you can find all the files in the lab directory. Your task is to complete the code as stated in the comments in the source code. 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. Data file Here is a sample of the data csv file in the following format: 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. fscanf(fp,"%60[ ] ", 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 . 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. 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. fscanf (fp,"%[ |t \v\f,%c, 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. Otherwise return true. 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. Records were retrieved successfully Data records were grouped by the user id successfully User id, timeinhours, Fctime, Fwifitime, Package Name 0,1.49325,369926,5065762,com.tencent.mm0,1.35947,172756,4721320,com.tencent.mm0,1.66986,1221,6016276,com.ucmobile5,1.60287,5722288,48042,com.sina.weibo5,1.92426,266011,6667309,com.tencent.mm5,1.47877,2089962,3233672,com.ucmobile9,1.02618,288007,3406229,com.digiplex.game9,1.23554,59991,4387945,com.tencent.mm9,12.9425,2190642,44402341,com.tencent.mm9,1.21251,2544077,1820967,com.tencent.qqmusic

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions

Question

Describe how we perceive depth in three-dimensional space.

Answered: 1 week ago

Question

=+6. Did your solution clearly highlight the main consumer benefit?

Answered: 1 week ago