Question: #ifndef BOGGLE _ BOGGLE _ H #define BOGGLE _ BOGGLE _ H #include #include Dictionary.h using namespace std; const int BOARD _ SIZE =

#ifndef BOGGLE_BOGGLE_H
#define BOGGLE_BOGGLE_H
#include
#include "Dictionary.h"
using namespace std;
const int BOARD_SIZE =4;
class BoardNotInitialized {};
class Boggle {
public:
Boggle(); // load "dictionary.txt" into dict
explicit Boggle(string filename); // load filename into dict
void SetBoard(string board[BOARD_SIZE][BOARD_SIZE]);
void SolveBoard(bool printBoard, ostream& output);
void SaveSolve(string filename); // Saves all the words from the last solve.
Dictionary GetDictionary();
Dictionary WordsFound();
private:
Dictionary dict;
Dictionary wordsFound;
string board[BOARD_SIZE][BOARD_SIZE];
int visited[BOARD_SIZE][BOARD_SIZE];
void PrintBoard(ostream& output);
void SolveBoardHelper(int row, int col, string currentWord);
};
#endif //BOGGLE_BOGGLE_H
Boggle.cpp
#include "Dictionary.h"
#include "Boggle.h"
#include
#include
// Your code here
Boggle::Boggle(){
// Load the dictionary from the default file "dictionary.txt"
dict.AddWord("Dictionary.txt");
}
Boggle::Boggle(string filename){
// Load the dictionary from the given filename
dict.AddWord("Dictionary.txt");
}
void Boggle::SetBoard(string inputBoard[BOARD_SIZE][BOARD_SIZE]){
for (int i =0; i < BOARD_SIZE; ++i){
for (int j =0; j < BOARD_SIZE; ++j){
board[i][j]= inputBoard[i][j]; // Copy each entry
}
}
// Initialize visited array to 0(unvisited)
memset(visited,0, sizeof(visited));
}
void Boggle::SolveBoard(bool printBoard, ostream& output){
wordsFound = Dictionary(); // Reset found words
// Iterate through each cell and start DFS
for (int i =0; i < BOARD_SIZE; ++i){
for (int j =0; j < BOARD_SIZE; ++j){
SolveBoardHelper(i, j,"");
}
}
// Optionally print the board
if (printBoard){
PrintBoard(output);
}
// Output the found words
for (const string& word : wordsFound.GetAllWords()){
output << word << endl;
}
}
// This function is done.
Dictionary Boggle::GetDictionary(){
return dict;
}
// This function is done.
Dictionary Boggle::WordsFound(){
return wordsFound;
}
void Boggle::SolveBoardHelper(int row, int col, string currentWord){
// Base case: if the current position is out of bounds or already visited, return
if (row <0|| row >= BOARD_SIZE || col <0|| col >= BOARD_SIZE || visited[row][col]){
return;
}
// Add the current letter to the word
currentWord += board[row][col];
// Check if the current word is in the dictionary
if (dict.IsWord(currentWord)){
wordsFound.AddWord(currentWord); // Add to found words
}
// Mark the current cell as visited
visited[row][col]=1;
// Explore all 8 directions (up, down, left, right, diagonals)
static int direction[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
for (int i =0; i <8; ++i){
SolveBoardHelper(row + direction[i][0], col + direction[i][1], currentWord);
}
// Backtrack: unmark the current cell
visited[row][col]=0;
}
void Boggle::PrintBoard(ostream& output){
for (int i =0; i < BOARD_SIZE; ++i){
for (int j =0; j < BOARD_SIZE; ++j){
output << board[i][j]<<"";
}
output << endl;
}
}
void Boggle::SaveSolve(string filename){
ofstream file(filename);
if (file.is_open()){
for (const string& word : wordsFound.GetAllWords()){
file << word << endl;
}
file.close();
}
}
error: forming reference to void
45| for (const string& word : wordsFound.GetAllWords()){
error: forming reference to void
99| for (const string& word : wordsFound.GetAllWords()){
|^
I got an error because of these lines. please help me fix this to let this code working.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!