Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- bool isVowel(char ch) {
- bool result = false;
- //Check if the character is a,e,i,o,u
- if(ch == 'a' || ch=='A' || ch=='e' || ch=='E' || ch=='i' || ch=='I' || ch=='o' || ch=='O' || ch=='u' || ch=='U') {
- result = true;
- }
- return result;
- }
- int countVowels(string word) {
- int count = 0;
- //Check each character of the word by calling isVowel function
- for(int j=0; j<word.length(); j++) {
- if(isVowel(word[j])) {
- count++;
- }
- }
- return count;
- }
- int countWords(string line) {
- int count = 0;
- //Check each character to see if there is a space
- for(int j=0; j<line.length(); j++) {
- if(line[j] == ' ') {
- count++;
- }
- }
- return count+1;
- }
- int main() {
- int vowelCount, wordCount;
- ifstream file("Lab17C.txt");
- string line;
- getline(file, line);
- vowelCount = countVowels(line);
- wordCount = countWords(line);
- cout <<"Number of vowels: "<< vowelCount << endl;
- cout <<"Number of words: "<< wordCount << endl;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement