25.0k 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:
You should implement your hash table first. You can try some fake data entries to play around to test functions add(), get(), and remove().

User Dannymac
by
7.7k points

1 Answer

4 votes

Final answer:

The CovidDB class includes add, get, and remove functions, working with a hash table using separate chaining for collision resolution, and manipulates data entries for COVID-19 statistics by country.

Step-by-step explanation:

In designing a C++ class named CovidDB, which involves operations on a hash table with separate chaining to handle collisions, the class should support methods to add, retrieve and remove data entries based on country names. Each DataEntry object will have attributes for date, country, cumulative cases, and deaths along with necessary getters and setters.

The add() function inserts a new data entry into the hash table, returning true if successful. The get() function retrieves a data entry based on a given country name; if no entry exists, it returns NULL. The remove() function deletes the data entry corresponding to the given country.

The hash function takes a string (a country name) and computes an index based on the ASCII values of the characters in the string and their position. To test the correctness of these functions, you should first implement the hash table and then create some fake data entries to use with the add, get, and remove operations.

User Wayne Werner
by
7.4k points