chicken class implementation and execution
$30-250 USD
Pagado a la entrega
Write a main program to exercise your Chicken class. This main program will use an array of 10 Chicken objects. The chickens will have laid 0, 1, 2,…, 9 eggs respectively. The chickens will weigh 3, 3.2, 3.4,…,4.8 kilograms respectively. The first 5 chickens will be in solitary confinement (position=CONFINED), otherwise they will be on the FARM. Every chicken will have attempted to escape once, however the first 2 chickens have attempted to escape 10 times. Finally, the program should output the attributes for the 10 chickens.
(5 pts) Bonus: compare the chickens to see if any chickens have attempted the same number of escapes and are currently in solitary confinement, i.e., use the operator overloaded function. If so, output which chickens matched, and their attributes using the appropriate outputAll method already written.
/** Begin code after this line **/
#include
using namespace std;
enum { FARM, CONFINED, UNKNOWN };
char locString[3][30] = { {"is on the farm"},
{"is in solitary confinement"},
{"cannot be found"}};
// Chicken class definition
class Chicken {
private:
int eggs,
escapes,
position;
float weight;
public:
Chicken(int, int, int, float); // Constructor
int getEggs(void);
int getEscapes(void);
void setEggs(int egg) { eggs=egg; };
void setEscapes(int escape) { escapes=escape; };
void setPosition(int pos) { position=pos; };
void setWeight(float w) { weight=w; };
void setAll(int,int,int,float);
void outputAll(int);
void outputAll(int,int,Chicken); // output compared chickens
/** Write operator overload definition here **/
};
// Constructor definition
Chicken::Chicken(int egg=0, int escape=0, int pos=UNKNOWN, float w=3.0) {
eggs = egg;
escapes = escape;
position = pos;
weight = w;
}
// Set all attributes
void Chicken::setAll(int egg, int escape, int pos, float w) {
eggs = egg;
escapes = escape;
position = pos;
weight = w;
}
// Output all attributes
void Chicken::outputAll(int n) {
cout << "Chicken [" << n+1 << "] has laid " << eggs << " eggs, "
<< "has escaped " << escapes << " times, "
<< "weighs " << weight << " kilograms, and " << locString[position] << endl;
}
// Output all attributes for 2 chickens that match criteria
void Chicken::outputAll(int n, int m, Chicken otherChick) {
cout << "Chicken [" << n+1 << "] matches with chicken [" << m+1 << "] "
<< "where each has escaped " << escapes << " times and are both in solitary confinement." << endl;
cout << "Chicken [" << n+1 << "] has laid " << eggs << " eggs and "
<< "weighs " << weight << " kilograms." << endl;
cout << "Chicken [" << m+1 << "] has laid " << [url removed, login to view] << " eggs and "
<< "weighs " << [url removed, login to view] << " kilograms.\n\n";
}
/** Write your operator overload implementation here **/
/** Write your main function here **/
/** End code before this line **/
Nº del proyecto: #4467144