Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ / Pet.cpp / / 2 a - Lab - 0 6 - Pets / / #include #include #include #include Pet.h size _ t
Pet.cpp
aLabPets
#include
#include
#include
#include "Pet.h
sizet Pet::population ;
Pet::Petstd::string name, long id int numlimbs : namenameididnumlimbsnumlimbs
population;
Pet::~Pet
population;
std::string Pet::getname const return name;
long Pet::getid const
return id;
int Pet::getnumlimbs const
return numlimbs;
bool Pet::setnamestd::string name
if name.empty
name name;
return true;
return false;
bool Pet::setidlong id
if id
id id;
return true;
return false;
bool Pet::setnumlimbsint numlimbs
if numlimbs
numlimbs numlimbs;
return true;
return false;
std::string Pet::tostring const
std::ostringstream oss;
oss Name: name ID: id Limb Count: numlimbs ;
return oss.str;
void Pet::getnpetssizet n std::vector& pets, int namelen
long previd ;
for sizet i ; i n; i
long id previd rand;
petsisetidid;
petsisetnumlimbsrand; up to arachnids
petsisetnamemakeanamenamelen;
previd id;
std::string Pet::makeanameint len
if len
return ; Return an empty string for len
const std::string vowels "aeiou";
const std::string consonants bcdfghjklmnpqrstvwxyz;
std::string result;
First letter is either a vowel or consonant
if rand
result vowelsrand vowels.length;
else
result consonantsrand consonants.length;
for int i ; i len; i
Alternate between vowels and consonants
if i
If the previous character was a vowel, choose a consonant
if resultback vowels result.back vowels result.back vowels result.back vowels result.back vowels
result consonantsrand consonants.length;
else If the previous character was a consonant, choose a vowel
result vowelsrand vowels.length;
else
Alternate between vowels and consonants
if resultback vowels result.back vowels result.back vowels result.back vowels result.back vowels
result vowelsrand vowels.length;
else
result consonantsrand consonants.length;
return result;
std::ostream& operatorstd::ostream& os const Pet& pet
os pet.tostring;
return os;
bool operatorconst Pet& pet const Pet& pet
return petgetname petgetname && petgetid petgetid &&
petgetnumlimbs petgetnumlimbs;
bool operator!const Pet& pet const Pet& pet
return pet pet;
this is the code i wrote but i get wrong output the error is i called a makeaname and giot yhuukf but i expect ihukuf
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started