1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
# include "GuessWord.h"
# include <iostream>
# include <string>
# include <ctime>
# include <cstdlib>
using namespace std;
GuessWord::GuessWord()
{
// You can initialize the word array at this way since you know its elements number
const char *szBuffer[] = {"automobile","lantern", "surfing", "woman", "university",
"computer","vacation", "television","apartment", "airplane",
"venom", "elephant","recording","Canada", "rhinoceros"};
for(int i=0;i<15;i++)
{
words[i] = szBuffer[i] ;
}
}
void GuessWord::Launch() const
{
srand(time(0));
int number = rand() % 15;
//string displayWord(number);
displayWord(number);
}
// displayWord(int number) is a member of GuessWord class so...
void GuessWord::displayWord(int number) const
{
// cout << words[i] << endl; i is underclared
cout << words[number] << endl;
}
|