CSCI 235 Spring 2024 Term Project
Algorithmic Adventures II: Exponential Creature Odyssey
It is now time to define the simulation setting. In this project you will implement the Cavern
class, where you will house your Creatures
. You will create functionality that allows you to add and remove Creatures
from the Cavern
, and you will also be able to query the Cavern
for information about the Creatures
it contains. You will also be able to release Creatures
from the Cavern
based on their level and category.
The link to accept the GitHub Classroom assignment can be found on Blackboard
This project consists of two parts:
You will modify the Creature
class
You will implement Cavern
, as a subclass of ArrayBag
that holds Creature
objects
You will NOT modify ArrayBag
this class will be untouched and remains as distributed.
Abstract Data Types:
Template Classes:
Operator Overloading:
Work through the tasks sequentially (implement and test). Only move on to a task when you are positive that the previous one has been completed correctly. Remember that the names of classes and methods must exactly match those in this specification (FUNCTION NAMES, PARAMETER TYPES, RETURNS, PRE AND POST CONDITIONS MUST MATCH EXACTLY).
Remember, you must thoroughly document your code!!!
Creature
class
/**
@param : a const reference to the right hand side of the == operator.
@return : Returns true if the right hand side creature is "equal", false otherwise.
Two creatures are equal if they have the same name, same category, same level, and if they're either both tame or both not
NOTE: By this definition, only the aforementioned subset of the creature's attributes must be equal for two creatures to be deemed "equal".
Example: In order for creature1 to be == to creature2 we only need:
- The same name
- The same category
- The same level
- They must either be both tame or both not
*/
operator==
/**
@param : a const reference to the right hand side of the != operator.
@return : Returns true if the right hand side creature is NOT "equal" (!=), false
otherwise. Two creatures are NOT equal if any of their name, category or level are not equal, or if one is tame and the other is not.
NOTE: By this definition, one or more of the aforementioned subset of the creature's attributes only must be different for two creatures to be deemed "NOT equal".
*/
operator!=
Cavern
class as a subclass of ArrayBag
The Cavern
is subclass of ArrayBag
that stores Creature
objects
The Cavern
class must have the following private member variables:
- An integer sum of the levels of all the creatures currently in the Cavern
- An integer count of all the creatures currently in the Cavern that are tame
The Cavern
class must have the following public member functions:
/**
Default constructor.
Default-initializes all private members.
*/
xxxxxxxxxx
/**
* @param : A reference to a Creature entering the Cavern
* @post : If the given Creature is not already in the Cavern, add Creature to the Cavern and updates the level sum and the tame Creature count if the creature is tame.
* @return : returns true if a Creature was successfully added to the Cavern, false otherwise
: Hint: Use the above definition of equality will help determine if a Creature is already in the Cavern
**/
enterCavern
/**
* @param : A reference to a Creature leaving the Cavern
* @return : returns true if a creature was successfully removed from the Cavern (i.e. items_), false otherwise
* @post : removes the creature from the Cavern and updates the level sum.
If the Creature is tame it also updates the tame count.
**/
exitCavern
/**
* @return : The integer level count of all the creatures currently in the Cavern
**/
getLevelSum
/**
* @return : The average level (int) of all the creatures in the Cavern
* @post : Computes the average level (double) of the Cavern rounded to the NEAREST integer.
**/
calculateAvgLevel
/**
* @return : The integer count of tame Creatures in the Cavern
**/
getTameCount
/**
* @return : The percentage (double) of all the tame creatures in the Cavern
* @post : Computes the percentage of tame creatures in the Cavern rounded up to 2 decimal places.
**/
calculateTamePercentage
/**
* @param : A reference to a string representing a creature Category with value in ["UNKNOWN", "UNDEAD", "MYSTICAL", "ALIEN"]
* @return : An integer tally of the number of creatures in the Cavern of the given category.
If the argument string does not match one of the expected category values, the tally is zero.
NOTE: no pre-processing of the input string necessary, only uppercase input will match.
**/
tallyCategory
/**
@param : An integer representing the level threshold of the creatures to be removed from the Cavern, with default value 0
@post : Removes all creatures from the Cavern whose level is less than the given level. If no level is given, removes all creatures from the Cavern. Ignore negative input.
@return : The number of creatures removed from the Cavern
*/
releaseCreaturesBelowLevel
/**
@param : A reference to a string representing a creature Category with a value in ["UNKNOWN", "UNDEAD", "MYSTICAL", "ALIEN"], or default value "ALL" if no category is given
@post : Removes all creatures from the Cavern whose category matches the given category. If no category is given, removes all creatures from the Cavern.
@return : The number of creatures removed from the Cavern
NOTE: no pre-processing of the input string necessary, only uppercase input will match. If the input string does not match one of the expected category values, do not remove any creatures.
*/
releaseCreaturesOfCategory
/**
* @post : Outputs a report of the creatures currently in the Cavern in the form:
"UNKNOWN: [x]\nUNDEAD: [x]\nMYSTICAL: [x]\nALIEN: [x]\n\nAVERAGE LEVEL: [x]\nTAME:[x]%\n"
Note that the average level should be rounded to the NEAREST integer, and the percentage of tame creatures in the Cavern should be rounded to 2 decimal places.
Example output:
UNKNOWN: 1
UNDEAD: 3
MYSTICAL: 2
ALIEN: 1
AVERAGE LEVEL: 5
TAME: 85.72%
*/
cavernReport
Although you will no longer submit your test file, you must continue to thoroughly and methodically test your code.
Start by stubbing all expected functions. Have all function declarations in the .hpp and stubs for all functions in the .cpp. When submitted as such, your program will compile, although you will fail all tests, since you have not implemented any functions yet. If your program compiles, you will have at least established that all functions have correct name, parameters and return-type.
What is a stub? A stub is a dummy implementation that always returns a single value for testing (or has an empty body, if void). Don’t forget to go back and implement the stub!!! If you put the word STUB in a comment, some editors will make it more visible.
Now you can start implementing and testing your project, ONE FUNCTION AT A TIME!
Write a main()
function to test your implementation. Choose the order in which you implement your methods so that you can test incrementally: i.e. implement constructors then accessor functions, then mutator functions.
For each class, test each function you implement with all edge cases before you move on to implement the next function. This includes all constructors.
Make sure you include all packages and libraries you use.
How to compile with your Makefile:
In terminal, in the same directory as your Makefile and your source files, use the following command
make rebuild
This assumes you did not rename the Makefile
and that it is the only one in the current directory.
Correctness 80% (distributed across unit testing of your submission)
Documentation 15%
Style and Design 5% (proper naming, modularity, and organization)
Important: You must start working on the projects as soon as they are assigned to detect any problems with submitting your code and to address them with us well before the deadline so that we have time to get back to you before the deadline.
We will grade the following :
Creature.hpp
Creature.cpp
Cavern.hpp
Cavern.cpp
Although Gradescope allows multiple submissions, it is not a platform for testing and/or debugging and it should not be used for that. You MUST test and debug your program locally. To help you not rely too much on Gradescope for testing, we will only allow 5 submissions per day. Before submitting to Gradescope you MUST ensure that your program compiles using the provided Makefile
and runs correctly on the Linux machines in the labs at Hunter (see detailed instructions on how to upload, compile and run your files in the “Programming Guidelines” document). That is your baseline, if it runs correctly there it will run correctly on Gradescope, and if it does not, you will have the necessary feedback (compiler error messages, debugger or program output) to guide you in debugging, which you don’t have through Gradescope. “But it ran on my machine!” is not a valid argument for a submission that does not compile. Once you have done all the above you submit it to Gradescope.
This project is due on 3/7.
No late submissions will be accepted.
You must start working on the projects as soon as they are assigned to detect any problems and to address them with us well before the deadline so that we have time to get back to you before the deadline. There will be no extensions and no negotiation about project grades after the submission deadline.
Help is available via drop-in tutoring in Lab 1001B (see website for schedule). You will be able to get help if you start early and go to the lab early. We only have 3 UTAs in the lab, the days leading up to the due date will be crowded and you will not be able to get much help then.
Authors: Georgina Woo, Tiziana Ligorio