Guest User

Untitled

a guest
Jun 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. // CREATE A SOUNDEX CODE
  2. // * Parameter list includes the string of characters that are to be converted to code and a variable to save the code respectively.
  3. void SoundsAlike(const char input[], char scode[])
  4. {
  5. scode[0] = toupper(input[0]); // First character of the string is added to the code
  6.  
  7. int matchCount = 1;
  8. int codeCount = 1;
  9. while((matchCount < strlen(input)) && (codeCount < 4))
  10. {
  11. if(((input[matchCount] == 'b') || (input[matchCount] == 'p') || (input[matchCount] == 'v') || (input[matchCount] == 'f')) && (scode[codeCount-1] != 1))
  12. {
  13. scode[codeCount] = 1;
  14. codeCount++;
  15. }
  16. else if(((input[matchCount] == 'c') || (input[matchCount] == 'g') || (input[matchCount] == 'j') || (input[matchCount] == 'k') || (input[matchCount] == 'q') || (input[matchCount] == 's') || (input[matchCount] == 'x') || (input[matchCount] == 'z')) && (scode[codeCount-1] != 2))
  17. {
  18. scode[codeCount] = 2;
  19. codeCount++;
  20. }
  21. else if(((input[matchCount] == 'd') || (input[matchCount] == 't')) && (scode[codeCount-1] != 3))
  22. {
  23. scode[codeCount] = 3;
  24. codeCount++;
  25. }
  26. else if((input[matchCount] == 'l') && (scode[codeCount-1] != 4))
  27. {
  28. scode[codeCount] = 4;
  29. codeCount++;
  30. }
  31. else if(((input[matchCount] == 'm') || (input[matchCount] == 'n')) && (scode[codeCount-1] != 5))
  32. {
  33. scode[codeCount] = 5;
  34. codeCount++;
  35. }
  36. else if((input[matchCount] == 'r') && (scode[codeCount-1] != 6))
  37. {
  38. scode[codeCount] = 6;
  39. codeCount++;
  40. }
  41. matchCount++;
  42. }
  43.  
  44. while(codeCount < 4)
  45. {
  46. scode[codeCount] = 0;
  47. codeCount++;
  48. }
  49. scode[4] = '';
  50.  
  51. cout << scode << endl;
  52. }
  53.  
  54. scode[codeCount] = 1;
  55.  
  56. scode[codeCount] = '1';
  57.  
  58. void Soundex( const string & input, string & output ) {
  59. for ( int i = 0; i < input.length(); i++ ) {
  60. char c = input[i]; // get character from input
  61. if ( c === .... ) { // if some decision
  62. output += 'X'; // add some character to output
  63. }
  64. else if ( ..... ) { // more tests
  65. }
  66. }
  67. }
Add Comment
Please, Sign In to add comment