fork download
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <fstream>
  5. #include <istream>
  6.  
  7. using namespace std;
  8.  
  9. void numbers(string word, char phoneNumber[], int loc);
  10. int numOfChoices(char digit);
  11. char letter(char digit, int perm);
  12. int numOfChoicesInt(int digit);
  13. void record(string word);
  14. int wordNumber = 1;
  15.  
  16. int _tmain(int argc, _TCHAR* argv[])
  17. {
  18. char phoneNumber[8];
  19. string word;
  20. fstream inputFile;
  21.  
  22. //Prompt Phone Number
  23. cout << "Phone Number: ";
  24. cin >> phoneNumber;
  25.  
  26. inputFile.open("memorableNumber.txt", ios::in);
  27. inputFile.close();
  28.  
  29. for (int loc = 0; loc < 7; loc++)
  30. {
  31. numbers(word, phoneNumber, loc);
  32. }
  33. return 0;
  34. }
  35.  
  36. //main loop
  37. void numbers(string word, char phoneNumber[], int loc)
  38. {
  39. //goes through each possible position
  40. int options = numOfChoices(phoneNumber[loc]);
  41.  
  42. for (int perm = 0; perm < options; perm++)
  43. {
  44. word += letter((phoneNumber[loc]), perm);
  45. //recursion
  46. if (loc < 7)
  47. numbers(word, phoneNumber, (loc + 1));
  48.  
  49. //records the "word"
  50. if (word.length() == 7)
  51. record(word);
  52.  
  53. }
  54. }
  55. //determines amount of choices
  56. int numOfChoices(char digit)
  57. {
  58. int result = 3;
  59. if (digit > '0' && digit < '2')
  60. result = 0;
  61. else if (digit == '7' || digit == '9')
  62. result = 4;
  63. return result;
  64. }
  65. //goes through each possible letter per place
  66. char letter(char digit, int perm)
  67. {
  68. int prevLetters = 0;
  69.  
  70. for (int i = 0; i < (digit - '0'); i++)
  71. prevLetters += numOfChoicesInt(i);
  72.  
  73. return 'A' + prevLetters + perm;
  74. }
  75. //determines amount of choices
  76. int numOfChoicesInt(int digit)
  77. {
  78. int result = 3;
  79. if (digit < 2)
  80. result = 0;
  81. else if (digit == 7 || digit == 9)
  82. result = 4;
  83. return result;
  84. }
  85. //record
  86. void record(string word)
  87. {
  88. ofstream outputFile;
  89. outputFile.open("memorableNumber.txt", ios::app);
  90. outputFile << "Word " << wordNumber << ": " << word << endl;
  91. outputFile.close();
  92. wordNumber++;
  93. }
  94.  
  95.  
  96. /*
  97. ABCDEFGHIJKLMNOPQRSTUVWXYZ
  98. 1234567890ABCDEFGHIJKLMNOP
  99. 22233344455566677778889999
  100. */
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:20: fatal error: stdafx.h: No such file or directory
 #include "stdafx.h"
                    ^
compilation terminated.
stdout
Standard output is empty