#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <istream>
using namespace std;
void numbers(string word, char phoneNumber[], int loc);
int numOfChoices(char digit);
char letter(char digit, int perm);
int numOfChoicesInt(int digit);
void record(string word);
int wordNumber = 1;
int _tmain(int argc, _TCHAR* argv[])
{
char phoneNumber[8];
string word;
fstream inputFile;
//Prompt Phone Number
cout << "Phone Number: ";
cin >> phoneNumber;
inputFile.open("memorableNumber.txt", ios::in);
inputFile.close();
for (int loc = 0; loc < 7; loc++)
{
numbers(word, phoneNumber, loc);
}
return 0;
}
//main loop
void numbers(string word, char phoneNumber[], int loc)
{
//goes through each possible position
int options = numOfChoices(phoneNumber[loc]);
for (int perm = 0; perm < options; perm++)
{
word += letter((phoneNumber[loc]), perm);
//recursion
if (loc < 7)
numbers(word, phoneNumber, (loc + 1));
//records the "word"
if (word.length() == 7)
record(word);
}
}
//determines amount of choices
int numOfChoices(char digit)
{
int result = 3;
if (digit > '0' && digit < '2')
result = 0;
else if (digit == '7' || digit == '9')
result = 4;
return result;
}
//goes through each possible letter per place
char letter(char digit, int perm)
{
int prevLetters = 0;
for (int i = 0; i < (digit - '0'); i++)
prevLetters += numOfChoicesInt(i);
return 'A' + prevLetters + perm;
}
//determines amount of choices
int numOfChoicesInt(int digit)
{
int result = 3;
if (digit < 2)
result = 0;
else if (digit == 7 || digit == 9)
result = 4;
return result;
}
//record
void record(string word)
{
ofstream outputFile;
outputFile.open("memorableNumber.txt", ios::app);
outputFile << "Word " << wordNumber << ": " << word << endl;
outputFile.close();
wordNumber++;
}
/*
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890ABCDEFGHIJKLMNOP
22233344455566677778889999
*/