Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 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.     textInput.open("textInput.txt");
  32.     screenOutput.open("screenOutput.txt");
  33.  
  34.     userInput(fArray);
  35.     ascendSort(fArray, FSIZE);
  36.  
  37.  
  38.  
  39.  
  40.     textInput.close();
  41.     screenOutput.close();
  42.     fileOutput.close();
  43.  
  44.     return 0;
  45. }
  46.  
  47. void userInput(string fArray[])
  48. {
  49.  
  50.     int i = 0;
  51.     string word;
  52.  
  53.     cout << "Please enter the location and name of where you would like to save the output file. Example: C:\\user\\desktop" << endl;
  54.     getline(cin, fileOutputName);
  55.     cin.ignore;
  56.    
  57.  
  58.     fileOutput.open(fileOutputName);
  59.     fileOutput << "Please enter the location and name of where you would like to save the output file. Example: C:\\user\\desktop" << endl;
  60.     fileOutput << fileOutputName << endl;
  61.     fileOutput << "Please enter the location and name of where you would like to save the output file. Example: C:\\user\\desktop" << endl;
  62.  
  63.     do
  64.     {
  65.         cout << "Please enter the location and name of the file you wish to read from. Example: C:\\user\desktop\filename" << endl;
  66.         fileOutput << "Please enter the location and name of the file you wish to read from. Example: C:\\user\desktop\filename" << endl;
  67.         getline(cin, inputFileName);
  68.         fileOutput << inputFileName << endl;
  69.  
  70.         if (inputFile)
  71.         {
  72.             inputFile.open(inputFileName);
  73.  
  74.             while (inputFile >> word)
  75.             {
  76.                 fArray[i++] = word;
  77.                 fileOutput << word << endl;
  78.             }
  79.         }
  80.         else
  81.         {
  82.             cout << "There was an error in reading the file, please try again." << endl;
  83.             fileOutput << "There was an error in reading the file, please try again." << endl;
  84.         }
  85.     } while (!inputFile);
  86.  
  87.    
  88. }
  89.  
  90. void ascendSort(string fArray[], int size)
  91. {
  92.     int startScan, minIndex;
  93.     string minValue;
  94.     for (startScan = 0; startScan < (size - 1); startScan++)
  95.     {
  96.         minIndex = startScan;
  97.         minValue = fArray[startScan];
  98.         for (int index = startScan + 1; index < size; index++)
  99.         {
  100.             if (fArray[index] < minValue)
  101.             {
  102.                 if (string::length(fArray[index]) == 1)
  103.                 {
  104.  
  105.                 }
  106.                 minValue = fArray[index];
  107.                 minIndex = index;
  108.             }
  109.         }
  110.         fArray[minIndex] = fArray[startScan];
  111.         fArray[startScan] = minValue;
  112.     }
  113.  
  114.     for (int i = 0; i < (size - 1); i++)
  115.     {
  116.         fileOutput << fArray[i] << endl;
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement