### Telephone number to word generator

(Telephone-Number Word Generator) Standard telephone keypads contain the digits zero through nine. The numbers two through nine each have three letters associated with them (Fig. 18.16). Many people find it difficult to memorize phone numbers, so they use the correspondence between digits and letters to develop seven-letter words that correspond to their phone numbers. For example, a person whose telephone number is 686-2377 might use the correspondence indicated in Fig. 18.16 to develop the seven-letter word " NUMBERS ." Every seven-letter word corresponds to exactly one seven-digit telephone number. A restaurant wishing to increase its takeout business could surely do so with the number 825-3688 (i.e., "TAKEOUT").

Every seven-letter phone number corresponds to many different seven-letter words. Unfortunately, most of these words represent unrecognizable juxtapositions of letters. It is possible, however, that the owner of a barbershop would be pleased to know that the shop's telephone number, 424-7288, corresponds to "HAIRCUT." The owner of a liquor store would no doubt be delighted to find that the store's number, 233-7226, corresponds to "BEERCAN." A veterinarian with the phone number 738-2273 would be pleased to know that the number corresponds to the letters "PETCARE." An automotive dealership would be pleased to know that its phone number, 639-2277, corresponds to "NEWCARS."

2- ABC 3- DEF 4- GHI 5- JKL 6- MNO 7- PRS 8- TUV 9- WXY

Write a GUI program that, given a seven-digit number, uses a StreamWriter object to write to a file every possible seven-letter word combination corresponding to that number. There are 2,187 (3^7 ) such combinations. Avoid phone numbers with 1 and 0.

My codes don't even compile. Pleas HELP!

#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class Point{

private:
char ipress[7];

public:
Point(){};
friend istream& operator>>(istream& input, Point& p);
friend ostream& operator<<(ostream& output, const Point& p);
friend Point NumWorGen(Point pToi);
friend int main(int argc, char** argv);
};

/*Overload >> operator for Point objects.
*Accepts input in xxx-xxxx format*/
istream& operator>>(istream& input, Point& p){
char temp;
cout << "Please Enter a Phone Number (xxx-xxxx & Omit 1's and 0's):" << endl;

input >> p.ipress[0] >> p.ipress[1] >> p.ipress[2] >> temp >> p.ipress[3] >> p.ipress[4] >> p.ipress[5] >> p.ipress[6];
//Input cannot be 0 or 1. How to fix this?
if(p.ipress[0]=='0'||'1'||p.ipress[1]=='0'||'1'||p.ipress[2]=='0'||'1'||p.ipress[3]=='0'||'1'||p.ipress[4]=='0'||'1'||p.ipress[5]=='0'||'1'||p.ipress[6]=='0'||'1'){
cerr << "::ERROR::DO NOT ENTER 1's and 0's::"<<endl;
}
return input;
}

ostream& operator<<(ostream& output, const Point& p){
cout << "You have entered: "<<endl;
output << p.ipress[0]<<p.ipress[1]<<p.ipress[2]<<"-"<<p.ipress[3]<<p.ipress[4]<<p.ipress[5]<<p.ipress[6]<<endl;
return output;
}

//telephone number to word generator

Point NumWorGen(Point pToi){

char letArray[3][10] =
{
' ',
' ',
'ABC',
'DEF',
'GHI',
'JKL',
'MNO',
'PRS',
'TUV',
'WXY'
};

pToi.ipress[2] = letArray[rand()%2+0][2];

pToi.ipress[3] = letArray[rand()%2+0][3];

pToi.ipress[4]=letArray[rand()%2+0][4];

pToi.ipress[5]=letArray[rand()%2+0][5];

pToi.ipress[6]=letArray[rand()%2+0][6];

pToi.ipress[7]=letArray[rand()%2+0][7];

pToi.ipress[8]=letArray[rand()%2+0][8];

pToi.ipress[9]=letArray[rand()%2+0][9];

return pToi;
};

int main(int argc, char** argv) {

Point userP;
cin >> userP;
cout << userP << endl;

//How can I make variables in ' if statements ' transfer down here. Reference? but how?

Point* middleman=new Point;
for (int k;k<2187;k++) //for all possible combinations
{
*middleman = userP;
NumWorGen(*middleman);
cout << *middleman;
delete middleman;
}
// I might need to add a loop for all the possible combinations

return 0;
}
Topic archived. No new replies allowed.