Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.78 KB | None | 0 0
  1. /*
  2.  
  3. Joel Bares
  4.  
  5.  
  6. */
  7.  
  8. #include <iostream>
  9. #include <fstream>
  10. #include <string>
  11.  
  12. using namespace std;
  13.  
  14. void userInput(string []);
  15. void ascendSort(string[], int);
  16. void binarySearch(string[], int);
  17.  
  18. ofstream textInput;
  19. ofstream screenOutput;
  20. ofstream fileOutput;
  21. string inputFileName, fileOutputName;
  22. ifstream inputFile;
  23.  
  24.  
  25.  
  26. int main()
  27. {
  28.     const int FSIZE = 1024; // size of file (1024 elements)
  29.     string fArray[FSIZE];   // declare array for file
  30.  
  31.     userInput(fArray);
  32.     ascendSort(fArray, FSIZE);
  33.  
  34.  
  35.  
  36.  
  37.  
  38.     return 0;
  39. }
  40.  
  41. void userInput(string fArray[])
  42. {
  43.     textInput.open("textInput.txt");
  44.     screenOutput.open("screenOutput.txt");
  45.  
  46.     int i = 0;
  47.     string word;
  48.  
  49.     cout << "Please enter the location and name of where you would like to save the output file. Example: C:\\user\\desktop" << endl;
  50.     getline(cin, fileOutputName);
  51.     cin.ignore;
  52.  
  53.     fileOutput.open(fileOutputName);
  54.  
  55.     fileOutput << "Please enter the location and name of where you would like to save the output file. Example: C:\\user\\desktop" << endl;
  56.     fileOutput << fileOutputName << endl;
  57.     screenOutput << "Please enter the location and name of where you would like to save the output file. Example: C:\\user\\desktop" << endl;
  58.  
  59.     do
  60.     {
  61.         cout << "Please enter the location and name of the file you wish to read from. Example: C:\\user\desktop\filename" << endl;
  62.         fileOutput << "Please enter the location and name of the file you wish to read from. Example: C:\\user\desktop\filename" << endl;
  63.         screenOutput << "Please enter the location and name of the file you wish to read from. Example: C:\\user\desktop\filename" << endl;
  64.         getline(cin, inputFileName);
  65.         cin.ignore;
  66.         fileOutput << inputFileName << endl;
  67.  
  68.         if (inputFile)
  69.         {
  70.             inputFile.open(inputFileName);
  71.  
  72.             while (inputFile >> word)
  73.             {
  74.                 fArray[i++] = word;
  75.                 fileOutput << word << endl;
  76.             }
  77.         }
  78.         else
  79.         {
  80.             cout << "There was an error in reading the file, please try again." << endl;
  81.             fileOutput << "There was an error in reading the file, please try again." << endl;
  82.         }
  83.     } while (!inputFile);
  84.  
  85.     textInput.close();
  86.     screenOutput.close();
  87.     fileOutput.close();
  88.    
  89. }
  90.  
  91. void ascendSort(string fArray[], int size)
  92. {
  93.     fileOutput.open(fileOutputName);
  94.  
  95.     int startScan, minIndex;
  96.     string minValue;
  97.     for (startScan = 0; startScan < (size - 1); startScan++)
  98.     {
  99.         minIndex = startScan;
  100.         minValue = fArray[startScan];
  101.         for (int index = startScan + 1; index < size; index++)
  102.         {
  103.             if (fArray[index] < minValue)
  104.             {
  105.                 if (string::length(fArray[index]) == 1)
  106.                 {
  107.  
  108.                 }
  109.                 minValue = fArray[index];
  110.                 minIndex = index;
  111.             }
  112.         }
  113.         fArray[minIndex] = fArray[startScan];
  114.         fArray[startScan] = minValue;
  115.     }
  116.  
  117.     for (int i = 0; i < (size - 1); i++)
  118.     {
  119.         fileOutput << fArray[i] << endl;
  120.     }
  121.  
  122.     fileOutput.close();
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement