• Home
  • Textbooks
  • Starting out with C++: From Control Structures through Objects
  • Characters, C-Strings, and More about the string Class

Starting out with C++: From Control Structures through Objects

Tony Gaddis

Chapter 10

Characters, C-Strings, and More about the string Class - all with Video Answers

Educators


Chapter Questions

Problem 1

What header file must you include in a program using character-testing functions such as isalpha and isdigit?

Check back soon!

Problem 2

What header file must you include in a program using the character conversion functions toupper and tolower?

Check back soon!

Problem 3

Assume c is a char variable. What value does c hold after each of the following state-
ments executes?

$$
\begin{array}{lll} \text { Statement} & \text { Contents of c } \\
\text { c = toupper('a'); } & \_\_\_\_\_\_ \\
\text { c = toupper('B'); } & \_\_\_\_\_\_ \\
\text { c = tolower('D'); } & \_\_\_\_\_\_ \\
\text { c = toupper('e'); } & \_\_\_\_\_\_
\end{array}
$$

Check back soon!

Problem 4

Look at the following code. What value will be stored in s after the code executes?
char name[10];
int s;
strcpy(name, "Jimmy");
s = strlen(name);

Check back soon!

Problem 5

What header file must you include in a program using string functions such as strlen and strcpy?

Check back soon!

Problem 6

What header file must you include in a program using string/numeric conversion functions such as atoi and atof?

Check back soon!

Problem 7

What header file must you include in a program using string class objects?

Check back soon!

Problem 8

How do you compare string class objects?

Check back soon!

Problem 9

The _________ function returns true if the character argument is uppercase.

Check back soon!

Problem 10

The _________ function returns true if the character argument is a letter of the alphabet.

Check back soon!

Problem 11

The _________ function returns true if the character argument is a digit.

Check back soon!

Problem 12

The _________ function returns true if the character argument is a whitespace character.

Check back soon!

Problem 13

The _________ function returns the uppercase equivalent of its character argument.

Check back soon!

Problem 14

The _________ function returns the lowercase equivalent of its character argument.

Check back soon!

Problem 15

The _________ file must be included in a program that uses character-testing functions.

Check back soon!

Problem 16

The _________ function returns the length of a string.

Check back soon!

Problem 17

To _________ two strings means to append one string to the other.

Check back soon!

Problem 18

The _________ function concatenates two strings.

Check back soon!

Problem 19

The _________ function copies one string to another.

Check back soon!

Problem 20

The _________ function searches for a string inside of another one.

Check back soon!

Problem 21

The _________ function compares two strings.

Check back soon!

Problem 22

The _________ function copies, at most, n number of characters from one string to another.

Check back soon!

Problem 23

The _________ function returns the value of a string converted to an integer.

Check back soon!

Problem 24

The _________ function returns the value of a string converted to a long integer.

Check back soon!

Problem 25

The _________ function returns the value of a string converted to a float.

Check back soon!

Problem 26

The _________ function converts an integer to a string.

Check back soon!

Problem 27

The following if statement determines whether choice is equal to 'Y' or 'y':
if (choice == 'Y' || choice == 'y')
Simplify this statement by using either the toupper or tolower function.

Check back soon!
03:31

Problem 28

Assume input is a char array holding a C-string. Write code that counts the number of elements in the array that contain an alphabetic character.

SS
Sarvesh Somasundaram
Numerade Educator

Problem 29

Look at the following array definition:
char str[10];
Assume name is also a char array, and it holds a C-string. Write code that copies the contents of name to str if the C-string in name is not too big to fit in str.

Check back soon!

Problem 30

Look at the following statements:
char str[] = "237.89";
double value;
Write a statement that converts the string in str to a double and stores the result in value.

Check back soon!

Problem 31

Write a function that accepts a pointer to a C-string as its argument. The function should count the number of times the character ‘w’ occurs in the argument and return that number.

Check back soon!

Problem 32

Assume str1 and str2 are string class objects. Write code that displays “They are the same!” if the two objects contain the same string.

Check back soon!

Problem 33

True or False
T F Character-testing functions, such as isupper, accept strings as arguments and test each character in the string.

Check back soon!

Problem 34

True or False
T F If toupper’s argument is already uppercase, it is returned as is, with no changes.

Check back soon!

Problem 35

True or False
T F If tolower’s argument is already lowercase, it will be inadvertently converted to uppercase.

Check back soon!

Problem 36

True or False
T F The strlen function returns the size of the array containing a string.

Check back soon!

Problem 37

True or False
T F If the starting address of a C-string is passed into a pointer parameter, it can be assumed that all the characters, from that address up to the byte that holds the null terminator, are part of the string.

Check back soon!

Problem 38

True or False
T F C-string-handling functions accept as arguments pointers to strings (array names or pointer variables), or literal strings.

Check back soon!

Problem 39

True or False
T F The strcat function checks to make sure the first string is large enough to hold both strings before performing the concatenation.

Check back soon!

Problem 40

True or False
T F The strcpy function will overwrite the contents of its first string argument.

Check back soon!

Problem 41

True or False
T F The strcpy function performs no bounds checking on the first argument.

Check back soon!

Problem 42

True or False
T F There is no difference between “847” and 847.

Check back soon!
02:09

Problem 43

Each of the following programs or program segments has errors. Find as many as you can.

char str[] = "Stop";
if (isupper(str) == "STOP")
exit(0);

James Kiss
James Kiss
Numerade Educator
02:09

Problem 44

Each of the following programs or program segments has errors. Find as many as you can.

char numeric[5];
int x = 123;
numeric = atoi(x);

James Kiss
James Kiss
Numerade Educator

Problem 45

Each of the following programs or program segments has errors. Find as many as you can.

char string1[] = "Billy";
char string2[] = " Bob Jones";
strcat(string1, string2);

Check back soon!
02:09

Problem 46

Each of the following programs or program segments has errors. Find as many as you can.

char x = 'a', y = 'a';
if (strcmp(x, y) == 0)
exit(0);

James Kiss
James Kiss
Numerade Educator