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

I wrote this C++ code but it doesn\'t work can some PLEASE fix it. Thank You. I

ID: 3666313 • Letter: I

Question

I wrote this C++ code but it doesn't work can some PLEASE fix it. Thank You. I don't what i did wrong but the output doesn't show properly it is weird symbols. THANK YOU.

MY CODE -------

#include <iostream>
#include <fstream>
using namespace std;

const int ROWSIZE = 10;
const int COLSIZE = 5;
const int NUMSIZE = 8;
int wordcount=0;
/**
* Taleph - One Number Word Generator
*/
void combine(char* array,char letters[][COLSIZE], char* buildArr, int index, ofstream& ofile)
{
   if(index==NUMSIZE)
   {
       ofile<<buildArr<<endl;
       return;
   }
   for(int i=0;i<COLSIZE;i++)
   {
       buildArr[index]=letters[array[index]-'0'][i];
       combine(array,letters,buildArr,index+1,ofile);
       if(array[index]==0||array[index]==1)
           return;
   }
}
//main function
int main() {
   char array[NUMSIZE]; //user input - do not go beyond 7 chars and a null byte!
   //2-d array of letters
   char letters[ROWSIZE][COLSIZE]={
           {'0','','','',''},
           {'1','','','',''},
           {'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',''},
   };
   char buildArr[ROWSIZE]={'0','','','','','0','','','',''}; //output
   cout<<"Enter a 7 digit number (Do not enter number starting with 0 or 1):";
   for(int i=0;i<NUMSIZE-1;i++)
   {
       cin>>array[i];
   }
   cout<<"Entered number:"<<array<<endl;
   string ofilename="output.txt";
   ofstream ofile(ofilename.c_str());
   combine(array,letters,buildArr,0,ofile);
   cout<<"Output is in "<<ofilename<<endl;
   ofile.close();
   return 0;
}

----------------------------

This is what the code was supposed to be written on.

0 9 Many people find it difficult to memorize phone numbers, so they use the correspondence between digits on develop the seven-letter word "NUMBERS. Businesses frequently attempt to get telephone numbers that are easy for their clients to remember. Ifa TAKEOUT. Each seven-digit phone number corresponds to many separate seven-letter words the owner of a barber shop would be pleased to know that the shop's telephone number, 424-7288 corresponds to "HAIRCUT." A veterinarian with the phone number 738-2273 would be happy to know that the number corresponds to "PETCARE. Write a program that, given a seven-digit number, writes to a file every possible seven-letter word corresponding to that number. There are 2187 (3 to the seventh power) such words. Avoid phone numbers 2

Explanation / Answer

#include <iostream>
#include <map>

/* struct that holds up to 4 characters */

struct LetterQuad {

char l1, l2, l3, l4;

LetterQuad(char a, char b, char c, char d = '')

:l1(a), l2(B)/>, l3(c), l4(d) {

}

};

typedef std::map<int, LetterQuad*> PhoneKeyMap;

int main() {

PhoneKeyMap keyMap;

/* numbers 0 and 1 dont have letters */

keyMap[0] = new LetterQuad('', '', '');

keyMap[1] = new LetterQuad('', '', '');

char c = 'a';

for(int i=2; i<=9; i++) {

/* Numbers 7 and 9 have 4 letters rather than 3 */

if(i == 7 || i == 9) {

keyMap[i] = new LetterQuad(c, c++, c++, c++);

}

else {

keyMap[i] = new LetterQuad(c, c++, c++);

}
c++;

}

/* a random phone number */

std::string phoneNumber = "6843354";

for(std::string::iterator i = phoneNumber.begin(); i != phoneNumber.end(); i++) {

/* Print out letters that corrispond to each number */

/* *i - '0' converts the character *i to a char */

std::cout<<*i<<" = "<<keyMap[*i - '0']->l1;

std::cout<<keyMap[*i - '0']->l2;

std::cout<<keyMap[*i - '0']->l3;

std::cout<<keyMap[*i - '0']->l4<<std::endl;
// You have access to each character available for each number

// Now you need to find all possible word corrispondances

}

/* dealloc keypad map */

for(PhoneKeyMap::iterator i = keyMap.begin(); i != keyMap.end(); i++) {

delete i->second;

}

return 0;

}