The number of vowels
Read one sentence (it may contain spaces) and print how many vowels it has (a, e, i, o, u – lower and upper case).
Example
Input
Programming is funOutput
5A test on working with text in C++ (string): reading a word and a whole line, going through the characters, upper and lower case letters, counting, comparing and changing characters. This page is new – the tasks are in two groups, with solutions.
cin >> s (one word) and getline(cin, s) (a whole line)s.length() and accessing a character s[i]<cctype>: isupper, islower, isdigit, tolower, toupperc - 'a' is the position of the letter, '0' + 5 is the character 5+) and searching (find)| Points | 0–11 | 12–16 | 17–21 | 22–26 | 27–30 |
|---|---|---|---|---|---|
| Grade | 1 | 2 | 3 | 4 | 5 |
The scale is a suggestion for self-assessment; the teacher can adapt it. (In Serbian schools grades go from 1 to 5, where 5 is the best.)
Read one sentence (it may contain spaces) and print how many vowels it has (a, e, i, o, u – lower and upper case).
Programming is fun5Read a sentence and check whether it is a palindrome when spaces and the difference between upper and lower case letters are ignored. Print YES or NO.
Never odd or evenYESWorld of programmingNOThe Caesar cipher replaces every letter with the letter that is k places further in the alphabet (after z comes a again). Read k (0 ≤ k ≤ 25) and a word of lower case letters of the English alphabet, and print the encrypted word.
3
zebracheudRead a sentence in which the words are separated by one or more spaces (there may also be spaces at the beginning and at the end) and print the number of words.
Today is a nice day 5Read a sentence and print its longest word. If there are several words of the same, greatest length, print the first one.
The world of programming is interestingprogramming("programming" and "interesting" both have 11 letters, so the first one is printed.)
A password is strong if it has at least 8 characters, at least one upper case letter, at least one lower case letter and at least one digit. Read the password (without spaces) and print STRONG, or WEAK and below it everything that is missing.
Password123STRONGsecretWEAK
- too short
- no upper case letter
- no digitcin >> n the end of the line remains; if you then read with getline, first call cin.ignore().s[i] == 'a', and strings with double quotes: s == "end".for (char &c : s) loop, you need the & sign.1. What does cin >> s read if the user enters Good day?
2. What is 'd' - 'a'?
3. What does s.length() return for s = "cat 1"?