//Bow.h
class Bow
{
//data member declarations
string color;
bool drawn;
int numOfArrows;
public:
Bow(string aColor); //constructor
~Bow(); //destructor
//methods
void draw();
int fire();
};
//Bow.cpp
Bow::Bow(string aColor)
{
numOfArrows = 10;
drawn = false;
color = aColor;
//seeds the time
//(we need the rand() function in the fire() method)
srand((unsigned)time(0));
}
Bow::~Bow()
{
}
//draws the bow
void Bow::draw()
{
drawn = true;
cout<< "The "<<color<<" bow has been drawn." <<endl;
}
//fires the bow if drawn
int Bow::fire()
{
if(!drawn)
{
cout<< color << " has not been drawn "
"and therefore could not fire." << endl;
return 0;
}
int score;
score = rand() % (10 - 0 + 1) + 0;
if(score == 0)
cout<<color<< " missed the target!!!" <<endl;
else
cout<< color << " scored " << score
<< " points!!!" <<endl;
return score;
}