Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************************
- Author: Trayvon Banks
- Course: cs 1336.003
- Date: 02/15/2018
- Assignment: 5
- Complier: Visual Studios 2017 Enterprise
- *****************************************************************************/
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int main()
- {//creating variables and establishing file manipulation
- ifstream inputFile;
- ofstream outputFile;
- string userInput;
- int countLength, countSpace, totalVowels, totalNumbers, totalOther;
- double alphaPercent, vowelPercent, numPercent, otherPercent;
- int totalLetters[26] = { 0 };
- char getChar;
- totalVowels = 0;
- totalNumbers = 0;
- totalOther = 0;
- countLength = 0;
- countSpace = 0;
- //Prompt user to enter file
- cout << "Enter the file name: " << endl;
- getline(cin, userInput);
- if (userInput == "message.txt")
- {
- inputFile.open("message.txt");
- if (inputFile.is_open())
- {
- while (getline(inputFile, userInput))
- {
- countLength += userInput.length();
- for ( int unsigned n = 0; n < userInput.length(); ++n)
- {
- //reads the letters in the file
- getChar = char(userInput[n]);
- if (userInput == " ")
- {
- countSpace++;
- }
- if (getChar == 'a' || getChar == 'e' || getChar == 'i' || getChar == 'o' || getChar == 'u' || getChar == 'A' || getChar == 'E' || getChar == 'I' || getChar == 'O' || getChar == 'U')
- {
- totalVowels++;
- }
- else if (getChar == '0' || getChar == '1' || getChar == '2' || getChar == '3' || getChar == '4' || getChar == '5' || getChar == '6' || getChar == '7' || getChar == '8' || getChar == '9')
- {
- totalNumbers++;
- }
- else
- {
- totalOther++;
- }
- }
- }
- alphaPercent = ((countLength - totalNumbers - totalOther) * 100) / countLength;
- vowelPercent = (totalVowels * 100) / countLength;
- numPercent = (totalNumbers * 100) / countLength;
- otherPercent = (totalOther * 100) / countLength;
- cout << "% of alphabets = " << alphaPercent << "%" << endl;
- cout << "% of vowels = " << vowelPercent << "%" << endl;
- cout << "% of numbers = " << numPercent << "%" << endl;
- cout << "% of the rest = " << otherPercent << "%" << endl;
- cout << "Total number of characters = " << countLength << endl;
- inputFile.close();
- }
- }
- else
- {
- cout << "Type in an available file." << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement