Infection spreads across the land. Cities are now being monitored by the CDC. The CDC is keeping a list of infected cities and applying an infection level to each city.
- You’ll read in from a file a list of cities (with name, population, and current infection level).
- As your adding cities to your list, you must keep them sorted by population (descending order)
- You’ll then prompt the user for what happens next (see below):
- User options:
- Increase the infection level of all cities by 1
-Increase the infection level of a specific city by 1
- Print the status of a city (searched by name)
- Print all cities above a certain infection level
- Create quarantine log
- Save all quarantined cities information to a file named by the user
- Format must match that of the input file
- Repeat all option until the user wants to exit
- Increase the infection level of all cities by 1
- User options:
- Monitor the user’s actions take any needed actions based on a city’s infection level
|Infection level||required action(s)|
|1||Remove this city from the list|
|1||Decrease the population by 10% (round down)|
|1||Add it back to the list (this helps keeps the list sorted by population)|
|2||Remove this city from the list|
|2||Decrease the population by 20% (round down)|
|2||Add it back to the list (this helps keeps the list sorted by population)|
|3||Take 25% (round down) of the population and form a new city (both cities should be removed and added back to the list as before)|
|4||All hope is lost for the city|
|4||The city is removed from the infected list and moved to the quarantined list (with it’s remaining inhabitants).|
|4||A message “City X has been placed in quarantine” is printed to the screen|
|4||This city can no longer be interacted with other than to be saved in the quarantine log|
- When forming a new city…
- the infection level will reset to zero
- the name will always be the name of the old city with a “New” in front (e.g. New Lawrence, new Kansas City, etc.)
- It’s okay to have a “New New New Lawrence”
- Once a city is moved to quarantine, it does not change infection level or population
- Both lists should be ordered by population (descending). Rank by infection level then alphabetically by name in a tie.
- At least one city needs be quarantined before the user can make the quarantine log
The input will with be organized in the following way: city, population, current infection level
Lawrence,85483,3 Kansas City,1500000,2 Smallville,23,0
- No actions need to be taken upon reading the file. Only take action based on user interaction
- City names may contain spaces
- Populations will always be a whole number
- Files will always be properly formatted
- There is no count of entries at the top. You’ll need to read until end of file is reached.
This is a sample interaction with the provided sample input file.
Make a selection: 1) Increase infection level of all cities 2) Increase infection level of specific city 3) Print status of a specific city 4) Create quarantine log 5) Print all cities above an infection level 6) Exit Choice: 2 Which city do you want to infect?: fake town Sorry, "fake town" is not a city in the list. Make a selection: 1) Increase infection level of all cities 2) Increase infection level of specific city 3) Print status of a specific city 4) Create quarantine log 5) Print all cities above an infection level 6) Exit Choice: 2 Which city do you want to infect?: Lawrence Infection level for "Lawrence" increased by 1 Make a selection: 1) Increase infection level of all cities 2) Increase infection level of specific city 3) Print status of a specific city 4) Create quarantine log 5) Print all cities above an infection level 6) Exit Choice: 1 The infection level for all cities has been increased. Lawrence has been placed in quarantine!
- MedicalExecutive class
- Reads in the initial list of cities
- Maintains the infected cities list and the quarantined cities list
- Note: The LinkedList specification is entirely positional, so this class will need to use the available list methods to maintain the required ordering by population
- Handles User Interaction
- City class
- Holds the information for one city
- Implement getters, setters, and constructors that make sense
- List implementation
- Use your List and Node implementations from Lab 2
- The file format we are using is called a “comma-separated value” file or CSV. It’s a common format for storing data in a text file. we used it in lab 01 as well. Is there any code from your lab 01 you can reuse to help handle the file reading? If not, explain. If so, what form does the code take (e.g. a block you copy and paste, a method, a class, etc.)
- Design a file reader class that specializes in reading CSV files. Make a list of methods you want it have. You do not have to actually implement this class, but if you start to think it would be handy, feel free to make a working implementation.
- Make a list of all methods that are called with the user chooses option 1 (increase infection rate of all cities). With each method name, please note the class it belongs to
In this lab we will be using a feature from c++11, the nullptr key word, and templating. Please see the Makefile tutorial for needed updates to your Makefile.
valgrind --leak-check=full ./YourProgram
It will tell you if any leaks occurred. Make sure you have the -g flag in your Makefile and you’ll get the added bonus of see what lines of code created an object that was never deleted. Science!
Recently, valgrind began reporting on a buffer that automatically allocated then deallocated after our main ends. This would look like you’re doing something wrong. But be aware if you run a program with an empty main, you’ll see the following:
==23799== HEAP SUMMARY: ==23799== in use at exit: 72,704 bytes in 1 blocks ==23799== total heap usage: 1 allocs, 0 frees, 72,704 bytes allocated ==23799== ==23799== LEAK SUMMARY: ==23799== definitely lost: 0 bytes in 0 blocks ==23799== indirectly lost: 0 bytes in 0 blocks ==23799== possibly lost: 0 bytes in 0 blocks ==23799== still reachable: 72,704 bytes in 1 blocks ==23799== suppressed: 0 bytes in 0 blocks ==23799== Reachable blocks (those to which a pointer was found) are not shown. ==23799== To see them, rerun with: --leak-check=full --show-leak-kinds=all ==23799== ==23799== For counts of detected and suppressed errors, rerun with: -v ==23799== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Note the amount of allocations. My empty main didn’t allocate anything, but valigrind is reporting everything it can see. There is a buffer being allocated that we don’t control. It is freed, but after our main ends, so Valgrind reports on it.
Just make sure…
- your allocs are only off by 1
- there are no memory error
- nothing is lost