Hello, I am very new to programming and I could use a little help! Our professor asked us to write a program taht reads a string and outputs the number of times lowercase vowels appears in it! It has to contain 5 functions:
Function1: Function with one of its parameters a string that return the of times each lowercase vowel appears in it
Function2: Function that determines if a character is lowercase letter (i.e. between 97 and 122 in ASCII table)
Function3: Function that determines if a character is a vowel
Function4: Function that reads a string from file
Function5: Function that prints out the result
My question is I don't know how to read each letter of the string and pass it through both functions to see if it is lowercase and a vowel. I've looked it up alot and no results. It is starting to frustrate me as i have been doing this for about 3 hours now! Please help.
Here is the code I currently have:
ifstream inFile;
string stringInFile;
int lowercaseCount;
int vowelCount;
int totalCount;
int main()
{
char array[50];
for(int i = 0; i < stringInFile.length(); i++)
{
if(isAVowel(array[i]) = true && isLowercase(array[i]) = true)
{
}
}
system("pause");
return 0;
}
void fileOpen(string stringInFile)
{
string fileName;
while(fileName != "stringWithVowels.txt")
{
cout << "To open the file please enter the name of the file." << endl;
cin >> fileName;
}
Nothing to it really. The only hard part might be figuring out a way to make all the functions work together to produce the desired result in the end. I will show you how by implementing the lowercaseVowel method (with a different return type) which is the main driving force of the entire process.
1 2 3 4 5 6 7 8 9 10
int lowerCaseVowel(std::string str) {
int length = str.length();
int counter = 0;
for (int v = 0; v < length; v++) {
if (isLowercase(str[v]) && isAVowel(str[v])) {
counter++;
}
}
return counter;
}
First off, I would like to say thank you soo much for helping me out! It makes alot more sense now that you say that haha! :) OK so here is what I have for the code so far, and I am not sure what is wrong with it! I added the last function and called the counter to it... i really don't fully understand what I am doing! Anyway I am getting the Error: error LNK2019: unresolved external symbol "int __cdecl lowercaseVowel(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?lowercaseVowel@@YAHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main.
int lowercaseVowel(string);
bool isLowercase(char);
bool isAVowel(char);
void fileOpen();
void printResult(int);
ifstream inFile;
int lowercaseCount;
int vowelCount;
int totalCount;
int counter;
int main()
{
string stringInFile;
int lowercaseVowels = 0;
int length = 0;
length = stringInFile.length();
fileOpen();
lowercaseVowel(stringInFile);
printResult(counter);
system("pause");
return 0;
}
void fileOpen()
{
string fileName;
while(fileName != "stringWithVowels.txt")
{
cout << "To open the file please enter the name of the file." << endl;
cin >> fileName;
}
int lowerCaseVowel(string str)
{
int length = str.length();
int counter = 0;
for (int v = 0; v < length; v++)
{
if(isLowercase(str[v]) && isAVowel(str[v]))
{
counter++;
}
}
return counter;
}
void printResult(int counter)
{
cout << "There are " << counter << " lowercase vowels in the string." << endl;
}
if there is anything I am doing wrong, just tell me and ill fix it right away... it would be helpful if you explained why it was wrong so I can learn from my mistakes! :) Thanks again