Page 1 of 1

Utilizing C++ programming in basic C++ terms for example no pointers to be used, could someone assist in answering the 1

Posted: Sun Jul 03, 2022 9:59 am
by answerhappygod
Utilizing C++ programming in basic C++ terms for example nopointers to be used, could someone assist in answering the 1question below please? After question one the code and the textfiles are provided to help in 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