OOP- Word Jumble & Scoring

Hey guys, new to the forum. I am working on an assignment for class for the
Word Jumble game. I have already added the scoring system.
I understand the other codes that I've come across, but the teacher insists that everything be put into classes, and this is what screws me up haha.
Everything seems to work fine, however, I am a bit confused as to where I need to place the actual words and hints that are to be scrambled. I keep getting back errors that say the array isnt correct.I'm pretty sure I've just forgotten to change a word or two somewhere. Any hints would be appreciated! Thanks in advance!

Here is my code:
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356


// wordjumble.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstdlib> //same as number generator!!!!
#include <ctime>

using namespace std;

const int MAXNUMBER = 10;
const int TRIES = 0;
const int NUM_WORDS = 5;
enum fields {WORD, HINT, NUM_FIELDS};
const int NUM_WORDS = 5;
const int MAX_GUESSES = 5;


	


/************************************************
CLASS: JUMBLER
*************************************************/

class JUMBLER {


private:
	int choice;  
	string originalWord; 
	string theJumble; 


public:
	JUMBLER(){
			srand(time(0));
			
		}//end jumbler public

	string jumbleWord(string theWord){   
	originalWord = theWord; 
	theJumble = theWord; 

			int length = theJumble.length();
			
			for(int i=0; i < length; i++){ 

				int index1 = (rand() % length); 	
				int index2 = (rand() % length); 
				

				char tmp = theJumble[index1]; 
				theJumble[index1]= theJumble[index2]; 
				theJumble[index2]= tmp; 
				
				
	do{  index2 = (rand() % length);
           }while(index1 == index2);//is equal to
	

			}//end for loop



	return(theJumble);

		
} //end JUMBLER


		

		string getJumble(){	  //getJumble::string; 
			return(theJumble);
		}//end string getJumble

		string getTheWord(){ //gettheWord::string
			return(originalWord);
		} //end getTheWord




bool isCorrect(string guess) {
	if(guess == originalWord){	

  cout << "\nYou Guessed Correctly!" << endl;  
	return(true);	
	} else{ 
		cout << "\nYour Guess is not Correct!" << endl;
		return(false);		
			} 
		} //end bool
};






///************************************************
//CLASS: PLAYER   
//*************************************************/

class Player{



private:
	
	
	string theGuess;//changed from int to string
	string name;
	int score;
	int tries;

	void init(){
	//private 
		
		score = 0;
		tries = 0;		
	}





public:

		Player(){
			
			tries = MAXNUMBER+1;
		} //end player1
		
		
		Player(string myName){
			init();
			name = myName;
			tries = MAXNUMBER+1;
		}//end player string

				
		string getName(){
			return(name);
		}//end string gname
		


		
		string takeYourTurn(){ //do while LOOP will run more than once
			// do{
				cout << "\n " << name << "2, Enter your guess : ";	//add the comma so the prompt enters the player's name!!!!!!
				cin >> theGuess; 
			//if(theGuess == 0;){}
			// }while(theGuess < 1 || theGuess > MAXNUMBER); // || = OR   this is the validation CODE!
			
			
			tries--; // most appropriate place to do this!!
			

			// return((tries==0)? TRIES : 1); //ternary operator "if tries equals zero, return 0; if not, return the guess"
			return (theGuess);

		}//end tyTurn



		string gettheGuess(){
			return(theGuess);
		//get the data and return it
		}//end gtGuess


		void resetTries(){
			tries = MAXNUMBER+1;
			}//end rTries
	
		int getTries(){			//need a "getter" to reset
			return(tries);
		}//end gTries

		
		string getGuess(){
			return(theGuess);			
		}
		
		



		
	    int getScore(){
		return(score);//get the data and return it
		}//end gScore

		void resetScore(){
			score = 0;
			} //end void rScore



		int awardPoints(){
			score += tries;
			return(score);
		} //end int aPoints    


		
	
};//end class player
	






///************************************************
//CLASS: WORD JUMBLE   MASTER CLASS!!!!!!
//*************************************************/
class WordJumble {


private:
	


const string WORDS[NUM_WORDS][NUM_FIELDS];
	JUMBLER jumbler;
	//two indexes>declaring = max number wanted


const string WordJumble::WORDS[NUM_WORDS][NUM_FIELDS] = {
	{"wall","do you feel like banging your head against something?"},
	{"glasses","these might help you see the answer."},
	{"labored","Going slowly, is it?"},
	{"jumble","It's what the game is all about."},
	{"persistant","Keep at it!"}
	 };





	void PlayOneRound(){

		int choice = (rand() % NUM_WORDS);
		string theWord = WORDS[choice][WORD];
		string theHint = WORDS[choice][HINT];
		string jumble = theWord;
		string guess;
		int points = 0;
		bool status;

	
		
		


	



cout << "The jumble is " << jumbler.jumbleWord(WORDS[wordIndex][WORD]) << endl;





		do{
			cout<< "1Enter Your Guess: ";
			cin >> guess;
			if(guess == "hint"){
				cout << "HINT: " << WORDS[wordIndex][HINT] <<endl;
				status = false;
				continue;
			}
			status = jumbler.isCorrect(guess);
		}while(status == false);

		cout << "Congratulations! \n" << endl;

	}//end playoneround


public:
	WordJumble(){
	}


	
	int Play(){
		PlayOneRound();

		return 0;
	}//end void


}; //end WordJumble












int _tmain(int argc, _TCHAR* argv[])
{

	JUMBLER c; //these are the instances!!!!!!!
	Player p("Christine");
	string guess;

///************************************************
// multi jumble
//*************************************************/
	for(int i =0; i< 10; i++){
	//	c.jumbleWord(index1);
		cout << "the jumble: " << &JUMBLER::getTheWord <<  endl;

	guess = p.takeYourTurn();


	if(c.isCorrect(guess)){
		cout << "\nYOUR ON FIRE!\n" << endl;
	
	}else{
		cout << "\nLOOOOOOSER!";
	} //else


	
	p.awardPoints();
	cout << p.getName() << ", Your Score is: " << p.getScore() << endl;
	cout << "Done!" << endl;  


	}//end for loop; 	
	
	return 0;
}





- It looks like a lot of the stuff you do between line 48 and line 58 should maybe be in the constructor?

- Why do you set "tries" to the max value right from the start in the "Player" constructor?

- Why is there a '2' in line 151?

- Line 272: workIndex is not declared for use here.

- getScore returns an unintiated value unless you pass it a string. This isn't an issue now but don't forget to fix that.

- I don't see where you actually check the players choice against the jumble

- I think you need to give this a look: http://www.cplusplus.com/doc/tutorial/inheritance/
especially that part about "freind" classes
Last edited on
ok thanks for pointing those out!
- Line 237 - Line 243 is just confusing to look at. Are you trying to make is so that if the user types any of these "keywords" that the program outputs the line that seems to match up with it? Or else what are you trying to do? Please be specific.
Topic archived. No new replies allowed.