Program. #include <stdio.h>. #include<stdlib.h>. #inclu

Added on - 21 Sep 2019

  • 9

    pages

  • 2474

    words

  • 238

    views

  • 0

    downloads

Showing pages 1 to 3 of 9 pages
Program#include<stdio.h>#include<stdlib.h>#include<ctime>#include<string>#include<vector>#include<algorithm>#define_CRT_SECURE_NO_WARNINGSusingnamespacestd;intgenerateUniqueInt(){staticvector<int> generatedValues;intnum;srand((unsigned)time(0));while(1){num = rand() % 20;if(find(generatedValues.begin(), generatedValues.end(), num)==generatedValues.end()) {generatedValues.push_back(num);break;}}returnnum;}intmain(){char* words[] = {"SAMPLE","WORD","ABOUT","ABOVE","GRADE","INDEX","INNER","JOINT","JAPAN","LASER","GRASS","SPACE","LAUGH","LABEL","STAND","START","SPEED","YOUTH","STAGE","WRITE"};charletters[] ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};enumMETHOD{TOP_BOTTOM,LEFT_RIGHT,DIAGONAL};charboard[10][10];boolloop =true;intchoice;while(loop){printf("Menu\n");printf("******\n");printf("1) Generate a new Word Puzzle\n");printf("2) Exit\n");printf("Enter your choice: ");scanf_s("%d",&choice);switch(choice){case1:{srand((unsigned)time(0));for(inti = 0; i < 10; i++)for(intj = 0; j < 10; j++)board[i][j] ='-';staticvector<char*> selectedWords;staticvector<char*> selectedFirstCell;
staticvector<char*> selectedSecondCell;staticvector<bool> wordFound;for(inti = 0; i < 4; i++){char* selectedWord = words[generateUniqueInt()];selectedWords.push_back(selectedWord);wordFound.push_back(false);METHODtype =static_cast<METHOD>(rand() % 3);switch(type){caseTOP_BOTTOM:while(1){intselectRow = rand() % 10;intselectCol = rand() % 10;if(selectRow + strlen(selectedWord)- 1 <10){intloc = 0;boolcorrectWord =false;for(intj = selectRow; j <(selectRow + strlen(selectedWord)); j++){if(board[j][selectCol] =='-'|| board[j][selectCol] == selectedWord[loc++])correctWord =true;else{correctWord =false;break;}}if(correctWord){loc = 0;char*str= (char*)malloc(5);str[0] ='\0';_itoa_s(selectRow,str,sizeofstr,10);chartemp[2] ={ letters[selectCol],'\0'};strcat_s(str, 5, temp );selectedFirstCell.push_back(str);intj;for( j = selectRow; j <(selectRow + strlen(selectedWord)); j++)if(board[j][selectCol]=='-'|| board[j][selectCol] == selectedWord[loc])board[j][selectCol] = selectedWord[loc++];
char*str1=(char*) malloc(5);str1[0] ='\0';_itoa_s(j - 1, str1,sizeofstr1, 10);chartemp1[2] ={ letters[selectCol],'\0'};strcat_s(str1, 5, temp1);selectedSecondCell.push_back(str1);break;}}}break;caseLEFT_RIGHT:while(1){intselectRow = rand() % 10;intselectCol = rand() % 10;if(selectCol + strlen(selectedWord) - 1 <10){intloc = 0;boolcorrectWord =false;for(intj = selectCol; j <(selectCol + strlen(selectedWord)); j++){if(board[selectRow][j] =='-'|| board[selectRow][j] == selectedWord[loc++])correctWord =true;else{correctWord =false;break;}}if(correctWord){loc = 0;char*str=(char*) malloc(5);str[0] ='\0';_itoa_s(selectRow, str,sizeofstr, 10);chartemp[2] ={ letters[selectCol],'\0'};strcat_s(str, 5, temp);selectedFirstCell.push_back(str);intj;for( j = selectCol; j <(selectCol + strlen(selectedWord)); j++)
desklib-logo
You’re reading a preview
card-image

To View Complete Document

Become a Desklib Library Member.
Subscribe to our plans

Download This Document