Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

C++代写 | Assignment: Infection Tracing Database System

C++代写 | Assignment: Infection Tracing Database System


Information of a single patient

For each confirmed Covid-19 patient, he/she has following related information:

  • ID: a unique patient integer ID, assigned to patients according to chronological order (starting from 1)
  • Date of infection: a relative date, the first Covid-19 patient in the database got infected in day 1.
  • Status: current status of the patient, i.e. active, recovered, deceased.
  • Date of recovery or death: a relative date. If the patient is still sick, the date is set to be -1.
  • District: Home location of the patient, i.e. 18 districts in Hong Kong.
  • Infector: Patient ID of the infector who passes the virus to the patient, for cases with unknow source, the infector is set to be -1.

Patient Struct

A Patient struct is defined in patient.h as below. You can imagine, a Patient object can be used to save information of a single patient. The usage of data members, e.g. ID, date_of_infection, current_status, data_recovery_or_death, location, is straightforward. The usage of two pointer data members, next and infectees, will be explained later.

There are a few other user-defined data types in patient.h, e.g. STATUS and DISTRICT, and arrays, e.g. STATUS_NAME[][] and DISTRICT_NAMES. They’re helpful to improve the readability of the code.

enum STATUS{







struct Patient{

int ID;

int date_of_infection;

STATUS current_status;

int date_of_recovery_or_death;

DISTRICT location;

Patient *next;

Patient *infectees;



const char STATUS_NAME[][10] = {“ACTIVE”, “RECOVERED”, “DECEASED”};


const char DISTRICT_NAMES[][30] = { // Present as full name

“Central and Western”,



“Kowloon City”,

“Kwai Tsing”,

“Kwun Tong”,


“Sai Kung”,

“Sham Shui Po”,

“Sha Tin”,


“Tai Po”,

“Tsuen Wan”,

“Tuen Mun”,

“Wan Chai”,

“Wong Tai Sin”,

“Yau Tsim Mong”,

“Yuen Long”



Information of all patients

Information of all patients are store in an encoded text file.

The following sample file stores information of 14 (imaginary) patients, with unique patient ID 1 to 14.

(The sample file is generated randomly. It does not refer to any real information from government data.)


Take line 1 as an example. It stores information of Patient 1. The patient got infected in Day 1, and he is recovered in Day 3. He lives in CW (Central and Western) area. He is a case of unknown source.

The following line 2 stores information of Patient 2. The patient got infected in Day 1. Unfortunately, he deceased in Day 5. He lives in EA (eastern) area. He is also a case of unknown source.

Check the last column (infector) of all 14 patients, you can find Patient 3 and 5 are both directly infected by Patient 1. Patient 1 is the infector, Patient 3 and 5 are direct infectees of him.

We’re curious about whether the virus keep spreading, and it seems YES. Patient 7 and 14 are directly infected by Patient 3. Patient 9, 12 and 13 are further directly infected by Patient 7.

Linked list/Tree Hybrid Data Structure for Patient Database

Taking patient information text file as the input, we wish to build up a data structure to store details of each single patient, while at the same time, describe the chain of infection among all patients.

This is done by building up a hybrid data structure consists of both linked list and tree.

The following hybrid linked list/tree data structure is built up from the sample input file. Each rectangle in the diagram is a Patient node. Here, we’re interested in how the patients are connected (epidemiologically linked) with each other.

The image has typo before (Case 11 should have nullptr for both the infectees pointer and the next pointer.)


Take patient 1 node as an example. It has two pointers, infectees and next. The infectees pointer (in blue) points to a linked list of patients who’re directly infected by patient 1. Patient 1 directly infected patient 3 and 5. So its infectees pointer is the head pointer to a linked list of 2 Patient nodes, one for patient 3 and the other for patient 5.

Similarly, infectees pointer of Patient 3 node is the head pointer of linked list of patient node 7 and 14.

The next pointer (in red) just works as next pointer in the linked list. It points to the next node in the linked list.

The linked list on the top level, which has patient node 1, 2 and 4, is a bit special. This is a linked list of patients who have unknown source.

The root pointer, which points to Patient 1, is important. Once you get the root pointer, you have access to every single Patient node in the data structure.

There are some underlying assumptions for the sample patient file that make the hybrid data structure simple.

  1. Each infectee only has one or unknown infector. Obviously, the infector gets infected in an earlier date than its infectee(s).
  2. Unique patient IDs are assigned to each patient according to chronological order: a patient with smaller patient ID always gets infected in earlier date or the same date as the patient with larger patient ID, regardless of whether these two patients are epidemiologically linked with each other or not.
    • To be clear, there will be no missing IDs among the IDs in the file. So there will not be having sample patient files like ID:{1, 4, 7}, or ID:{1, 2, 3, 6, 7, 9}, ID: {2, 4, 6, 8, 9}.
  3. A patient can only infect others from one day after the infection date, until the date of recovery or death (included).

With the data structure, we can easily trace the chain of infection. If you wish to find out how many patients got infected directly or indirectly by patient, you just follow the downward infectees pointer to figure out different generations of infectees, and then follow next pointer to count how many infectees in each generation.

Again, take Patient 1 as an example, it directly infected Patient 3 and 5 (1st generation). Patient 3 directly infected Patient 7 and 14 (2nd generation). Patient 7 then directly infected Patient 9, 12 and 13 (3rd generation). So, patient 1 infected 7 patients in total.

Given Functions

In the skeleton code, we provide functions which help to build up the hybrid data structure, and print ID of a given patient.

Patient* buildChainInfection(char filename[])

It loads the file with the given filename and generates the hybrid data structure accordingly. The root of the data structure is returned.

========= COVID-19 TRACING DATABASE MENU =========

There is no data in the system

10 —- Load a file to the system

88 —- Quit the program

=========COVID-19 TRACING DATABASE MENU =========

Please enter your option: 10

Please type the file for loading to the database.