you will write a program in \"C+\" that will create the a set of 16 semi-random
ID: 665349 • Letter: Y
Question
you will write a program in "C+" that will create the a set of 16 semi-random letters in a 4-by-4 grid and have the user enter in as many words as possible that can be made from these letters in a 3 minute time frame.
This game has been marketed as Boggle.The letters used come from 16 6-sided cubes (or dice) with one letter per side. Each of the 16 locations in the 4-by-4 grid will use one letter from one of the dice. Since the letters on each of the dice are pre-determined, we can call this a "semi-random" distribution. We will use the following dice combinations:
AAEEGN
ABBJOO
ACHOPS
AFFKPS
AOOTTW
CIMOTU
DEILRX
DELRVY
DISTTY
EEGHNW
EEINSU
EHRTVW
EIOSST
ELRTTY
HIMNUQu
HLNNRZ
You should use functions as much as possible when writing this program. You are REQUIRED to have
a function to determine and store the letters in the grid
a function to print out the letters to user
a function to monitor the users input of words and keep track of the 3 minutes of time
Explanation / Answer
#include <iostream>
#include <cstdlib>
using namespace std;
//function prototypes
void fillArray(char ch[][4]);
void printLetters(char ch[][4]);
void readWords(string words[]);
int main()
{
char ch[4][4]; //declaring char array to store 16 chars
string words[500];
fillArray(&ch); //calling functions
printLetters(ch);
readWords(&words);
return 0;
}
void fillArray(char ch[][4]){ //function to fill random chars
srand((unsigned)time(0));
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
ch[i][j] = 'a' + rand()%26;
}
}
}
void printLetters(char ch[][4]){ //function to print random chars to console
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
cout<<ch[i][j]<<" ";
}
}
}
void readWords(string words[]){ //reading words from user
time_t end = time(NULL) + 180; //allowed only 180 sec == 3 minutes
int i=0;
while (time(NULL) <= end)
{
cout<<" Enter word: ";
cin>>words[i]; //reading word from user
i++;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.