Font size
WorksheetsChapter 10: Characters, C-Strings, and string Class
Total questions: 51
Worksheet time: 1hrs 12mins
What header file must you include in a program using character testing functions such as isalpha and isdigit?
#include <cstring>
#include <string>
#include <cctype>
#exclude <ccbyte>
What header file must you include in a program using the character conversion functions toupper and tolower?
#exclude <cctype>
#include <cctype>
#input <cctype>
#output <cctype>
Assume c is a char variable. What value does c hold after each of the following statements executes?
c = toupper('a'); (a)
c = toupper('B'); (b)
c = tolower('D'); (c)
c = toupper('e'); (d)
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);
What header file must you include in a program using string functions such as strlen and strcpy ? (a)
What header file must you include in a program using string/numeric conversion functions such as atoi and atof ?
#include <string>
#include <cstring>
#input <cstring>
#input <string>
What header file must you include in a program using string class objects?
#include <cctype>
#include <cstring>
#exclude <string>
#include <string>
How do you compare string class objects?
mystring.compare(str);
strcmp(str1, str2);
strstr(str);
mystring.append(str);
The (a) function returns true if the character argument is uppercase.
The (a) function returns true if the character argument is a letter of the alphabet.
The (a) function returns true if the character argument is a digit.
The (a) function returns true if the character argument is a whitespace character.
The (a) function returns the uppercase equivalent of its character argument.
The (a) function returns the lowercase equivalent of its character argument.
The (a) file must be included in a program that uses character testing functions.
The (a) function returns the length of a string.
To (a) two strings means to append one string to the other
The (a) function concatenates two strings.
The (a) function copies one string to another
The (a) function searches for a string inside of another one.
The (a) function compares two strings.
The (a) function copies, at most, n number of characters from one string to another
The (a) function returns the value of a string converted to an integer.
The (a) function returns the value of a string converted to a long integer.
The (a) function returns the value of a string converted to a float.
The (a) function converts an integer to a string.
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.
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.
Look at the following array definition.
char str[10];
Assume that 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.
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.
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.
Assume that str1 and str2 are string class objects. Write code that displays “They are
the same!” if the two objects contain the same string.
Character testing functions, such as isupper , accept strings as arguments and test each character in the string.
True
False
If toupper ’s argument is already uppercase, it is returned as is, with no changes.
True
False
If tolower ’s argument is already lowercase, it will be inadvertently converted to uppercase.
True
False
The strlen function returns the size of the array containing a string.
True
False
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.
True
False
C-string handling functions accept as arguments pointers to strings (array names or pointer variables), or literal strings.
True
False
The strcat function checks to make sure the first string is large enough to hold both strings before performing the concatenation.
True
False
The strcpy function will overwrite the contents of its first string argument.
True
False
The strcpy function performs no bounds checking on the first argument.
True
False
There is no difference between “847” and 847.
True
False
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);
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);
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);
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);
Organize these options into the right categories
isupper
isalpha
isspace
tolower
strlen
strstr
strcat
strcpy
mystring.at(x);
mystring.size();
mystring.append(str);
mystring.assign(str);
Organize these options into the right categories
islower
isalnum
isdigit
ispunct
strncpy
strncat
strlen
strstr
mystring.begin();
mystring.end();
mystring.front();
mystring.back();
Which of the following is a character functions: (a) (b)
Which of the following is a cstring functions: (a) (b)
Which of the following is a string functions: (a) (b)
