Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.65 KB | None | 0 0
  1. /***************************************************************************
  2. Author: Trayvon Banks
  3. Course: cs 1336.003
  4. Date: 02/15/2018
  5. Assignment:  5
  6. Complier: Visual Studios 2017 Enterprise
  7. *****************************************************************************/
  8. #include <iostream>
  9. #include <fstream>
  10. #include <string>
  11.  
  12. using namespace std;
  13.  
  14. int main()
  15. {//creating variables and establishing file manipulation
  16.     ifstream inputFile;
  17.     ofstream outputFile;
  18.     string userInput;
  19.     int countLength, countSpace, totalVowels, totalNumbers, totalOther;
  20.     double alphaPercent, vowelPercent, numPercent, otherPercent;
  21.     int totalLetters[26] = { 0 };
  22.     char getChar;
  23.  
  24.     totalVowels = 0;
  25.     totalNumbers = 0;
  26.     totalOther = 0;
  27.     countLength = 0;
  28.     countSpace = 0;
  29. //Prompt user to enter file
  30.     cout << "Enter the file name: " << endl;
  31.     getline(cin, userInput);
  32.  
  33.     if (userInput == "message.txt")
  34.     {
  35.         inputFile.open("message.txt");
  36.  
  37.         if (inputFile.is_open())
  38.         {
  39.             while (getline(inputFile, userInput))
  40.             {
  41.                 countLength += userInput.length();
  42.                
  43.  
  44.                 for ( int unsigned n = 0; n < userInput.length(); ++n)
  45.                     {
  46.                         //reads the letters in the file
  47.                         getChar = char(userInput[n]);
  48.                         if (userInput == " ")
  49.                         {
  50.                             countSpace++;
  51.                         }
  52.  
  53.                         if (getChar == 'a' || getChar == 'e' || getChar == 'i' || getChar == 'o' || getChar == 'u' || getChar == 'A' || getChar == 'E' || getChar == 'I' || getChar == 'O' || getChar == 'U')
  54.                         {
  55.                             totalVowels++;
  56.                         }
  57.                         else if (getChar == '0' || getChar == '1' || getChar == '2' || getChar == '3' || getChar == '4' || getChar == '5' || getChar == '6' || getChar == '7' || getChar == '8' || getChar == '9')
  58.                         {
  59.                             totalNumbers++;
  60.                         }
  61.                         else
  62.                         {
  63.                             totalOther++;
  64.                         }
  65.                     }
  66.                
  67.             }
  68.             alphaPercent = ((countLength - totalNumbers - totalOther) * 100) / countLength;
  69.             vowelPercent = (totalVowels * 100) / countLength;
  70.             numPercent = (totalNumbers * 100) / countLength;
  71.             otherPercent = (totalOther * 100) / countLength;
  72.  
  73.             cout << "% of alphabets = " << alphaPercent << "%" << endl;
  74.             cout << "% of vowels = " << vowelPercent << "%" << endl;
  75.             cout << "% of numbers = " << numPercent << "%" << endl;
  76.             cout << "% of the rest = " << otherPercent << "%" << endl;
  77.             cout << "Total number of characters = " << countLength << endl;
  78.  
  79.             inputFile.close();
  80.  
  81.         }
  82.     }
  83.     else
  84.     {
  85.         cout << "Type in an available file." << endl;
  86.     }
  87.  
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement