-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallvowels.cpp
More file actions
44 lines (38 loc) · 1.5 KB
/
Copy pathallvowels.cpp
File metadata and controls
44 lines (38 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* TODO: Write a function that takes a string parameter, and returns a boolean
* value indicating whether or not *all* vowels (a,e,i,o,u) are present
* somewhere in the string. For example, if the input is "hello world", the
* return value should be false, and on input "programming is super fun!" the
* return value should be true.
* NOTE: to simplify things, you can assume the input string is all lower case.
* */
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <string>
using std::string;
bool all_volwels(const string& s){ //pass by reference
bool a=false, e=false, i=false,o=false, u=false;
//Loop through each item in
for(char ch:s){ //“For every character in the string s, temporarily store it in a variable called ch, and do something with it.”
if (ch=='a') a=true;
else if (ch=='e') e=true;
else if (ch=='i') i=true;
else if (ch=='o') o=true;
else if (ch=='u') u=true;
}
return a && e && i && o && u; //“Return true only if all five of these are true.”
} // logical AND operator.
int main()
{
string input;// string variable named input to store whatever I type
cout << " enter a string: ";
getline(cin, input); //Fills that string with what I typed,Gets the full line of input (spaces too)
if (all_volwels(input)){
cout << "all vowels are present" << endl;
}else{
cout << "not all vowels are present" << endl;
}
return 0;
}
// vim:foldlevel=2