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

Write this program in C++ 0 9 Many people find it difficult to memorize phone nu

ID: 3665876 • Letter: W

Question

Write this program in C++

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

Solution:

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

#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;
}

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