COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
1.cpp File Reference
#include <string>
#include <iostream>
Include dependency graph for 1.cpp:

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

◆ main()

int main ( void )

Definition at line 5 of file 1.cpp.

5 {
6 string input; // store the user input string
7 getline(cin, input); // get the whole line as requested
8 cout << input.length() << endl; // print the length of the string
9 // get the substring after the last space
10 string input_substr = input.substr(input.rfind(' ') + 1, input.length() - input.rfind(' ') - 1);
11 cout << input_substr << endl;
12 // vowel counting
13 int a = 0; int e = 0; int i = 0; int o = 0; int u = 0;
14 for (long long unsigned int index = 0; index<input_substr.length(); index++) {
15 switch (tolower(input_substr[index])) {
16 case 'a':
17 a++;
18 break;
19 case 'e':
20 e++;
21 break;
22 case 'i':
23 i++;
24 break;
25 case 'o':
26 o++;
27 break;
28 case 'u':
29 u++;
30 break;
31 }
32 }
33 cout << "a: " << a << endl;
34 cout << "e: " << e << endl;
35 cout << "i: " << i << endl;
36 cout << "o: " << o << endl;
37 cout << "u: " << u << endl;
38 return 0;
39}