#include #include #include #include using namespace std; char f_transform( char
ID: 3757820 • Letter: #
Question
#include #include #include #include using namespace std; char f_transform( char c ) { string consonants[ 6 ] = { "BFPV", "CGJKQSXZ", "DT", "L", "MN", "R" }; for (int i = 0; i < 6; i++) if (consonants[ i ].find( c ) != string::npos) return (i +1) +'0'; return c; } string soundex( const string& s ) { string result; // Validate s if (std::find_if( s.begin(), s.end(), std::not1(std::ptr_fun(std::isalpha)) ) != s.end()) return result; // result <-- uppercase( s ) result.resize( s.length() ); std::transform( s.begin(), s.end(), result.begin(), std::ptr_fun(std::toupper) ); // Convert Soundex letters to codes std::transform( result.begin() +1, result.end(), result.begin() +1, f_transform ); // Collapse adjacent identical digits result.erase( std::unique( result.begin() +1, result.end() ), result.end() ); // Remove all non-digits following the first letter result.erase( std::remove_if( result.begin() +1, result.end(), std::not1(std::ptr_fun(std::isdigit)) ), result.end() ); result += "000"; result.resize( 4 ); return result; } int main() { string userInput; string converted; cout << "Input string to be converted: "; cin >> userInput; converted = soundex(userInput); cout << "Original: " << userInput << endl << "Soundex: " << converted << endl; }
Explanation / Answer
write ac++ program which represents asoundex index system . your system acts as the following :
*reads string from afile "name.txt" .each string less than 16 characters long .this string represents sounding names or namees with similar spelling .
* your task is to convert asequense of names into the corresponding sonundex codees for easy retrieval .use afunction for conversion.
*stores the codes in an array and sorts is ascending.
*lets the main program write out both forms on afile "output.txt".
* asoundex code always consists of aletter followed by three digits . such that :
1/ the first letter of aname appears "unencoded"as the first character of the soundex code. and it's capitalized . it is also the only letter.
2/ the letters "a ;e;i;o;u;y;w;h" are never encoded when they are not the first character in aword . they do sreve .however ; to break sequences of like coded letters" see the next rule"
3/ all other letters encoded accoirding to the following table .excpet when they immediatly follow aletter "including the first letter" that would be encoded with the same code digit .according to the table :
1: B ,P,F,V.
2: C ,S,K,G,J,Q,X,Z.
3:D,T.
4:L.
5:M,N.
6:R.
EXAMPLE:
INPUT .... OUTPUT
LEE ..... LEE=>L000
Kuhne EBELL ................. Kuhne=>K500
EBELL=>E140
ebelson ebelson=>E142
SCHAEFER SCHAAK SCHAEFER=>S160
SCHAAK=>S200
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.