#include #include // for ifstream #include "CPstring.h" #include "prompt.h" #include "vector.h" // file: morse.cc // author Dietolf Ramm; date: 11/3/96 // read text, as characters, output equivalent Morse code. bool LoadCode(Vector & morse) // postcondition: morse contains a translate table and returns true // or returns an error code of false { int k = 0; string s; ifstream init; init.open("MorseCode"); while (getline(init, s)) { morse[k] = s; k++; } return k == 256; } int main() { Vector morse(256); if (LoadCode(morse) != true) { cout << "Code loading error. Aborted." << endl; exit(1); } string filename = PromptString("Enter name of input file: "); ifstream inchar; inchar.open(filename); char c, lastc = ' '; while (inchar.get(c)) { cout << morse[c] << " "; if (c == ' ' && lastc != ' ') cout << endl; lastc = c; } cout << endl; return 0; } Sample output morse Enter name of input file: honor.short .- -. . ... ... . -. - .. .- .-.. ..-. . .- - ..- .-. . --- ..-. -.. ..- -.- . ..- -. .. ...- . .-. ... .. - -.-- .. ... .. - ... -.-. --- -- -- .. - -- . -. - - --- .. -. - . --. .-. .. - -.-- .- -. -.. . - .... .. -.-. .- .-.. -.-. --- -. -.. ..- -.-. - cat honor.short An essential feature of Duke University is its commitment to integrity and ethical conduct.