Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Dec 7th, 2018 56 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. //
  2. //  main.cpp
  3. //  Project4MCS360
  4. //
  5. //  Created by Peter Apostle on 12/5/18.
  6. //  Copyright © 2018 MCS360. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <stack>
  11. #include <string>
  12. #include <fstream>
  13.  
  14. using namespace std;
  15.  
  16. void convertFile(){
  17.    
  18.     ifstream myFile;
  19.     ofstream outputFile;
  20.     myFile.open("project4text.txt");
  21.    
  22.    
  23.     stack<string> wholeFile;
  24.     stack<char> splitWords;
  25.     stack<char> reversedSplitWords;
  26.     string wordInput;
  27.     string strPop;
  28.    
  29.     while (myFile >> wordInput){
  30.         wholeFile.push(wordInput);
  31.     }
  32.     myFile.close();
  33.    
  34.  
  35.     while (!wholeFile.empty()){
  36.         strPop = wholeFile.top();
  37.         cout << strPop << endl;
  38.         wholeFile.pop();
  39.         for (int i = 0; i < strPop.length(); i++){
  40.             char temp;
  41.             temp = strPop[i];
  42.             splitWords.push(temp);
  43.         }
  44.         splitWords.push(' ');
  45.     }
  46.     while (!splitWords.empty()){
  47.         char temp;
  48.         temp = splitWords.top();
  49.         reversedSplitWords.push(temp);
  50.     }
  51.     outputFile.open("project4text2.txt");
  52.     while (!reversedSplitWords.empty()){
  53.         cout << reversedSplitWords.top();
  54.         outputFile << reversedSplitWords.top();
  55.         reversedSplitWords.pop();
  56.     }
  57. }
  58.  
  59. int main() {
  60.    
  61.     convertFile();
  62.    
  63.    
  64.     return 0;
  65. }
  66.  
  67. /*
  68.  Program trace:
  69.  
  70.  Read file in one function, each word pushed to a stack
  71.  i.e. "AB CD EF" -> stack has [EF | CD | AB]
  72.  Pop from first stack and set strPop = popped value (EF)
  73.  call strPop[i] for loop to push to second stack [E | F]
  74.  pop from second stack to third stack to reverse letters [F | E]
  75.  pop from third stack to write to file, when third stack is empty add space character
  76.  
  77.  
  78.  MAKE SURE TO INCLUDE A SPACE AT THE END OF EACH WORD.
  79.  Repeat until all words written to new file.
  80.  
  81.  */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top