Please implement classes and objects into this code provided. Class wordle is already created. This is a wordle, please

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Please implement classes and objects into this code provided. Class wordle is already created. This is a wordle, please

Post by answerhappygod »

Please implement classes and objects into this codeprovided. Class wordle is already created. This is a wordle, pleaseimplement classes and objects.
#include <iostream>#include <ctime>#include <vector>using namespace std;class Wordle {private: string input{""};
public: string checkInput() { return input; }};
string verify_input(string input) { while (input.size() != 4 and input != "q" and input != "Q"and input != "h" and input != "t"){ cout << "Invalid Input! Make sure your word is4 letters long" << endl; cout << "Enter your guess word: "; cin >> input; }
return input;}vector<string> list_of_words{"bake", "race", "exit", "mars","game"};string get_word() { srand(time(0)); return list_of_words[rand() % list_of_words.size()];}
vector<string> compare_words(string answer_word, stringuser_guess) { Wordle word; vector<string> status_of_word{}; int match{0}, part_match{0}, no_match{0}; string status_string{""}; for (int character = 0; character < answer_word.size();character++) { if (tolower(user_guess[character]) ==answer_word[character]) { match += 1; status_string.insert(character, "!"); } else if (tolower(user_guess[character]) !=answer_word[character] and answer_word.find(user_guess[character]) != -1) { part_match += 1; status_string.insert(character, "?"); } else if(answer_word.find(tolower(user_guess[character])) == -1) { no_match += 1; status_string.insert(character, "X"); } } status_of_word.push_back(to_string(match)); status_of_word.push_back(to_string(part_match)); status_of_word.push_back(to_string(no_match)); status_of_word.push_back(status_string);
return status_of_word;}
string give_second_hint(string answer) { if (answer == "bake") { return "The process of heating food. Usually done inan oven.\n"; } else if (answer == "race") { return "The name of a competition to see who is thefastest.\n"; }
else if (answer == "exit") { return "The process of leaving a place.\n"; }
else if (answer == "mars") { return "One of the planets in our solar system. Has ared color\n"; }
else { return "The name of what you're playing rightnow!\n"; }}int main() { cout << "Welcome to Wordle!\n"; cout << "Guess a word, letter by letter.\n" <<endl; cout << "Check status for: " << '\n' << "Right Letter Right Position(RLRP)" << '\n' << "Right Letter Wrong Position(RLWP)" << '\n' << "Wrong Letter Wrong Position(WLWP)\n" << endl;
string user_input{""}, answer_word{get_word()}; static int number_of_guesses{1}, number_of_hints{0}; const bool running{true}; bool flag{true}; enum status_of_program {Running = 1, Quit = 0}; status_of_program status; while (Running) { if (number_of_hints == 0) { cout << "Guess the word 4 letters (q =new word; Q = quit game; t = test): "; }
else { cout << "Guess the word 4 letters (q =new word; Q = quit game; h = hint; t = test): "; }
cin >> user_input;
if (user_input == "q") { answer_word = get_word(); cout << "\nNew word given!" <<endl; cout << endl; number_of_guesses = 1; } else if (user_input == "h") { if (number_of_hints == 1) { cout << "Your words are: "; for (int word = 0; word <list_of_words.size(); word++) { cout <<list_of_words[word] << " "; } cout << endl; cout << endl; number_of_hints++; } else if (number_of_hints == 2) { cout << "Hint: " <<give_second_hint(answer_word) << endl; flag = false; number_of_hints++; } else { cout << "You've already used upall your hints!\n" << endl; } }
else if (user_input == "t") { cout << "The word is: " <<answer_word << endl; cout << endl; flag = false; }
else if (user_input == "Q") { cout << "\nYou ended the game!Good-bye!\n"; return Quit; }
vector<string> status_of_word =compare_words(answer_word, user_input); if (user_input != "q" and user_input != "h" anduser_input != "t") { number_of_hints = 1; cout<< "(Guess #" << number_of_guesses++ << ") "<< user_input << "status: " <<"RLRP: " << status_of_word[0] << "RLWP: " << status_of_word[1] << "WLWP: " << status_of_word[2] << " " <<status_of_word[3] << endl; cout<< endl; }
if (stoi(status_of_word[0]) == 4) { cout << "You guessed the word!Congratulations!\n" << endl; answer_word = get_word(); number_of_guesses = 1; } } return 0;}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply