#include #include #include #include using namespace std; class toLower {public: char operator() (char c) const {return tolower(c);}}; int main() { ifstream fin; string fileInput; //Create a list const int MAX_INPUTS = 10; int nInput = 0; string input[MAX_INPUTS]; cout << "Enter file to open: "; cin >> fileInput; cin.ignore(1000, 10); fin.open(fileInput.c_str()); if (!fin.good()) { cout << "Unable to open file: " << fileInput << "\n"; throw "I/O error"; } while (fin.good()) { string aInput; fin >> aInput; fin.ignore(1000, 10); //Check for blank lines if (aInput.length() > 0) { //Check for duplicates bool good = true; for (int i = 0; i <= nInput; i++) { if (input[i] == aInput) { good = false; break; } //if } //for //Stop at 10names if (good) { if (nInput < MAX_INPUTS) { input[nInput++] = aInput; } } //if } //if } //while //Sort alphabetically for (int i = 0; i < nInput; i++) { for (int j = i + 1; j < nInput; j ++) { string temp1 = input[i]; transform(input[i].begin(), input[i].end(), input[i].begin(), toLower()); if (input[i] > input[j]) { string temp = input[i]; input[i] = input[j]; input[j] = temp; if (input[j] != temp1) { input[j] = temp1; } } else { if (input[i] != temp1) { input[i] = temp1; } } } } for (int i = 0; i < nInput; i++) { cout << input[i] << "\n"; } return 0; }