Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming language is C++. Crossword puzzle is generated below. Show code and

ID: 3783745 • Letter: P

Question

Programming language is C++. Crossword puzzle is generated below. Show code and an example of the output on Putty when done.

DOWN 2 Teague 326 (Note: This is an example, not the correct room number) ACROSS 1. HRBB 312 (Note: This is an example not the correct room number) BRO o K S U H Now write a C++ program named hw1pr1.cpp which prints the clues and the puzzle using lots of cout statements. Do not turn in the completed crossword puzzle running your program will display it on the screen like the example above, except yours will have 15 names.

Explanation / Answer

#include <iostream>

using namespace std;

#include <string>

#define n 9

char g[n][n];  

string word[n];

int w,r,c;

void creatGrid()

    {for(r=0;r<n;r++) for(c=0;c<n;c++) g[r][c]='A'+rand()%26;            

    for(r=0;r<n;r++){for(c=0;c<n;c++) cout<<g[r][c]<<" "; cout<<" "<<endl;}

    }

void pickWords()       

{   int x,h,  

    d, t[n][4]; //t[n][r,c,l,d]; d(0..7, CCW) direction of the word to consider for search,

    h=(n+1)/2;

    for(w=0;w<n;w++) {for(d=0;d<2;d++)t[w][d]=rand()%n; t[w][2]=h;}  

    h=n/2;

    for(w=0;w<n;w++)

    {   x=rand()%3;

        if(t[w][0]>h && t[w][1]<h) t[w][3]=x;   else

        if(t[w][0]>h && t[w][1]>h) t[w][3]=x+2; else

        if(t[w][0]<h && t[w][1]>h) t[w][3]=x+4; else

        if(t[w][0]<h && t[w][1]<h) t[w][3]=(x+6)%8;

    }

    cout<<" r,c,l,d ======= "; for(w=0;w<n;w++){for(d=0;d<4;d++)cout<<t[w][d]<<" "; cout<<endl;} //PRINT THE CHOICES t[][]

    cout<<" words ===== ";                                                                    

    for(w=0;w<n;w++)            

    {   r=t[w][0]; c=t[w][1];      

        for(int h=0;h<t[w][2];h++)

        switch(t[w][3])            

        {                                                           

        case 0: cout<<g[r ][c+h]; word[w]+=g[r ][c+h]; break;

        case 1: cout<<g[r-h][c+h];    word[w]+=g[r-h][c+h]; break;

        case 2: cout<<g[r-h][c ];    word[w]+=g[r-h][c ]; break;

       case 3: cout<<g[r-h][c-h];    word[w]+=g[r-h][c-h]; break;

        case 4: cout<<g[r ][c-h];    word[w]+=g[r ][c-h]; break;

        case 5: cout<<g[r+h][c-h];   word[w]+=g[r+h][c-h]; break;

        case 6: cout<<g[r+h][c ];    word[w]+=g[r+h][c ]; break;

        case 7: cout<<g[r+h][c+h];    word[w]+=g[r+h][c+h];          

        }   cout<<endl;

    }   cout<<endl;                  

    for(w=0;w<n;w++)cout<<word[w]<<endl;     }

void findWord()

{   for(w=0;w<n;w++)                           

    {   int l; string s; s=word[w]; l=s.length();  

        for(r=0;r<n;r++) for(c=0;c<n;c++)        

    ;

    }

}

void main()

{   creatGrid(); pickWords();

    findWord();

}