Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

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
Execution example
This program is partially developed, and you can find all the files in the file directory.
Your task is to complete the code as stated in the comments in the source code.
The Code
The structure holding the customers' records is designed as follows:
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
struct Customers {
char* Package_Name;
int user_id;
double timeinhours;

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.
int dayofyear;
int Fwifitime;
int Fctime;
char dayofweek;
};
dayofweek, user_id, timeinhours, dayofyear, Fwifitime, Fctime,
Package_Name<NEWLINE>
T 2 0.030551111 121 1989 107995 com.android.chrome
F 0 1.669860278 122 6010276 1221 com.UCMobile
F 5 1.478770556 122 3233672 2089902 com.UCMobile
S 0 0.721798889 124 248535 2349941 com.UCMobile
S 8 0.098520556 124 354674 0 com.uu.uunavi
S 2 0.087850556 124 0 316262 com.zhihu.android
M 3 0.107762222 125 0 387944 cn.coupon.kfc
M 8 6.175799722 125 20623140 1609739 com.android.chrome

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
student number 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.
Package Module
The Package Module has two global variables:
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.
fscanf(fp, "%60[^\n]\n", ......
fscanf(fp, "%d,".......
fscanf(fp, "%lf,",......
fscanf(fp, "%[^ \t\n\r\v\f,]%*c",......
1. int no_of_traces;
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.
Otherwise return true.
Implement the following two functions:
1.
2. Customers* users;
Error reading the records, Check the data file.

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.
If you have any additional custom code, (i.e. functions, classes etc) that you want to
reuse in this project save them under a module called Utils ( Utils.cpp and
Utils.h )
Data Entry
No data entry
To test and demonstrate execution of your program use the same data as shown in the
main.h
main.cpp
Package.h
Package.cpp
Tools.h
Tools.cpp
....
Custom code submission
If you have any additional custom code, (i.e. functions, classes etc) that you want to
reuse in this project save them under a module called Utils ( Utils.cpp and Utils.h )
and submit them with your project using the instructions in the

Data Entry
No data entry

You might also like