(Solved) : Centipede S Shoes Mr Centipede Lot Feet Shoes Mr C S Shoes Come Two Types Shoes Laces Slip Q37190860 . . .
The Centipede’s Shoes…
Mr. Centipede has a lot of feet,… and shoes. Mr. C’s shoes comein two types: shoes with laces, and slip-ons. He considers both ofthese types of shoes to be “footwear”. He has begun working on aprogram to help him keep track of these shoes and has asked you toassist him in its development.
For this problem you will create three classes to assist Mr.Centipede. These classes are to be called:
- Footwear
- SlipOnShoe
- LacedShoe
The Footwear class
Footwear is to be an abstract class from which the other twoclasses must be directly derived. Much of the Footwear class hasalready been written for you, but there are a few things you needto add.
Footwear should have a name, upper and sole materials, primarycolor, and integer size. All Footwear can be either on, or off(i.e. of Mr. Centipede’s feet).
Footwear properties:
- name
- upperMaterial
- soleMaterial
- primaryColor
- size
- onFeet
NOTE: NONE of these values should be made public (deduction 5points) – though you may decide to make one or more of themprotected.
The name, size, materials, and primary color of a pair ofFootwear does not change and so are specified when a Footwear itemis constructed, and not changed thereafter. This is accomplishedwith a parameterized constructor. All Footwear are initially “off”of Mr Centipede’s feet. The Footwear class has getters for thename, upperMaterial, soleMaterial, primaryColor, size, and onFeetvalues. These are named:
- Name()
- UpperMaterial()
- SoleMaterial()
- PrimaryColor()
- Size()
- OnFeet()
Name(), UpperMaterial(), SoleMaterial(), and PrimaryColor()return strings. Size() returns an int, and OnFeet a boolean – inaccordance with the purpose of their names (i.e. Name() returns thename of the Footwear).
In order to facilitate easily retrieving a summary of a Footwearitem, the Footwear class also has a ToStr() method that returns astring containing the shoe size, primaryColor, name, upperMaterialand soleMaterial. For example, if a Footwear object had the values:name =”boots”, size=10, upperMaterial=”leather”,soleMaterial=”rubber”, and color=”brown” the string returned fromToStr() would be:
size 10 brown boots with leather uppers and rubber soles
NOTE: ToStr() does NOT make use of cout – it returns a string,it does not print one.
As mentioned above, you are to change Footwear to be an abstractclass. It should be abstract because it must declare two purevirtual methods called Apply() and Remove(). These methods must bedefined by the derived classes and will determine the manner inwhich Footwear is to be removed. This is because some footwear maysimply be put on or off, whereas others require first untying orunfastening first etc.
The SlipOnShoe class
The first derived class you should create is the SlipOnShoeclass. This class represents the simplest of the derived classes interms of functionality. SlipOnShoe should inherit from Footwear(which will require that it call Footwear’s parameterizedconstructor properly) and implement the two pure virtual methodsfrom that class – Apply() and Remove(). Apply() should change thevalue of onFeet to true, and print a message that states the nameof the SlipOnShoe item and that it has been applied. For example,if the SlipOnShoe object’s name value were set to “boots” – thismessage would be:
boots applied
Similarly, the Remove() method should change the value of onFeetto false, and print a message indicating that the item has beenremoved. For example, if the SlipOnShoe object’s name value wereset to “boots” – this message would be:
boots removed
The LacedShoe class
As with the SlipOnShoe class, the LacedShoe class must bederived from the Footwear class, and it must implement the Apply()and Remove() methods which will perform the same actions as in theSlipOnShoe class. However, in this case a bit of extra work is alsorequired to keep track of those laces. The LacedShoe class shouldkeep track of whether or not a LacedShoe object’s laces are tied ornot. When an instance of LacedShoe is created the laces shoulddefault to an untied state. Two new methods, Tie(), and Untie()should appropriately update the state of the laces and outputmessages indicating what was done. For instance, if the LacedShoeobject is named “running shoes”, and the Tie() method is called -then the message printed to the screen should read:
tied running shoes
and…
untied running shoes
when the Untie() method is called.
In addition to the Tie() and Untie() methods for managing thelaces, a “getter” method called AreTied() should return a booleanvalue indicating whether or not the laces for this object aretied.
When the Remove() method is called for a LacedShoe object – thismethod should check to see if the laces on the object are tied. Ifthe laces are not tied, simply proceed with the removal process. Ifon the other hand the laces ARE tied, then the Untie() methodshould be called before removal is performed.
Test Code
In addition to the unit tests that we will use to evaluate yourclasses – Mr. Centipede has provided some test code in a main()function to help you in the creation and testing of your classes.This code is in working order and does not require modification inorder to get full credit. All of your coding efforts should be inthe header files for the classes you need to implement. Normally(as you have been taught) we would implement most of the methodsfor our classes in .cpp files. For the sake of simplifying thisquestion we are having you do this in the provided .h files.
Additional Information/Requirements
- For the sake of simplicity you can assume that Remove()/Apply()methods will only be called when a pair of shoes can be removed orapplied. In other words you don’t need to check to see that a pairof shoes is on before removing them, or off before applying them.Similarly, you can assume that the Tie()/Untie() methods will onlybe called on shoes that can be tied or untied (no need to check tosee if they are already tied/untied).
- For the sake of efficiency we have provided you with a partialimplementation of the Footwear class, as well as some “skeletoncode” (a rough start) for the two derived classes you will need tocomplete. You are free to use this code or to delete it and startfrom scratch if you choose – just remember to meet all of thestated requirements etc.
given code:
#include “SlipOnShoe.h”
#include “LacedShoe.h”
#include <vector>
#include <iostream>
using namespace std;
int main(){
//a few slip on shoes…
SlipOnShoe cowboyBoots(“cowboy boots”, “leather”, “dense rubber”,”brown”, 10);//giddyup
SlipOnShoe usedToBeCool(“Crocks”, “foamy rubber”, “foamy rubber”,”green”, 5);//still comfy
SlipOnShoe toLookTall(“1 inch heels”, “plastic”, “dense rubber”,”black”, 6);//I’m a bug… 1 inch is huge…
cowboyBoots.Apply();
usedToBeCool.Apply();
toLookTall.Apply();
toLookTall.Remove();
cowboyBoots.Remove();
//a few laced shoes…
LacedShoe runningShoes(“running shoes”, “polyester”, “soft rubber”,”white”, 8);
LacedShoe sundayShoes(“dress shoes”, “genuine leather”, “denseleather”, “dark brown”, 9);
LacedShoe workShoes(“Redwing boots”, “leather”, “dense rubber”,”black”, 15);
runningShoes.Apply();
sundayShoes.Apply();
workShoes.Apply();
runningShoes.Tie();
sundayShoes.Tie();
workShoes.Tie();
sundayShoes.Untie();
sundayShoes.Remove();
runningShoes.Remove();
//now let’s try some polymorphism…
vector<Footwear*> shoeList;
shoeList.push_back(&cowboyBoots);
shoeList.push_back(&usedToBeCool);
shoeList.push_back(&toLookTall);
shoeList.push_back(&runningShoes);
shoeList.push_back(&sundayShoes);
shoeList.push_back(&workShoes);
for(unsigned int i = 0; i < shoeList.size(); i++){
cout << shoeList.at(i)->ToStr();
if(shoeList.at(i)->OnFeet()){
shoeList.at(i)->Remove();
}
}
return 0;
}
Expert Answer
Answer to The Centipede’s Shoes… Mr. Centipede has a lot of feet,… and shoes. Mr. C’s shoes come in two types: shoes with lace…
OR