
for this code pls make a pseudocode or a flow chart
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <
#include <string>
const int GRID_SIZE = 5;
// Function to generate a random letter
char generateRandomLetter() {
return 'A' + rand() % 26;
}
// Function to generate a random grid
void generateGrid(char grid[GRID_SIZE][GRID_SIZE]) {
for (int i = 0; i < GRID_SIZE; i++) {
for (int j = 0; j < GRID_SIZE; j++) {
grid[i][j] = generateRandomLetter();
}
}
}
// Function to display the grid
void displayGrid(const char grid[GRID_SIZE][GRID_SIZE]) {
for (int i = 0; i < GRID_SIZE; i++) {
for (int j = 0; j < GRID_SIZE; j++) {
std::cout << grid[i][j] << ' ';
}
std::cout << std::endl;
}
}
// Function to check if a word is found in the grid
bool isWordFound(const std::string& word, const char grid[GRID_SIZE][GRID_SIZE], int row, int col, std::vector<std::vector<bool>>& visited, int index) {
// Base cases for recursion
if (index == word.length()) {
return true; // All characters of the word have been found
}
if (row < 0 || row >= GRID_SIZE || col < 0 || col >= GRID_SIZE) {
return false; // Out of bounds
}
if (visited[row][col]) {
return false; // Already visited this cell for the current word
}
if (grid[row][col] != word[index]) {
return false; // Current character doesn't match
}
// Mark current cell as visited
visited[row][col] = true;
// Recursively search for the remaining characters in all eight directions
bool found = false;
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
if (i == 0 && j == 0) {
continue; // Skip the current cell
}
found = isWordFound(word, grid, row + i, col + j, visited, index + 1);
if (found) {
break;
}
}
if (found) {
break;
}
}
// Mark current cell as unvisited for the next word
visited[row][col] = false;
return found;
}
int main() {
srand(time(0));
char grid[GRID_SIZE][GRID_SIZE];
generateGrid(grid);
std::cout << "Welcome to Bad Spelling!" << std::endl;
std::cout << "Generated grid:" << std::endl;
displayGrid(grid);
while (true) {
std::string word;
std::cout << "\nEnter a word (or 'q' to quit): ";
std::cin >> word;
if (word == "q") {
break;
}
std::vector<std::vector<bool>> visited(GRID_SIZE, std::vector<bool>(GRID_SIZE, false));
bool found = false;
for (int i = 0; i < GRID_SIZE; i++) {
for (int j = 0; j < GRID_SIZE; j++) {
if (isWordFound(word, grid, i, j, visited, 0)) {
found = true;
break;
}
}
if (found) {
break;
}
}
if (found) {
std::cout << "The word '" << word << "' is found in the grid!" << std::endl;
} else {
std::cout << "The word '" << word << "' is not found in the grid." << std::endl;
}
}
return 0;
}

Step by stepSolved in 4 steps with 2 images

- C++languagearrow_forwardpiechart1<-function(){#open function #Function to graph a pie chart #assign values to un.teenager vector un.teenager<-c("20-29","30-39","40-49","50-59","60-69","70-79") #draw a pie chart of data pie(un.teenager) }close function trying to make a pie chart in Rarrow_forwardC PROGRAMMING LANGUAGEarrow_forward
- C programmingarrow_forwardCan you fix the code please on the first picture shows the error output. // Corrected code #define _CRT_SECURE_NO_WARNINGS #include "LibraryManagement.h" #include "Books.h" #include "DigitalMedia.h" #include "LibraryConfig.h" #include #include #include #include // Include the necessary header for boolean data type // Comparison function for qsort to sort Digital Media by ID int compareDigitalMedia(const void* a, const void* b) { return ((struct DigitalMedia*)a)->id - ((struct DigitalMedia*)b)->id; } // initializing library struct Library initializeLibrary() { struct Library lib; lib.bookCount = 0; lib.ebookCount = 0; lib.digitalMediaCount = 0; // Initialize book array for (int i = 0; i < MAX_BOOK_COUNT; i++) { lib.books[i].commonAttributes.id = -1; // Set an invalid ID to mark empty slot } // Initialize ebook array for (int i = 0; i < MAX_EBOOK_COUNT; i++) { lib.ebooks[i].commonAttributes.id = -1; }…arrow_forwardstruct remove_from_front_of_vector { // Function takes no parameters, removes the book at the front of a vector, // and returns nothing. void operator()(const Book& unused) { (/// TO-DO (12) ||||| // // // Write the lines of code to remove the book at the front of "my_vector". // // Remember, attempting to remove an element from an empty data structure is // a logic error. Include code to avoid that. //// END-TO-DO (12) /||, } std::vector& my_vector; };arrow_forward
- #include <iostream>#include <cstdlib>#include <time.h>#include <chrono> using namespace std::chrono;using namespace std; void randomVector(int vector[], int size){ for (int i = 0; i < size; i++) { //ToDo: Add Comment vector[i] = rand() % 100; }} int main(){ unsigned long size = 100000000; srand(time(0)); int *v1, *v2, *v3; //ToDo: Add Comment auto start = high_resolution_clock::now(); //ToDo: Add Comment v1 = (int *) malloc(size * sizeof(int *)); v2 = (int *) malloc(size * sizeof(int *)); v3 = (int *) malloc(size * sizeof(int *)); randomVector(v1, size); randomVector(v2, size); //ToDo: Add Comment for (int i = 0; i < size; i++) { v3[i] = v1[i] + v2[i]; } auto stop = high_resolution_clock::now(); //ToDo: Add Comment auto duration = duration_cast<microseconds>(stop - start); cout << "Time taken by function: " << duration.count()…arrow_forwardc++ language using addition, not get_sum function with this pseudocode: Function Main Declare Integer Array ages [ ] Declare integer total assign numbers = [ ] assign total = sum(ages) output "Sum: " & total end fucntion sum(Integer Array array) declare integer total declare integer index assign total = 0 for index = 0 to size(array) -1 assign total = total + array[ ] end return integer totalarrow_forwardUsing C++ Programming language: Assume you define a vector in the following way: vector<int> vec; Assign the value 10 to the first element of this vector. What is the statement you would use?arrow_forward
- Describe how arrays are used in a struct.arrow_forwardAlphabet Random Walk• Write a program to generate a random walk that spans a 10*10 character array (The initial values of the elements are all.). The program must randomly walk from one element to another, moving one element position up, down, left or right each time. The elements that have been visited are labeled with the letters A through Z in the order in which they were visitedarrow_forwardC++ Coding: Arrays Implement a two-dimensional character array. Use a nested loop to store a 12x6 flag. 5 x 2 stars as * Alternate = and – to represent stripe colors Use a nested loop to output the character array to the console.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





