Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Joel Bares
- */
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- void userInput(string []);
- void ascendSort(string[], int);
- void binarySearch(string[], int);
- ofstream textInput;
- ofstream screenOutput;
- ofstream fileOutput;
- string inputFileName, fileOutputName;
- ifstream inputFile;
- int main()
- {
- const int FSIZE = 1024; // size of file (1024 elements)
- string fArray[FSIZE]; // declare array for file
- textInput.open("textInput.txt");
- screenOutput.open("screenOutput.txt");
- userInput(fArray);
- ascendSort(fArray, FSIZE);
- textInput.close();
- screenOutput.close();
- fileOutput.close();
- return 0;
- }
- void userInput(string fArray[])
- {
- int i = 0;
- string word;
- cout << "Please enter the location and name of where you would like to save the output file. Example: C:\\user\\desktop" << endl;
- getline(cin, fileOutputName);
- cin.ignore;
- fileOutput.open(fileOutputName);
- fileOutput << "Please enter the location and name of where you would like to save the output file. Example: C:\\user\\desktop" << endl;
- fileOutput << fileOutputName << endl;
- fileOutput << "Please enter the location and name of where you would like to save the output file. Example: C:\\user\\desktop" << endl;
- do
- {
- cout << "Please enter the location and name of the file you wish to read from. Example: C:\\user\desktop\filename" << endl;
- fileOutput << "Please enter the location and name of the file you wish to read from. Example: C:\\user\desktop\filename" << endl;
- getline(cin, inputFileName);
- fileOutput << inputFileName << endl;
- if (inputFile)
- {
- inputFile.open(inputFileName);
- while (inputFile >> word)
- {
- fArray[i++] = word;
- fileOutput << word << endl;
- }
- }
- else
- {
- cout << "There was an error in reading the file, please try again." << endl;
- fileOutput << "There was an error in reading the file, please try again." << endl;
- }
- } while (!inputFile);
- }
- void ascendSort(string fArray[], int size)
- {
- int startScan, minIndex;
- string minValue;
- for (startScan = 0; startScan < (size - 1); startScan++)
- {
- minIndex = startScan;
- minValue = fArray[startScan];
- for (int index = startScan + 1; index < size; index++)
- {
- if (fArray[index] < minValue)
- {
- if (string::length(fArray[index]) == 1)
- {
- }
- minValue = fArray[index];
- minIndex = index;
- }
- }
- fArray[minIndex] = fArray[startScan];
- fArray[startScan] = minValue;
- }
- for (int i = 0; i < (size - 1); i++)
- {
- fileOutput << fArray[i] << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement