Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Chapter 10 Starting out with C++ Characters C-Strings


 

Download  file with the answers

Not a member!
Create a FREE account here to get access and download this file with answers


 

Chapter Ten

MULTIPLE CHOICE

1. To test whether a character is a numeric digit character, use this function.
a. isnumber
b. notAlpha
c. isnumeric
d. isdigit
e. None of these

2. To test whether a character is a printable character, use this function.
a. isprint
b. isprintable
c. isprintok
d. isoktoprint
e. None of these

3. This is the escape sequence representing the null terminator.
a. \n
b. \t
c. \0
d. /NULL
e. None of these

4. The null terminator stands for this ASCII code.
a. 57
b. 100
c. 1000
d. 0
e. None of these

5. This function accepts a pointer to a C-string as an argument, and it returns the length of the C-string (not including the null terminator).
a. numchar
b. strlength
c. strlen
d. countstring
e. None of these

6. The strcpy function’s arguments are:
a. two C-strings
b. two addresses
c. three pointers
d. one array and one pointer
e. None of these

7. A library function that can find one C- string inside another is:
a. strcmp
b. strstr
c. strfind
d. strsearch
e. None of these

8. This function accepts a C-string as an argument and converts the string to a long integer.
a. atol
b. strlong
c. strtolong
d. stringlong
e. None of these

9. This function converts a C-string to an integer and returns the integer value.
a. atoint
b. strtoint
c. strint
d. atoi
e. None of these

10. Which statement converts the string “10” to the integer value 10?
a. itoa(“ten”)
b. atoi(“ten”)
c. atoi(“10”)
d. itoa(10)
e. None of these

11. This function will return true if its argument is a printable character other than a digit, letter, or space.
a. isprint
b. ispunct
c. ischar
d. isnotdls
e. None of these

12. The C-string company[12] can hold
a. Twelve characters
b. Thirteen characters
c. Eleven characters and the null terminator
d. Twelve characters and the null terminator
e. None of the above

13. Look at the following statement.

if (!isdigit(var1))

The expression being tested by this statement will evaluate to true if var1 is:

a. an alphabetic character
b. 9
c. a symbol such as $ or &
d. both a and c
e. None of these

14. “Whitespace” encompasses which of the following?
a. tab
b. newline
c. space
d. All of these
e. None of these

15. A practical application of this function is to allow a user to enter a response of ‘y’ or ‘Y’ to a prompt.
a. tolower
b. toupper
c. a or b
d. ignorecase
e. None of these

16. This function accepts a C-string containing a number as its argument and returns the integer equivalent.
a. strToInt
b. itoa
c. atoi
d. int_from
e. None of these

17. To determine whether a character entered is a letter of the alphabet, use this function.
a. isdigit
b. fromkeyboard
c. alphaok
d. isalpha
e. None of these

18. To determine whether a character is whitespace, use this function.
a. iswhite
b. isspace
c. iswhitespace
d. isblank
e. None of these

19. To change a character argument from lower to upper case, use this function.
a. isupper
b. toupper
c. tolarge
d. fromlower
e. None of these

20. What is the output of the following statement?

cout << tolower(toupper(‘Z’)) << endl;

a. upper case Z
b. lower case z
c. a lower case z followed by an upper case Z
d. a compiler error
e. None of these

21. In C++, a C-string is a sequence of characters stored in consecutive memory, terminated by a
a. period
b. space
c. null character
d. semicolon
e. None of these

22. To use the strlen function in a program, you must also write #include ______________.
a.
b.
c.
d.
e. None of these

23. This function concatenates the contents of one C-string with another C-string.
a. strcopy
b. strappend
c. strcat
d. stradd
e. None of these

24. This function accepts pointers to two C-strings and an integer argument, which indicates how many characters to copy from the second C-string to the first.
a. strcpy
b. strncpy
c. copystring
d. strintcpy
e. None of these

25. After the following statement executes, what value is stored in the variable num?

num = atoi(“1000”);

a. 1000
b. 999 (1000 minus 1 for the null terminator)
c. “1000”
d. “thousand”
e. None of these

26. To change a lower case character to an upper case character, use this function.
a. atoi
b. itoa
c. ltou
d. toupper
e. None of these

27. This library function reverses the order of a C-string.
a. reverstr
b. strrev
c. reversit
d. backward
e. None of these

28. To define a C-string that will store students’ last names of up to 25 characters in length, which is an appropriate statement?
a. char lastName[25];
b. string lastName[25];
c. char lastName[26];
d. string lastName[24];
e. None of these

29. Which of the following lines of code defines an array of C-strings that will hold 49 characters and the null terminator?
a. char [49];
b. char str[50];
c. char[50] str;
d. character str[50];
e. None of the above

30. The statement

char var1 = tolower(‘A’);

will result in:

a. var1 storing the character value ‘A’ .
b. var1 storing the ASCII value for lower case ‘a’.
c. A is output to the monitor.
d. a is output to the monitor.
e. None of these

TRUE/FALSE

1. True/False: A test using the isupper function will return false if the argument is an uppercase character.

2. True/False: The isdigit function will return a true if its argument is a digit between 0 and 9.

3. True/False: When using the strcat function, you must be careful not to overwrite the bounds of an array.

4. True/False: The C++ compiler performs strict array bounds checking when it encounters an array of characters.

5. True/False: The itoa function is similar to atoi, but it works in reverse.

6. True/False: By being able to pass arrays as arguments, you can write your own functions for processing C-strings.

7. True/False: The strlen function returns a C-string’s length and adds one for \0.

8. True/False: The C++ library provides functions for converting a string representation of a number to a numeric data type, and vice-versa.

9. True/False: The ftoa function converts a floating-point value to an ASCII value.

10. True/False: If a C-string that cannot be converted to a numeric value is passed to the atoi function, the function’s behavior is undefined by C++.

11. True/False: If an uppercase character is passed as an argument to toupper, the result will be an uppercase character.

12. True/False: Although C++ provides ample library functions to handle numeric values, we must write all of our own functions to manipulate character values.

13. True/False: You may use the <, >, <=, >=, ==, and != relational operators to compare string objects.

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!