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

Hi please I have a scrabble project in c++ and I want to solve it . I want to ma

ID: 3874045 • Letter: H

Question

Hi please I have a scrabble project in c++ and I want to solve it . I want to make a scrabble game in c++ . I want to use iostream and string and stdafx.h libraries only .

there are two players , they want to make words from these caracters :ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQ

RSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRST

these 2 players have to make words from these caracters till these caracters done .

at the end all the words that the 2 players made by (cin) must be viewed on the screen by (cout ).

every time a player enter a word, the characters of this word must be eliminated from the list of characters

Explanation / Answer

/* The list of characters currently have multiple occurences of each letter. Once a word is entered, it is not clear that all the occurences of a character
present in the word should be removed or just one occurence. Currently the code removes the occurences depending on the number of occurences of a letter
in the word itself. for e.g if the word is apple, then two occurences of p will be removed from the list of characters along with one occurences of a,l and e */

#include<iostream>
#include<string>

using namespace std;

int main(){

   cout << "******Welcome to Game of Scrabbles****** ";
   cout << "Two player game.Each player will get the set of characters (A-Z).Every player ";
   cout << " will enter a word and corresponding characters will be removed from the set (A..Z) ";
   cout << " .Game will continue till all the characters are used up and at the end all the words ";
   cout << " will be output on the screen ";

   string p1_set = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRST";
   string p2_set = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRST";

   string p1_new = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRST";
   string p2_new = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRST";


   string p1_words[100];
   string p2_words[100];
   string word;
   char c;
   int found;

   int count1 = 0;
   int count2 = 0;
   while(p1_new.length() > 0 || p2_new.length() > 0){

      if (p1_new.length() > 0){
         cout << " Player1 set of characters:" << p1_new << endl << endl;;
         cout << " Player1: Enter a word:";
         cin >> word;
         p1_words[count1] = word;
         p1_new = "";
         for (int i = 0; i<p1_set.length(); i++){
           found = 0;
           for(int j=0; j<word.length(); j++){
              c = word[j];
              if (word[j] >= 'a' && word[j] <= 'z'){
                 c = word[j] - 32;
              }
              if (c == p1_set[i]){
                     found = 1;
                     word[j] = ' ';
                     break;
              }
           }
           if (found == 0)
              p1_new = p1_new + p1_set[i];
         }
         count1++;
         p1_set = p1_new;
      }

      if (p2_new.length() > 0){
         cout << " Player2 set of characters:" << p2_new << endl;
         cout << " Player2: Enter a word:";
         cin >> word;
         p2_words[count2] = word;
         p2_new = "";
         for (int i = 0; i<p2_set.length(); i++){
           found = 0;
           for(int j=0; j<word.length(); j++){
              c = word[j];
              if (word[j] >= 'a' && word[j] <= 'z'){
                 c = word[j] - 32;
              }
              if (c == p2_set[i]){
                     found = 1;
                     word[j] = ' ';
                     break;
              }
           }
           if (found == 0)
             p2_new = p2_new + p2_set[i];
         }
         count2++;
         p2_set = p2_new;
      }
   }
   cout << "Player1 words: ";
   for(int i = 0; i<count1; i++){
       cout << p1_words[i] << endl;
   }
   cout << "Player2 words: ";
   for(int i = 0; i<count2; i++){
       cout << p2_words[i] << endl;
   }

   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote