Пример #1
0
/*
 * Function: GetDiceConfiguration
 * ---------------------------------
 * Prompts user for a specific dice configuration for boggleBoard.
 *
 *@return diceConfig which denotes a string containing the user-specified dice configuration.
 */
string GetDiceConfiguration(int boardDimension)
{
	int maxChars = boardDimension * boardDimension;
	cout << endl << "Enter a " << maxChars << "-character string to identify which letters you want on the cubes." << endl;
	cout << "The first " << boardDimension << " letters are the cubes on the top row from left to right next "
    << boardDimension << " letters are the second row, etc." << endl;
	cout << "Enter the string: ";
	string diceConfig = ConvertToUpperCase(GetLine());
	while (diceConfig.length() < maxChars) { //prompts until dice configuration meets minimum length of maxChars
		cout << "String must include " << maxChars << " characters! Try again: ";
		diceConfig = ConvertToUpperCase(GetLine());
	}
	return diceConfig;
}
Пример #2
0
/*
* Returns an encoded string according to the 
* Soundex algorithm.
*/
string ParseName(string name) {
    string code;
    name = ConvertToUpperCase(name);
    for (int i = 0; i < name.length(); i++) {    
        if (i == 0)
            code += name[i]; // save first char
        if (i > 0 && isalpha(name[i]) != 0)
            code += ParseChar(name[i]);
    }
    
    for (int j = 0; j < code.length(); j++) {
        if (j > 0 && code[j] == code[j-1]) {
            code.erase(j,1); // delete duplicates
        } else if (code[j] == '0') {
            code.erase(j,1); // delete zeros
        }
    }
    
    if (code.length() < CODE_LENGTH) {
        int zeros = CODE_LENGTH - code.length();
        for (int k = 0; k < zeros; k++) {
            code += '0';  // padd zeros if code is too short
        }
    } else if (code.length() > CODE_LENGTH) {
        code = code.substr(0,CODE_LENGTH); // truncate if code is too long
    }
    return code;
}
Пример #3
0
/*
 * Function: GameContinue
 * ------------------------
 * Provides user with option to play another round of boggle with the computer.
 */
bool GameContinue()
{
	cout << "Would you like to play again? ";
	string answer = VerifyUserInput(ConvertToUpperCase(GetLine()));
	if (answer == "NO") return false;
	return true;
}
Пример #4
0
/*
 * Function: UserBoardConfiguration
 * -----------------------------------
 * Provides user with option to specify a specific board configuration.
 */
bool UserBoardConfiguration()
{
	cout << "Do you want to force the board configuration? ";
	string answer = VerifyUserInput(ConvertToUpperCase(GetLine()));
	if (answer == "YES") return true;
	return false;
}
Пример #5
0
/*
 * Function: VerifyUserInput
 * ---------------------------
 * Checks to see whether or not user has supplied appropriate input to a "yes" or "no" question.
 */
string VerifyUserInput(string answer)
{
	while (answer != "YES" && answer != "NO") { //prompts user until correct input is required
		cout << "Please answer yes or no: ";
		answer = ConvertToUpperCase(GetLine());
	}
	return answer;
}
Пример #6
0
/*
 * Function: BoggleBoardSize
 * ----------------------------
 * Provides user with option to increase dimensions of the boggle board from a 4x4 to a 5x5.
 *
 *@return int which denotes the user-specified grid dimension.
 */
int BoggleBoardSize()
{
	cout << endl << "I'll give you a chance to set up the board to your specification." << endl;
	cout << "Do you want to play on a 5x5 boggle board instead of a 4x4? ";
	string answer = VerifyUserInput(ConvertToUpperCase(GetLine()));
	if (answer == "YES") return 5;
	return 4;
}
Пример #7
0
void wxTextEntry::ForceUpper()
{
    if ( !m_isUpperCase )
    {
        ConvertToUpperCase();

        m_isUpperCase = true;
    }
}
Пример #8
0
main()
{
	char array[] = "characters";

	printf("The string before conversion is %s\n", array);
	ConvertToUpperCase(array);
	printf("The string after conversion is %s\n", array);

	return 0;
}
Пример #9
0
/*
 * Function: SoundFeature
 * -------------------------
 * Provides user with option to turn the sound on or off.
 */
void SoundFeature()
{
	cout << endl << "Would you like to turn on the sound? ";
	string answer = VerifyUserInput(ConvertToUpperCase(GetLine()));
	if (answer == "NO") {
		SetSoundOn(false);
	} else {
		SetSoundOn(true);
	}
}
Пример #10
0
void PlayerTurn(Grid<string> & board, Lexicon & lex, Set<string> & wordsSeen) {
	while (true) {
		cout << "Please enter a word found in the puzzle (ENTER to finish): ";
		string word = GetLine();
		word = ConvertToUpperCase(word);
		if (word == "") break;
		if (WordIsValid(word, board, lex, wordsSeen)) {
			putWordOnBoard(board, word, wordsSeen);
		} else {
			cout << "Sorry, that word is invalid. ";
		}
	}
}
Пример #11
0
int main()
{
	while (true) {
		//initialize
		Randomize();
		Set<string> wordsSeen;
		Lexicon lex("lexicon.dat");
		Grid<string> board(4,4);			//changes for 5x5
		SetWindowSize(9, 5);
		InitGraphics();
		DrawBoard(4,4);						//changes for 5x5
		Welcome();
		GiveInstructions();
		
		//either set up the board automatically or let the user set it up
		cout << "Would you like to configure the board? ";
		string response = GetLine();
		response = ConvertToUpperCase(response);
		if (response == "YES") {
			UserConfigureBoard(board);
		} else {
			InitializeBoard(board);
		}
		
		//have the player play, then the computer
		PlayerTurn(board, lex, wordsSeen);
		ComputerTurn(board, lex, wordsSeen);
		
		//check if the user wants to play again
		cout << "Would you like to play again? ";
		response = GetLine();
		response = ConvertToUpperCase(response);
		if (response != "YES") break;
	}
	return 0;
}
Пример #12
0
static void ReadAnswers(FILE *infile, questionT q)
{
    string line, ans;
    int len, cpos, nextq, nAnswers;

    nAnswers = 0;
    while ((line = ReadLine(infile)) != NULL
           && (len = StringLength(line)) != 0) {
        cpos = FindChar(':', line, 0);
        if (cpos == -1) Error("Illegal answer format");
        ans = SubString(line, 0, cpos - 1);
        nextq = StringToInteger(SubString(line, cpos+1, len-1));
        q->answers[nAnswers].ans = ConvertToUpperCase(ans);
        q->answers[nAnswers].nextq = nextq;
        nAnswers++;
    }
    q->nAnswers = nAnswers;
}
Пример #13
0
/*
 * Function: GiveInstructions
 * ----------------------------
 * Provides user with option to obtain instructions on how to play boggle.
 */
void GiveInstructions()
{	
	cout << "Do you need instructions? ";
	string answer = VerifyUserInput(ConvertToUpperCase(GetLine()));
	if (answer == "YES") {
		cout << endl << "The boggle board is a grid onto which I will randomly distribute " 
		<< "cubes. These 6-sided cubes have letters rather than numbers on the faces, " 
		<< "creating a grid of letters on which you try to form words. You go first, " 
		<< "entering all the words you can find that are formed by tracing adjoining " 
		<< "letters. Two letters adjoin if they are next to each other horizontally, " 
		<< "vertically, or diagonally. A letter can only be used once in the word. Words "
		<< "must be at least 4 letters long and can only be counted once. You score points "
		<< "based on word length: a 4-letter word is worth 1 point, 5-letters earn 2 "
		<< "points, and so on. After your puny brain is exhausted, I, the super computer, "
		<< "will find all the remaining words and double or triple your paltry score." << endl;
		cout << "\nHit return when you're ready...";
		GetLine();
	}
}
Пример #14
0
/*
 * Function: CheckUserGuess
 * ---------------------------
 * Checks if the format of user guess meets all requirements of the boggle rules.
 *
 *@return string userGuess when function has confirmed that all requirements have been met.
 */
string CheckUserGuess(Lexicon wordList, Lexicon usedWords)
{
	while (true) { //prompts until appropriate guess is received
		cout << "Enter a word: ";
		string userGuess = ConvertToUpperCase(GetLine());
		if (userGuess == "") return "";
		if (userGuess.length() < minWordLength) { //checks if minimum word length is met
			cout << "I'm sorry, but we have our standards." << endl;
			cout << "That word doesn't meet the minimum word length of 4." << endl;
			PlayNamedSound("whoops.wav");
		} else if (!wordList.containsWord(userGuess)) { //checks if the guess is actually a word
			cout << "That's not a word! " << RandomizeResponse() << endl;
			PlayNamedSound("whoops.wav");
		} else if (usedWords.containsWord(userGuess)) { //checks if the guess has already been used
			cout << "You've already guessed that! " << RandomizeResponse() << endl;
			PlayNamedSound("whoops.wav");
		} else {
			return userGuess;
		}
	}
}
Пример #15
0
void Findable(Grid<string> & board, string word, int row, int col, Vector<locationT> locations, Vector<Vector<locationT> > & answers) {
	word = ConvertToUpperCase(word);
	if (word.size() == 0) {							//every letter has been found, so add the locations to the set of answers
		answers.add(locations);
	}
	for (int i = 0; i < board.numRows(); i++) {
		for (int j = 0; j < board.numCols(); j++) {
			if (board(i,j) == word.substr(0,1) &&	//checks that the next letter is at a location, that it is a neighbor of the last letter
				AreNeighbors(i,j,row,col) && NotDuplicated(i,j, locations)) {			//and that it hasn't been used before
				locationT location;
				location.numRow = i;
				location.numCol = j;
				locations.add(location);
				Findable(board, word.substr(1), i, j, locations, answers);		//recurs with a truncated word and updated location
				if (word.size() != 0) {
					locations.removeAt(locations.size() - 1);			//word wasn't found going down this path, so remove the letter from 
				}														//the list of letters already seen
			}
		}
	}
}
Пример #16
0
static void ProcessCourse(courseDB course)
{
    questionT q;
    int qnum;
    string ans;
    int index;

    printf("%s\n", course->title);
    qnum = 1;
    while (qnum != 0) {
        q = course->questions[qnum];
        AskQuestion(q);
        ans = ConvertToUpperCase(GetLine());
        index = FindAnswer(ans, q);
        if (index == -1) {
            printf("I don't understand that.\n");
        } else {
            qnum = q->answers[index].nextq;
        }
    }
}
Пример #17
0
void UserConfigureBoard(Grid<string> &board) {
	string config;
	while (true) {
		cout << "Please enter your configuration. It must be 16 letters: " << endl;
		config = ConvertToUpperCase(GetLine());
		if (config.length() > 15) break;
		cout << "String too short. Enter another string" << endl;
	}
	if (config.length() > 16) { //truncate string to 16 letters
		config = config.substr(0, 16);
	}
	for (int i = 0; i < board.numRows(); i++) { //assign each letter to proper space in board
		for (int j = 0; j < board.numCols(); j++) {
			board(i,j) = config[i * board.numCols() + j];
		}
	}
	for (int i = 0; i < board.numRows(); i++) { //update display
		for (int j = 0; j < board.numCols(); j++) {
			LabelCube(i, j, board(i,j)[0]);
		}
	}
}
Пример #18
0
std::string GetParametricParameter(  
				const std::string	&in_model_name,
				ProMdl				*in_p_model,
				const std::string   &in_ParameterOwner,
				const std::string   &in_ParameterName )
									throw (isis::application_exception)
{

	
	

	//typedef wchar_t	ProName[PRO_NAME_SIZE];
	if ( in_ParameterOwner.size() >= PRO_NAME_SIZE )
	{
		char temp_char_array[ISIS_CHAR_BUFFER_LENGTH];
		std::string err_str = "exception : Exceeded maximum number of characters. Owner Name: "  + std::string(in_ParameterOwner) + ", Maximum allowed characters: " + _itoa(PRO_NAME_SIZE - 1, temp_char_array, 10);
		isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << err_str;			
		throw isis::application_exception("C01003", err_str);
	}

	//typedef wchar_t	ProName[PRO_NAME_SIZE];
	if ( in_ParameterName.size() >= PRO_NAME_SIZE )
	{
		char temp_char_array[ISIS_CHAR_BUFFER_LENGTH];
		std::string err_str = "exception : Exceeded maximum number of characters. Parameter Name: "  + std::string(in_ParameterName) + ", Maximum allowed characters: " + _itoa(PRO_NAME_SIZE - 1, temp_char_array, 10);
		isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << err_str;			
		throw isis::application_exception("C01004", err_str);
	}


	char  ReadValue[ISIS_CHAR_BUFFER_LENGTH];
	
	try
	{
		std::string ParameterOwner_string_upper = ConvertToUpperCase(in_ParameterOwner);

		ProName ParameterOwner_wchar;
		ProStringToWstring(ParameterOwner_wchar, (char *)in_ParameterOwner.c_str() );

		ProName ParameterName_wchar;
		ProStringToWstring(ParameterName_wchar, (char *)in_ParameterName.c_str() );

		//std::cout << std::endl << "ParameterName: " << ProWstringToString(temp_string, ParameterName_wchar);	
		//std::cout << std::endl << "in_p_model:    " << in_p_model;
		//std::cout << std::endl << "*in_p_model:    " << *in_p_model;

		ProModelitem  ParameterModelItem_struct;

		if ( ParameterOwner_string_upper == "MODEL" )
			isis::isis_ProMdlToModelitem ( *in_p_model, &ParameterModelItem_struct );
		else
			isis::isis_ProModelitemByNameInit (*in_p_model, PRO_FEATURE, ParameterOwner_wchar, &ParameterModelItem_struct);
	
		ProParameter  ProParameter_struct;

		isis::isis_ProParameterInit ( &ParameterModelItem_struct, ParameterName_wchar, &ProParameter_struct);
		
		ProParamvalue  ProParamvalue_struct;

		isis::isis_ProParameterValueGet( &ProParameter_struct, &ProParamvalue_struct );
		

		switch ( ProParamvalue_struct.type ) 
		{
			case PRO_PARAM_DOUBLE:
				sprintf(ReadValue,"%lf", ProParamvalue_struct.value.d_val);
				break;

			case PRO_PARAM_STRING:
				char narrow_string[ISIS_CHAR_BUFFER_LENGTH];
				ProWstringToString(narrow_string,ProParamvalue_struct.value.s_val); 
				sprintf(ReadValue,"%s", narrow_string );
				break;

			case PRO_PARAM_INTEGER:
				sprintf(ReadValue,"%d", ProParamvalue_struct.value.i_val);
				break;
			
			case PRO_PARAM_BOOLEAN:
				if ( ProParamvalue_struct.value.l_val == PRO_B_TRUE )
					sprintf(ReadValue,"%s", "TRUE");
				else
					sprintf(ReadValue,"%s", "FALSE");
				break;

			default:
				std::string err_str = "exception : Erroneous CADReadParameter Type, Supported types are DOUBLE, INTEGER, STRING, and BOOLEAN.";
				isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << err_str;			
				throw isis::application_exception(err_str);
		}


	}
	catch ( isis::application_exception& ex )
	{
		std::string err_str =	"exception : Part/Assembly Name: " + in_model_name +
								", Parameter Name: " + in_ParameterName + ", " + ex.what();
		throw isis::application_exception("C01005", err_str); 

	}

	return std::string(ReadValue);

}  // end GetParametricParameter