rendered paste body#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
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++) {
string temp1 = aInput;
string temp2 = input[i];
transform(aInput.begin(), aInput.end(), aInput.begin(), toLower());
transform(input[i].begin(), input[i].end(), input[i].begin(), toLower());
if (input[i] == aInput) {
good = false;
break;
} //if
if (aInput != temp1) {
aInput = temp1;
}
if (input[i] != temp2) {
input[i] = temp2;
}
} //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];
string temp2 = input[j];
transform(input[i].begin(), input[i].end(), input[i].begin(), toLower());
transform(input[j].begin(), input[j].end(), input[j].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;
}
if (input[i] != temp2) {
input[i] = temp2;
}
}
else {
if (input[i] != temp1) {
input[i] = temp1;
}
if (input[j] != temp2) {
input[j] = temp2;
}
} //else
} //for
} //for
for (int i = 0; i < nInput; i++) {
cout << input[i] << "\n";
}
return 0;
}