Utilizing C++ programming in basic C++ terms, could someone assist in answering the 1 question below please? After quest

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

Utilizing C++ programming in basic C++ terms, could someone assist in answering the 1 question below please? After quest

Post by answerhappygod »

Utilizing C++ programming in basic C++ terms, could someoneassist in answering the 1 question below please? Afterquestion one the code and the text files are provided to helpin answering the question.
1.Selecting and Displaying Puzzle
After the player chooses a category, your program must randomlyselect a puzzle in that category from the array of Puzzle structs.Since a puzzle in any category can be randomly selected, it isimportant to repeatedly generate random numbers until a puzzle inthe desired category is found. After selecting the puzzle, it isdisplayed to the player with the letters “blanked off”. Thecharacter ‘#’ is used to hide the letters. If there are spaces ordashes (‘-‘) in the puzzle, these are revealed to the player, forexample, the puzzle “FULL-LENGTH WALL MIRROR” would be displayed asfollows:
####-###### #### ######
struct Puzzle{string category;char puzzle[80];};
void readCategories(string categories[]){ifstream inputFile;string word;int i = 0;inputFile.open("Categories.txt");if (!inputFile.is_open()) {cout << "Error -- data.txt could not be opened." <<endl;}while (getline(inputFile,word)) {categories = word;i++;}inputFile.close();}
void readPuzzles(Puzzle puzzle[]){ifstream inputFile;Puzzle puzzles[80];string categories;int numberOfPuzzles = 0;inputFile.open("WOF-Puzzles.txt");if (!inputFile.is_open()) {cout << "Error -- data.txt could not be opened." <<endl;}inputFile >> categories;while(getline(inputFile,categories)){puzzles[numberOfPuzzles].category = categories;inputFile.getline(puzzles[numberOfPuzzles].puzzle,80);numberOfPuzzles++;}inputFile.close();}
void chooseCategory(string categories[]){srand(time(0));categories[50];string randomCategory1;string randomCategory2;string randomCategory3;int choice;readCategories(categories);for(int i = 0; i <= 19; i++){categories;randomCategory1 = categories[rand() % 19];randomCategory2 = categories[rand() % 19];randomCategory3 = categories[rand() % 19];}cout << "1." << randomCategory1 << endl;cout << "2." << randomCategory2 << endl;cout << "3." << randomCategory3 << endl;cout << "Please select one of the three categories tobegin:(1/2/3)" << endl;cin >> choice;if (choice < 1 || choice > 3){cout << "Invalid choice. Try again." << endl;cin >> choice;}cout << endl;if(choice == 1){cout << "You selected: " << randomCategory1 <<"." << endl;}else if(choice == 2){cout << "You selected: " << randomCategory2 <<"." << endl;}else if(choice == 3){cout << "You selected: " << randomCategory2 <<"." << endl;}
}
Categories textfile:
Around the HouseCharacterEventFood & DrinkFun & Games
WOF-Puzzles textfile:
Around the HouseFLUFFY PILLOWSAround the HouseFULL-LENGTH WALL MIRRORCharacterWONDER WOMANCharacterFREDDY KRUEGER
EventROMANTIC GONDOLA RIDEEventAWESOME HELICOPTER TOURFood & DrinkSIGNATURE COCKTAILSFood & DrinkCLASSIC ITALIAN LASAGNA
Fun & GamesFLOATING DOWN A LAZY RIVERFun & GamesDIVING NEAR CORAL REEFSFun & Games
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply