Question: Can someone help with this assignment? Create a new C++ repl project to write the code below. You will create a total of 5 files
Can someone help with this assignment?
Create a new C++ repl project to write the code below. You will create a total of 5 files and submit a link to your repl.
Write a class called Dog in C++. Dogs have attributes (such as number of legs and eye color), and they can run and bark and wag tails. Dogs can also optionally have a bone, and you'll have to create a Bone class for this.
At a minimum, Dogs should have the following attributes:
numberOfLegs (integer, must be between 0 and 4)
eyeColor (a string that could be of any value)
furColor (a string that could be of any value)
weight (a float, must be between 1 and 200)
isHappy (a boolean, defaulting to true)
name (a string that could be of any value)
Dogs should have a constructor and a destructor:
The constructor should take one arguments: a string representing the name. It should print a message noting that the dog as been created (e.g "_name_ is alive!")
The destructor should print the dog's name and a message (e.g. "_name_ is no longer with us")
Dogs should provide the following 7 public functions (at a minimum):
void run(howFar, howFast)
howFar is an integer between 0 and 1000. If howFar is outside this range, then run should not do anything.
The run method will print one "#" character for each value between 0 and howFar.
howFast is an integer between 0 and 1000. It is the number of milliseconds to sleep between each print of the "#" character. There should be no newline until the last "#" is printed. If howFast is out of the accepted range, it should be set to 0.
If the dog has less than three legs, then run should not do anything.
If the dog has exactly three legs, it should run at 75 % of the rate of a 4 legged dog.
Note that the # character must actually appear on the screen between sleeps (not just all at once; see hints)
run should also print the number of legs the dog is using to run
run should print a message stating the values for howFar and howFast
void bark(numTimes)
should take a parameter of how many times to bark
should print the dogs name
if the dogs weight is < 100, then
it should print the word "yap!!!" numTimes
otherwise
should print the word "WOOF!!!" numTimes
void wag(numTimes, howFast)
numTimes is an integer between 0 and 1000. If numTimes is outside this range, then wag should not do anything.
If the dog is happy, the wag method will print alternating "\" and "/" characters separated by a space. The total number of slashes (both types) should be numTimes.
If the dog is not happy, wag doesn't do anything.
Once the dog is done wagging, he loses his bone, and he isn't happy about it, so take appropriate action.
There should be a single space printed between each "\" and "/".
howFast is an integer between 0 and 1000. it is the number of milliseconds to sleep between each print of the "\" or "/" characters. If howFast is out of the accepted range, it should be set to 0.
There should be no newline until the last "/" or "\" is printed.
Should print the values for numTimes and howFast
void setWeight(weight)
weight is a double
you can assume that weight will be between the range of 0 to 200, inclusive;
void setNumberOfLegs(numLegs)
numLegs is an integer
you can assume that numLegs will be between the range of 0 to 4, inclusive;
if numLegs is > 4, then you should set the dog to have 4 legs.
void setHappiness(isHappy)
happy is a boolean
void addBone()
makes the dog happy by setting the dogs happiness to true
also dynamically declares a new Bone.
You must also create a Bone class. The Bone class is pretty simple. It just has a constructor and a destructor. Your destructor should simply print "bone going away.".
I will be testing your Dog class using my own main class. So your Dog class must be called Dog, and it must implement at least the bark, wag, setName, setWeight, setNumberOfLegs and run methods with the parameters as specified above. Additionally, Dog must correctly implement the constructor and destructor as described.
You don't have to error check the color attributes. In other words, you can accept whatever color values are used. But you should provide methods to get and set the eyeColor, and furColor, and any other attributes you decide to make.
Hints
cout.flush() might come in handy.
Look up usleep (in unistd.h) for how to sleep.
If you declare a pointer to something, it is good practice to initialize it to NULL.
Anything that is created with new must be cleaned up!
Other Requirements
Do not clutter your .h and .cpp files with stuff that should not be included. Only include things that are needed by that file directly!
Do not do any variable initialization or assignments in your .h files. This type of thing should be done in your class constructor.
Make sure that you set your access modifiers correctly for the members of your class.
Your submission should contain the following:
Dog.h: the class definition for Dog.
Dog.cpp: the implementations of all instance methods (run, bark, etc.) along with the constructor and destructor.
Bone.h: the class definition for Bone.
Bone.cpp: the implementations of the Bone constructor and destructor.
main.cpp: The program file which includes a main method to test your classes. You may use the following code snippet to test your classes:
int main( ) { Dog dog1("Fido"); dog1.setWeight(5.0); dog1.bark(5); dog1.setNumberOfLegs(3); dog1.run(20,400); dog1.addBone(); dog1.wag(10,550); } Feel free to modify this as needed to test your classes. Remember I will be using my own main method to test your classes.
Submit
A link to your repl.it project (URL copied from the address bar)
Sample Output
If you use the code shown above in a main method you should see something like the following:
Fido is alive! I'm Fido and I'm here to say: yap!! yap!! yap!! yap!! yap!! Fido is running to catch squirrels on 3 legs | run: 20, sleep: 533ms #################### Fido is tired now. My tail is dragging. wow, thanks for the bone! I'm Fido, and I'm happy. I'm wagging my tail! | wags: 10, sleep: 550ms \ / \ / \ / \ / \ / bone going away I'm Fido, and I'm done being happy. all done. Fido is no longer with us.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
