String Processing Project: Find out how many times each English vowel appears in
ID: 3752174 • Letter: S
Question
String Processing Project: Find out how many times each English vowel appears in a file containing English text. Also output the English text with each vowel capitalized, so the vowels stand out. There are 5 vowels in English: 'A' or'a,'E' or'e','1, or ‘i','0' or ‘o','U' or'u'. You need 5 counters, one for each vowel. Follow Program Guidelines. Use string processing functions. Input: The input file contains an unknown number of lines of English text. Processing: The function main( ) will declare filestream and other variables, open files, and call functions to do the processing. Required functions are: 1. 2. 3. A Boolean function is Vowel returns true if a character is a vowel; it returns false otherwise. A function processes the input file contents line by line, counting vowels and capitalizing them. A function outputs the counter values for each vowel, with appropriate labels. Output: The output file will contain the input English text with each vowel capitalized, followed by the number of times each vowel appeared, with appropriate labels.Explanation / Answer
Please find the code below:::
#include<iostream>
#include<stdio.h>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
bool isVowel(char c){
if(c>='a' && c<='z'){c = c-32;}
if(c=='A' ||c=='E' ||c=='I'||c=='O'||c=='U' ){
return true;
}else{
return false;
}
}
void outputDetails(int *count,ofstream& writer){
writer<<"The number of occurrence of A is "<<count[0]<<endl;
writer<<"The number of occurrence of E is "<<count[1]<<endl;
writer<<"The number of occurrence of I is "<<count[2]<<endl;
writer<<"The number of occurrence of O is "<<count[3]<<endl;
writer<<"The number of occurrence of U is "<<count[4]<<endl;
}
void readfile(ifstream & inFile){
//get character
char singleCharacter;
//loop unitl character is reading
int count[5];
for(int i=0;i<5;i++){
count[i] = 0;
}
ofstream writer("output.txt"); //printing data to out file
while (inFile.get(singleCharacter))
{
if(isVowel(singleCharacter)){
if(singleCharacter>='a' && singleCharacter<='z'){singleCharacter-=32;}
if(singleCharacter=='A'){
count[0]++;
}else if(singleCharacter=='E'){
count[1]++;
}else if(singleCharacter=='I'){
count[2]++;
}else if(singleCharacter=='O'){
count[3]++;
}else if(singleCharacter=='U'){
count[4]++;
}
}
writer<<singleCharacter;
}
writer<<endl;
outputDetails(count,writer);
writer.close();
}
int main()
{
ifstream inFile;
char filename[100];
//read file name
cout<<"Enter name of the file : ";
cin>>filename;
//open the file
inFile.open (filename);
//writer to write the data to output.txt
//if file open
if (inFile.is_open())
{
readfile(inFile);
}else
{
cout << "Sorry, we could not find the equation file." << endl;
}
inFile.close();
return 0;
}
output:
input.txt file is
ABCDEFGHIJKLM NOPQRSTUVWXYZ
abcdefghijklm nopqrstuvwxyz
Hello how are you!!!
output.txt is
ABCDEFGHIJKLM NOPQRSTUVWXYZ
AbcdEfghIjklm nOpqrstUvwxyz
HEllO hOw ArE yOU!!!
The number of occurrence of A is 3
The number of occurrence of E is 4
The number of occurrence of I is 2
The number of occurrence of O is 5
The number of occurrence of U is 3