157k views
5 votes
Design and implement a C++ class named CovidDB, which supports:

1. bool add(DataEntry entry)
add() function should insert one data entry into the hash table.
2. DataEntry get(string country)
get() retrieves a data entry with the specific country name(string country). It returns NULL if
no such entry exists
3. void remove(string country)
This function removes the data entry with the specific country name (string country).

A data entry contains the following information:
Class DataEntry{
private:
string date;
string country;
int c_cases;
int c_deaths;
public:
// getters and setters();
...
}
For example, a data entry
10/14/2021, Afghanistan, 155627, 7234
represents: As of 10/14/2021, the cumulative cases and deaths in Afghanistan are 155627 and 7234,
respectively.
Your hash table size is m=17.
Your hash function is defined as:
For example, hash(Japan) is calculated as:
Hash(Japan) = (1*112 + 2*141 + 3*160 + 4*141 + 5*15) % 17 (ASCII : J: 112 a: 141 p:160 a: 141
n:156).
You need to use separate chaining as the technique to solve collision in hash tables.
Steps to finish it:
1. You should implement your hash table first. You can try some fake data entries to play around
to test functions add(), get(), and remove().
2. Import WHO-COVID-Data.csv, and use the data entries there to build your initial hash table.
Please pay attention that this file shows you the new cases and deaths on a certain day. For
example, line 326 in the table shown below indicates that on 11/23/2020, the new cases and
new deaths in Afghanistan were 203 and 12, respectively.
int hash(string country) {
int sum = 0;
for each character c at position i in string country{
sum = ⅀(i * c) % m; // m is the hash table size, c is the ASCII code for char.
}
return sum;
}

After loading WHO-COVID-Data.csv into your program, you need to find a way to get the
cumulative cases and deaths by the last day shown in your CSV file and insert the cumulative
cases and deaths by this date. For example, in WHO-COVID-Data.csv, line 1 – line 651 shows
daily COVID-19 new cases and deaths in Afghanistan from 1/3/2020 to 10/14/2021. Your entry
to your hash table should be:
10/14/2021, Afghanistan, 155627, 7234
instead of all the daily data entries. In other words, each country only has one data entry in
your hash table.


3. After the creation of your initial hash table, you should revise your add() to reflect any update
later made to the hash table. Suppose after creating your initial hash table successfully using the
WHO-COVID-Data.csv, the data entry for Afghanistan is
10/14/2021, Afghanistan, 155627, 7234
Now we want to insert another data entry that
a. The date is later than the existing data entry date.
b. The country already existed.
You should update your hash table accordingly. For example, add a data entry
10/15/2021, Afghanistan, 40, 3
The hash table should be updated with:
10/15/2021, Afghanistan, 155667,7237
If the date is earlier than the date in the current hash table, we just ignore the new entry.
4. Provide a user interface to allow users to operate on your hash table continuously. For
example,
// Covid Tracker
// Please choose the operation you want:
// 1. Create the initial hash table
// 2. Add a new data entry
// 3. Get a data entry
// 4. Remove a data entry
// 5. Display hash table
// 0. Quit the system
When you choose 1, the hash table is created based on WHO-COVID-Data.csv. Operation 2, 3,
and 4 are based on the hash table you create in Operation 1

User Nepoxx
by
8.0k points

1 Answer

4 votes

Final answer:

The C++ CovidDB class is designed to manage a hash table of COVID-19 data entries. It provides functionalities to add, retrieve, update, and remove data based on country and date. It processes cumulative data from a CSV file and user inputs, updating entries with newer information as required.

Step-by-step explanation:

The task involves designing and implementing a C++ class named CovidDB to manage COVID-19 data using a hash table with separate chaining collision resolution. The CovidDB class should support operations to add, retrieve, and remove DataEntry objects, each representing a country's COVID-19 data on a specific date. Additionally, the class should be able to parse cumulative data from a CSV file and update entries with more recent data.

To implement this, you would define the DataEntry class with appropriate private members for date, country, cumulative cases, and deaths, along with the necessary getters and setters. The CovidDB class would then contain a hash table of DataEntry lists, keyed by country names. The add() function inserts a new entry or updates an existing one, get() retrieves an entry by country, returning nullptr if not found, and remove() deletes an entry by country.

The hash function provided will calculate a unique index for each country. To build the initial table, you should process the WHO-COVID-Data.csv to sum up cumulative cases and deaths by the latest date in the file for each country and insert these as single entries in the hash table. The add() function should be later modified to accommodate updates that reflect new, more recent data. The instructor interface would provide the user with options to interact with the CovidDB instance, initiating these operations.

User Harry Blue
by
8.2k points