-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathExercise 15.1
75 lines (60 loc) · 3.49 KB
/
Exercise 15.1
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
1. (Program) a. The following function can be used to select and display all vowels in a userentered
string:
void vowels(char strng[])
{
int i = 0;
char c;
while ((c = strng[i++]) != '\0')
switch(c)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
cout << c;
} // end of switch
cout << endl;
return;
}
Note that the switch statement in vowels() uses the fact that selected cases “drop through”
in the absence of break statements. Therefore, all selected cases result in a cout object call.
Include vowels() in a working program that accepts a user-entered string and then displays
all vowels in the string. In response to the input How much is the little worth worth?,
your program should display ouieieoo.
b. Modify vowels() to count and display the total number of vowels in the string passed to it.
2. (Modify) Modify the vowels() function in Exercise 1a to count and display the numbers of
each vowel in the string.
3. (Program) a. Write a C++ function to count the total number of characters, including blanks,
in a string. Don’t include the end-of-string marker in the count.
b. Include the function written for Exercise 3a in a complete working program.
4. (Program) Write a program that accepts a string of characters from the keyboard and displays
the hexadecimal equivalent of each character.
5. (Program) Write a C++ program that accepts a string of characters from the keyboard and
displays the string with one word per line.
6. (Program) Write a function that reverses the characters in a string. (Hint: It can be considered
a string copy, starting from the back end of the first string.)
7. (Program) Write a function called delChar() that can be used to delete characters from a
string. The function should take three arguments: the string name, the number of characters to
delete, and the starting position in the string where characters should be deleted. For example,
the call delChar(strng,13,5), when applied to the string all enthusiastic people,
should result in the string all people.
8. (Program) Write a function called addChar() to insert one string of characters into another
string. The function should take three arguments: the string to be inserted, the original string,
and the position in the original string where the insertion should begin. For example, the call
addChar(“for all”,message,6) should insert the characters for all in message, starting
at message[5].
9. (Program) a. Write a C++ function named toUpper() that converts lowercase letters to
uppercase letters. The expression c - 'a' + 'A' can be used to make the conversion for any
lowercase character stored in c.
b. Add a data input check to the function written in Exercise 9a to verify that a valid lowercase
letter is passed to the function. A character in ASCII is lowercase if it’s greater than or
equal to a and less than or equal to z. If the character isn’t a valid lowercase letter, have
the toUpper() function return the passed character unaltered.
c. Write a C++ program that accepts a string from the keyboard and converts all lowercase
letters in the string to uppercase letters.
10. (Program) Write a C++ program that accepts a string from the keyboard and converts all
uppercase letters in the string to lowercase letters.
11. (Program) Write a C++ program that counts the number of words in a string. A word is
encountered whenever there’s a transition from a blank space to a nonblank character. Assume
the string contains only words separated by blank spaces.