Chapter 10 Flashcards

1
Q

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

A

cctype

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

cctype

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Assume c is a char variable. What value does c hold after each of the following statements
executes?
Statement Contents of c
c = toupper(‘a’); ___________
c = toupper(‘B’); ___________
c = tolower(‘D’); ___________
c = toupper(‘e’); __________

A

‘A’
‘B’
‘d’
‘E’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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);

A

5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

cstring

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

cstdlib

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. What header file must you include in a program using string class objects?
A

string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. How do you compare string class objects?
A

With the standard relational operators.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

isupper

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. The _________ function returns true if the character argument is a letter of the alphabet.
A

isalpha

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. The _________ function returns true if the character argument is a digit.
A

isdigit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. The _________ function returns true if the character argument is a whitespace character.
A

isspace

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. The _________ function returns the uppercase equivalent of its character argument.
A

toupper

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  1. The _________ function returns the lowercase equivalent of its character argument.
A

tolower

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  1. The _________ file must be included in a program that uses character testing functions.
A

cctype

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  1. The _________ function returns the length of a string.
A

strlen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q
  1. To _________ two strings means to append one string to the other.
A

concatenate

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q
  1. The _________ function concatenates two strings.
A

strcat

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q
  1. The _________ function copies one string to another.
20
Q
  1. The _________ function searches for a string inside of another one.
21
Q
  1. The _________ function compares two strings.
22
Q
  1. The _________ function copies, at most, n number of characters from one string to another.
23
Q
  1. The _________ function returns the value of a string converted to an integer.
24
Q
  1. The _________ function returns the value of a string converted to a long integer.
25
25. The _________ function returns the value of a string converted to a float.
atof
26
26. The _________ function converts an integer to a string.
itoa
27
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
if (toupper(choice) == 'Y')
28
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.
int numAlpha = 0; // Accumulator int i = 0; // Loop counter while (input[i] != '\0') { if (isalpha(input[i])) numalpha++; }
29
29. 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 .
if (strlen(name) <= 9) strcpy(str, name);
30
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 .
value = atof(str);
31
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.
int wCount(char *str) { int num = 0; while (*str != '\0') { if (*str == 'w') num++; } return num; }
32
32. 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.
if (str1 == str2) cout << "They are the same!";
33
Character testing functions, such as isupper , accept strings as arguments and test each character in the string
false
34
If toupper ’s argument is already uppercase, it is returned as is, with no changes.
true
35
If tolower ’s argument is already lowercase, it will be inadvertently converted to uppercase
false
36
The strlen function returns the size of the array containing a string.
false
37
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
38
C-string handling functions accept as arguments pointers to strings (arraynames or pointer variables), or literal strings
true
39
The strcat function checks to make sure the first string is large enough to hold both strings before performing the concatenation
false
40
The strcpy function will overwrite the contents of its first string argument.
true
41
The strcpy function performs no bounds checking on the first argument.
true
42
42. T F There is no difference between “847” and 847.
false
43
43. char str[] = "Stop"; if (isupper(str) == "STOP") exit(0);
The isupper function can only be used to test a character, not a string
44
44. char numeric[5]; int x = 123; numeric = atoi(x);
atoi converts a string to an integer, not an integer to a string
45
45. char string1[] = "Billy"; char string2[] = " Bob Jones"; strcat(string1, string2);
The compiler will not allocate enough space in string1 to accommodate both strings
46
46. char x = 'a', y = 'a'; if (strcmp(x, y) == 0) exit(0);
strcmp