You are to implement a C++ class that can read a text file containing the number of cases of the ongoing Covid-19 pandemic in different countries and answer some questions based on the data. The file...


You are to implement a C++ class that can read a text file containing the number of cases of the ongoing Covid-19 pandemic in different countries and answer some questions based on the data. The file is in the following format:



Example data (also in exampledata.txt)



Column 1 is the Country name, column 2 is the number of days since the first case, and column 3 is the number of cases. E.g., Afghanistan had 1 case on Day 0 and 5 cases on Day 15. Note that the data may not be sorted.


Implement your logic within a class CovidData. The class should have the following public member functions:



  1. CovidData(): the default constructor

  2. int readData(string filename):method which takes in a filename and reads in the data to its member variables. It should return the number of lines that were read from the file. E.g., for the example file above, readData should return 16.

  3. int getDays(string country):given a country name, return the number of days with cases in that country (i.e., the maximum number of days for that country). E.g., for the example file above, getDays (“Afghanistan”) should return 16; getDays (“Andorra”) should return 5. If the country does not exist, return -1.

These public member functions will be called from the provided main program and the answers printed there.

You are free to add other (public/private) member variables and functions to class CovidData, and any other structs/classes as needed.



  • You can implement all your code either in one header file called CovidData.h or split the declaration and definition in CovidData.h and CovidData.cpp

  • Class and filenames are case-sensitive. The class and filenames should be CovidData (not Coviddata, coviddata, …)

  • You can modify the main function to test your code with different input cases to make sure the logic will work in the general case - we will test your code with different text files which will contain different countries and days not included here.

  • Country names are strings are a single word without spaces. Hence, each line can be read like so:



    • mystream >> mycountry >> ndays >> ncases;




Data structure resources:



  • You are strongly encouraged to use the C++ Standard Library containers.



  • However, you are also given files containing templates for a Vector, singly and doubly linked list, Stack, and a Queue. For these data structures, you are also provided with a test program.You may use none, any, or all of them if it will help you. You are also free to edit any of these files. These files are posted in the “Data structure files for Part 2 (OPTIONAL)” section.


Documentation:



  • A short description of your approach. This should be turned in as a long comment at the beginning of CovidData.h.Make clear what, if any, data structures you use and their roles.


File submission:Uploadas separate files (do not zip):



  1. CovidData.h

  2. CovidData.cpp (if used)

  3. Any additional files that you wrote or edited.

Mar 27, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here