CS 202 exam #1

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

TRUE/ FALSE: The structure pointer operator is used to dereference a pointer to a structure, not a pointer that is a member of a structure.

T

TRUE/ FALSE: When using the strcat function you must be careful not to overwrite the bounds of an array.

T

TRUE/ FALSE: When you use a strongly typed enumerator in C++11 you must prefix the enumerator with the name of the enum followed by the :: operator.

T

TRUE/ FALSE: You may use the <, >, <=, >=, ==, and != relational operators to compare string objects.

T

TRUE/FALSE: It is possible for a structure variable to be a member of another structure variable.

T

TRUE/FALSE: The ios::out flag causes the file's existing contents to be deleted if the file already exists.

T

TURE/ FALSE: Any mathematical operation that can be performed on regular C++ variables can be performed on structure members.

T

True/ False: A pointer can be used as a function argument, giving the function access to the original argument.

T

True/ False: An array name is a pointer constant because the address stored in it cannot be changed at runtime.

T

True/ False: Assuming myValues is an array of int values and index is an int variable, both of the following statements do the same thing. 1. cout << myValues[index] << endl; 2. cout << *(myValues + index) << endl;

T

True/ False: C++ does not perform array bounds checking, making it possible for you to assign a pointer the address of an element out of the boundaries of an array.

T

True/ False: In C++11 you can use smart pointers to dynamically allocate memory and not worry about deleting the memory when you are finished using it.

T

True/ False: In C++11, the nullptr keyword was introduced to represent the address 0.

T

True/ False: It is legal to subtract a pointer variable from another pointer variable.

T

True/ False: The unique_ptr is the sole owner of a piece of dynamically allocated memory.

T

True/ False: To use any of the smart pointers in C++11 you must use the following directive in the header file: #include <memory>

T

True/False: A struct can contain members with varying data types.

T

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

T

True/False: File output may be formatted the same way as console screen output.

T

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++.

T

True/False: If a file already exists, you can open it with the flags ios::in | ios::out to preserve its contents.

T

True/False: If a function is legally prototyped to return an integer value, it can return a structure member that is an integer data type.

T

True/False: In C++ 11, if you want to retrieve a strongly typed enumerator's underlying integer value, you must use a cast operator.

T

True/False: It is possible for a structure to contain as a member a pointer to its own structure type.

T

True/False: Structure variables may be passed as arguments to functions.

T

True/False: The expression *s->p; indicates that s is a structure pointer and p, which is also a pointer, is a member of the structure pointed to by s.

T

True/False: The expression s->m; indicates that s is a structure pointer and m is a structure member.

T

True/False: The ios::hardfail bit is set when an unrecoverable error occurs.

T

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

T

True/False: When a programmer creates an abstract data type, he or she can decide what values are acceptable for the data type, as well as what operations may be performed on the data type.

T

True/False: When passing a file stream object to a function, you should always pass it by reference.

T

True/False: You cannot directly assign an integer value to an enum variable.

T

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

T

True/False: To use any of the smart pointers in C++ 11, you must #include the memory header file with the following directive: #include <memory>

True

TRUE/ FALSE: The itoa function is similar to atoi but it works in reverse.

T

TRUE/ FALSE: The string class's front and back member functions were introduced in C++11.

T

True/False: In C++ 11, the nullptr key word was introduced to represent the address 0.

True

True/False: It is legal to subtract a pointer variable from another pointer variable.

True

This function accepts a C-string as an argument and converts the string to a long integer. A. strtolong B. atol C. stringlong D. strlong E. None of these

B

Passing a structure as a constant reference parameter to a function ________. A. guarantees not to result in changes to the structure's members B. will always change the structure's members C. can potentially result in changes to the structure's members D. All of these E. None of these

A

Select all that apply. Which of the following can be used as pointers? a. array names b. numeric constants c. keywords d. None of these

A

A function may return a pointer but the programmer must ensure that the pointer a. still points to a valid object after the function ends b. has not been assigned an address c. was received as a parameter by the function d. has not previously been returned by another function e. None of these

A

A structure ________ contain members of the same data type. A. can B. shouldn't C. cannot D. None of these

A

A structure pointer contains a. the address of a structure variable b. the dereferenced address of a structure tag c. the name and address of the structure tag d. the address of a structure tag e. None of these

A

Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr; a. the value stored in the variable whose address is contained in ptr b. the string "*ptr" c. the address of the variable whose address is stored in ptr d. the address of the variable stored in ptr e. None of these

A

Given the following structure decaration, idNum is struct Employee { string name; int idNum; }; a. a member b. an array c. a tag d. None of these

A

If Circle is a structure tag, the statement: Circle doSomething(Circle c2)can be the header line for a function that ________. A. takes a Circle structure as a parameter, does something, and returns a Circle structure B. takes two Circle parameters and does something C. operates on a constant reference to a Circle structure D. determines and returns the area of a circle

A

If a is a structure variable and p, a pointer, is a member of the structure, what will the following statement do? cout << *a.p; a. output the dereferenced value pointed to by p b. result in a compiler error c. output the address stored in p d. output the value stored in a e. none of these

A

If you are using an older computer that does not support the C++11 standard, you should initialize pointers with a. the integer 0 or the value NULL b. the null terminator '\0' c. a nonzero value d. Any of these e. None of these

A

In C++11, the __________ keyword was introduced to represent address 0. a. nullptr b. NULL c. weak_ptr d. shared_ptr e. None of these

A

Look at the following statement. bookList[2].publisher[3] = 't';This statement ________. A will store the character 't' in the fourth element of the publishermember of booklist[2] B. will ultimately result in a runtime error C. is illegal in C++ D. will change the publisher's name of the second book in bookList to 't'

A

Not all arithmetic operations can be performed on pointers. For example, you cannot __________ or __________ pointers. a. multiply, divide b. +=, -= c. add, subtract d. increment, decrement e. None of these

A

The ________ marker is the character that marks the end of a file, and is automatically written when the file is closed. A. End of File (EOF) B. Data Read Stop (DRS) C. No More Data (NMD) D. Data Stream Close (DSC)

A

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

A

This data type can be used to create files and write information to them but cannot be used to read information from them. A. ofstream B. ifstream C. outstream D. afstream E. none of these

A

This describes only the general characteristics of an object. A. abstraction B. detailed specification C. initiation D. initialization

A

This function will return true if its argument is a printable character other than a digit, letter, or space. A. ispunct B. isprint C. ischar D. isnotdls E. None of these

A

This is required after the closing brace of the structure declaration. A. semicolon B. colon C. period D. square bracket E. None of these

A

This is the escape sequence representing the null terminator. A. \0 B. \n C. nullptr D. \t E. None of these

A

This term means non-sequentially accessing information in a file. A. random access B. incremented access C. linear access D. protected access E. None of these

A

To set up a file to perform file I/O, you must declare: A. one or more file stream objects B. a string object to store the file contents C. at least one variable, the contents of which will be written to the file D. All of these E. None of these

A

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

A

To use the strlen function in a program, you must also write #include________. A. <cstring> B. <iostring> C. <strlen> D. <stringlib> E. none of these

A

What is the value stored in num after the following statement executes? num = atoi("1000"); a. 1000 b. 999 c. "1000" d. "1 thousand" e. None of these

A

What is true about the following statement? out.open("values.dat", ios::app); A. If the file already exists, its contents are preserved and all output is written to the end of the file. B. If the file exists, it can be opened but not modified. C. If the file exists, it should be replaced with a new copy of values.dat. E. None of these

A

What will the following code output? int number = 22; int *var = &number; cout << var << endl; A. the address of number B. 22 C. an asterisk followed by 22 D. an asterisk followed by the address of number

A

Select all that apply. Whitespace encompasses which of the following? a. a tab b. a newline c. a space d. None of these

A, B, C

Select all that apply. Which of the following would be appropriate in a program that allows the user to enter either an uppercase or lowercase character in response to a prompt? a. tolower b. ignorecase c. toupper d. ignoreupper e. ignorelower

A, C

Select all that apply. Of the following, which statements have the same meaning? a. int *ptr = nullptr; b. int ptr = nullptr; c. *int ptr = nullptr; d. int* ptr = nullptr; e. int ptr* = nullptr;

A, D

The ________ and ________ operators can be used to increment or decrement a pointer variable. A. ++, -- B. addition, subtraction C. modulus, division D. All of these E. None of these

A. ++, --

The ________, also known as the address operator, returns the memory address of a variable. A. ampersand ( & ) B. asterisk ( * ) C. percent sign (%) D. exclamation point ( ! ) E. None of these

A. ampersand ( & )

Use the delete operator only on pointers that were ________. A. created with the new operator B. never used C. dereferenced inappropriately D. not correctly initialized E. None of these

A. created with the new operator

Look at the following code: int numbers[] = {0, 1, 2, 3, 4 }; int *ptr = numbers; ptr++; After this code executes, which of the following statements is true? A. ptr will hold the address of numbers[1]. B. ptr will hold the address of numbers[0]. C. ptr will hold the address of the 2nd byte within the element numbers[0]. D. This code will not compile

A. ptr will hold the address of numbers[1].

A function may return a pointer, but the programmer must ensure that the pointer ________. A. still points to a valid object after the function ends B. has not previously been returned by another function C. has not been assigned an address D. was received as a parameter by the function E. None of these

A. still points to a valid object after the function ends

If a variable uses more than one byte of memory, for pointer purposes its address is ________. A. the address of the first byte of storage B. the address of the last byte of storage C. general delivery D. the average of the addresses used to store the variable E. None of these

A. the address of the first byte of storage

A library function that can find one C- string inside another is: A. strsearch B. strstr C. strfind D. strcmp E. none of these

B

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

B

A pointer variable may be initialized with a. any nonzero integer value b. a valid address in the computer's memory c. an address less than zero d. any nonzero number e. None of these

B

All stream objects have ________, which indicate the condition of the stream. A. condition statements B. error state bits c. markers d. intrinsic error messages

B

Data types that are created by the programmer are known as a. variables b. abstract data types (ADTs) c. functions d. parameters e. None of these

B

Dynamic memory allocation occurs a. when a new variable is created by the compiler b. when a new variable is created at runtime c. when a pointer fails to dereference the right variable d. when a pointer is assigned an incorrect address e. None of these

B

Given the string shown below, if the delimiter is a space, how many tokens are in the string? "Tony's email address is [email protected]" a. 4 b. 5 c. 6 d. 7 e. 9

B

In C++11, assuming mychar is a char variable and mystring is a string, what is the value of mychar after the following statement executes? mychar = mystring.front(); a. the ASCII value of the first character of mystring b. the first character of mystring c. nothing, the function is missing an argument d. this will cause a compiler error

B

Look at the following declaration. enum Tree { OAK, MAPLE, PINE }; What is the value of the following relational expression? OAK > PINE A. true B. false C. This is an error. You cannot compare enumerators with relational operators.

B

The __________ function will change a character argument from lowercase to uppercase. a. isupper b. toupper c. tolarge d. fromlower e. None of these

B

The __________ function will change a character argument from uppercase to lowercase. a. islower b. tolower c. atoi d. toupper e. None of these

B

The __________, also known as the address operator, returns the memory address of a variable. a. asterisk (* ) b. ampersand ( & ) c. percent sign ( % ) d. exclamation point ( ! ) e. None of these

B

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

B

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

B

The strcpy function's arguments are: A. three pointers B. two addresses C.one array and one pointer D. two C-strings E. none of these

B

This member function writes a single character to a file. A. get B. put C. write D. insert E. None of these

B

This state bit can be tested to see if the end of an input stream is encountered. A. ios::failbit B. ios::eofbit C. ios::badbit D. ios::eof E. None of these

B

This state bit is set when an attempted operation has failed. A. ios::badbit B. ios::failbit C. ios::goodbit D. ios::hardfail E. None of these

B

To change a character argument from lower to upper case, use this function. A. tolarge B. toupper C. fromlower D. isupper E. None of these

B

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. char lastName[26]; C. string lastName[25]; D. string lastName[24]; E. none of these

B

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

B

To test whether a character is a printable character, use this function. A. isprintable B. isprint C. isoktoprint D. isprintok E. None of these

B

What is the output of the following statement? cout << tolower(toupper('Z')) << endl; a.uppercase Z b. lowercase z c. a lowercase z followed by an uppercase Z d. a compiler error e. None of these

B

What is the result after the following statement executes? char var1 = tolower('A'); a. var1 stores the character value 'A' b. var1 stores the ASCII value for lowercase 'a' c. the character A is output to the monitor d. the character a is output to the monitor e. None of these

B

What will the following code output? int number = 22; int *var = &number; cout << *var << endl; a. the address of number b. 22 c. an asterisk followed by 22 b. an asterisk followed by the address of number

B

What will the following statement output? cout << &num1; a. the value stored in the variable named num1 b. the memory address of the variable named num1 c. the number 1 d. the string &num1 e. None of these

B

When a file is opened, the file stream object's "read position" is a. at the end of the file b. at the beginning of the file c. nonexistent until the programmer declares it d. in the middle of the file e. None of these

B

When a structure is passed ________ to a function, its members are not copied. A. by value B. by reference C. Neither of these

B

Which of the following 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 these

B

Which of the following is the member function that can be used to store binary data to a file? a. binary.out b. write c. put << d. dataout(binary) e. None of these

B

Which of the following statements opens a file and links it to a file stream object? a. open(aFile) = link(anObject); b. file.open("filename.txt"); c. linkstream("filename.txt"); d. link(open("filename.txt"); e. None of these

B

Which of the following will allow you to access structure members? a. the structure access operator b. the dot operator c. the #include<structaccess> directive d. the getmember function e. None of these

B

Which of the following will return true if the argument is a printable character other than a digit, letter, or space? a. isprint b. ispunct c. ischar d. isnotdls e. None of these

B

ofstream, ifstream, and fstream are: A. string arrays B. Data types C. header files D. libraries E. None of these

B

What will the following statement output? cout << &num1; A. The number 1 B. the memory address of the variable called num1 C. The value stored in the variable called num1 D. The string "&num1" E. None of these

B. The memory address of the variable called num1

A pointer variable may be initialized with ________. A. any non-zero integer value B. a valid address in the computer's memory C. an address less than 0 D. A and C only E. None

B. a valid address in the computer's memory

The following statement: int *ptr = new int; A. results in a compiler error B. assigns an address to the variable named ptr C. assigns an integer less than 32767 to the variable named ptr D. creates a new pointer named int E. None of these

B. assigns an address to the variable named ptr

In C++ 11, the ________ key word was introduced to represent the address 0. A. NULL B. nullptr C. weak_ptr D. All of these E. None of these

B. nullptr

To help prevent memory leaks from occurring in C++ 11, a ________ automatically deletes a chunk of dynamically allocated memory when the memory is no longer being used. A. null pointer B. smart pointer C. dereferenced pointer D. A and C only E. None of these

B. smart pointer

When you work with a dereferenced pointer, you are actually working with ________. A. a copy of the value pointed to by the pointer variable B. the actual value of the variable whose address is stored in the pointer variable C. a variable whose memory has been allocated D. All of these E. None of these

B. the actual value of the variable whose address is stored in the pointer variable

A declaration for an enumerated type begins with the __________ key word. a. enumerated b. enum_type c. enum d. ENUM e. None of these

C

A function ________ return a structure. A. will always B. may not C. may D. cannot possibly E. None of these

C

A good reason to pass a structure as a constant reference is ________. A. to ensure changes to the structure members B. to speed up the function's modification of the structure members C. to prevent changes to the structure members D. to slow down the function's execution, preventing errors E. None of these

C

A practical application of this function is to allow a user to enter a response of 'y' or 'Y' to a prompt. A. toupper B. tolower C. A or B D. ignorecase E. None of these

C

After the code shown executes, which of the following statements is true? int numbers[] = {0, 1, 2, 3, 4}; int *ptr = numbers; ptr++; a. ptr will hold the address of numbers[0] b. ptr will hold the address of the second byte within the element numbers[0] c. ptr will hold the address of numbers[1] d. this code will not compile

C

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

C

Before a structure can be used, it must be ________. A. initialized B. dereferenced C. declared D. All of these E. None of these

C

Closing a file causes any unsaved information still held in the file buffer to be ________. A. retained in the buffer for safekeeping B. duplicated C. saved to the file D. deleted E. None of these

C

Given the following structure decaration, Employee is struct Employee { string name; int idNum; }; a. a member b. an array c. a tag d. None of these

C

If Circle is a structure, the statement: Circle *pcirc = nullptr; A. initializes a null pointer with the value of the Circle pointer B. declares an empty structure variable called *pcirc C. declares a structure pointer called pcirc initialized with a null pointer D. is illegal in C++ E. None of these

C

If a variable uses more than one byte of memory, for pointer purposes its address is a. the address of the last byte of storage b. the average of all the addresses used to store that variable c. the address of the first byte of storage d. the address of the second byte of storage e. None of these

C

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

C

In order, the three-step process of using a file in a C++ program involves a. insert a disk, open the file, remove the disk b. create the file contents, close the file, name the file c. open the file, read/write/save data, close the file d. name the file, open the file, delete the file e. None of these

C

In the following statement, what does int mean? int *ptr = nullptr; a. The variable named *ptr will store an integer value. b. The variable named *ptr will store an asterisk and an integer value c. ptr is a pointer variable and will store the address of an integer variable. d. The variable named *ptr will store the value in nullptr. e. None of these

C

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 these

C

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

C

The end-of-file marker is automatically written a. when a file is opened with ios::eof b. when a file is opened with ios::app c. when a file is closed d. when the program ends e. None of these

C

The escape sequence that represents the null terminator is a. \n b. \t c. \0 d. nullptr e. None of these

C

The following statement __________ int *ptr = new int; a. results in a compiler error b. assigns an integer less than 32767 to the variable ptr c. assigns an address to the variable ptr d. creates a new pointer named int e. None of these

C

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

C

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

C

The null terminator stands for this ASCII code. A. 57 B. 100 C. 0 D. 1000 E. None of these

C

To dereference a structure pointer, the appropriate operator is a. the ampersand (&) b. an asterisk (*) c. the -> operator d. the <- operator (<-) e. None of these

C

To test whether a character is a numeric digit character, use this function. A. isnumber B. notAlpha C. isdigit D. isnumeric E. none of these

C

To use the strlen function in a program you must include a. #include<strlen> b. #include<iostring> c. #include<cstring> d. #include<stringlib> e. None of these

C

Use the delete operator only on pointers that were a. never used b. not correctly initialized c. created with the new operator d. dereferenced inappropriately e. None of these

C

When the less than operator (<) is used between two pointer values, the expression is testing whether a. the value pointed to by the first is less than the value pointed to by the second b. the value pointed to by the first is greater than the value pointed to by the second c. the address of the first variable comes before the address of the second variable in the computer's memory d. the first variable was declared before the second variable e. None of these

C

When you work with a dereferenced pointer, you are actually working with a. a variable whose memory has been allocated b. a copy of the value pointed to by the pointer variable c. the actual value of the variable whose address is stored in the pointer variable d. None of these

C

Which of the following access flags, when used by itself, causes a file's contents to be deleted if the file already exists? a. ios::app b. ios::in c. ios::out d. Any of these e. None of these

C

Which of the following 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

C

Which of the following is the data type that can be used to create files, read data from them, and write data to them? a. ofstream b. ifstream c. fstream d. stream e. None of these

C

Which of the following is the directive you must use to access files from a C++ program? a. #include <fileaccess> b. #include <filestream> c. #include <fstream> d. #include <iostream> e. None of these

C

Which of the following is true about this statement: sum += *array++; a. This statement is illegal in C++. b. This statement will cause a compiler error. c. This statement assigns the dereferenced pointer's value, then increments the pointer's address. d. This statement increments the dereferenced pointer's value by one, then assign that value. e. None of these

C

Which of the following statements appropriately defines a C-string that stores names of up to 25 characters? a. char name[25]; b. string name[25]; c. char name[26]; d. string name[24]; e. None of these

C

Which of the following statements deletes memory that has been dynamically allocated for an array? a. int array = delete memory; b. int delete[ ]; c. delete [] array; d. new array = delete; e. None of these

C

Which of the following statements opens the file info.txt for both input and output? A. dataFile.open("info.txt", input || output); B. dataFile.open("info.txt", ios::in , ios::out); C. dataFile.open("info.txt", ios::in | ios::out); D. dataFile.open("info.txt", ios::in && ios::out);

C

Which statement converts the string "10" to the integer value 10? A. atoi("ten") B. itoa("ten") C. atoi("10") D. itoa(10) E. none of these

C

Which statement opens a file and links it to a file stream object? A. linkstream("filename.txt"); B. open(aFile) = link(anObject); C. file.open("c:\\filename.txt"); D. link(open(filename.txt")); E. None of these

C

Which statement opens a file in such a way that information will only be written to its end? A. dataFile(open.append("info.dat")); B. dataFile.open = "C:\\info.dat" ios:append; C. dataFile.open("info.dat", ios::out | ios::app); D. open(dataFile.append); E. None of these

C

With pointer variables you can __________ manipulate data stored in other variables. a. never b. seldom c. indirectly d. All of these e. None of these

C

Select all that apply. Select as many of the following options that make this sentence true: The contents of pointer variables may be changed with mathematical statements that perform a. multiplication b. division c. addition d. subtraction e. modulus

C, D

Every byte in the computer's memory is assigned a unique ________. A. pointer B. dynamic allocation C. address D. name E. None

C. address

Which of the following statements deletes memory that has been dynamically allocated for an array? A. new array = delete; B. int delete[ ]; C. delete [] array; D. int array = delete memory; E. None of these

C. delete [] array;

With pointer variables, you can ________ manipulate data stored in other variables. A. seldom B. never C. indirectly D. All of these E. None

C. indirectly

If you are using an older compiler that does not support the C++ 11 standard, you should initialize pointers with ________. A. a nonzero value B. the null terminator '\0' C. the integer 0, or the value NULL D. All of these E. None of these

C. the integer 0, or the value NULL

"Whitespace" encompasses which of the following? A. newline B. tab C. space D. all of these E. none of these

D

A pointer variable is designed to store a. any legal C++ value b. only floating-point values c. an integer d. a memory address e. None of these

D

Data stored here disappears once the program stops running or the computer is powered down. A. on a CD B. on the disk drive C. on a backup tape D. in RAM E. None of these

D

In C++, a C-string is a sequence of characters stored in consecutive memory, terminated by a ________. A. period B. semicolon C. space D. null character E. none of these

D

In C++11, you can use a new type of enum known as a(n) __________ (also known as an enum class) to have multiple enumerators with the same name, within the same scope. a. universal enum b. auto enum c. multi-cast enum d. strongly typed enum e. None of these

D

Look at the following statement. if (!isdigit(var1)) The expression being tested by this statement will evaluate to true if var1 is: A. a symbol such as $ or & B. 9 C. an alphabetic character D. both A and C E. none of these

D

Outside of a C++ program, a file is identified by its __________while inside a C++ program, a file is identified by a(n) __________. a. file number, file name b. File name, file number c. name, address d. name, file stream object e. None of these

D

The expression being tested by the statement shown below will evaluate to true if var1 is __________. if (!isdigit(var1)) a.an alphabetic character b. 9 c. a symbol such as $ or & d. both A and C e. None of these

D

The following statement __________ cin >> *num3; a. stores the keyboard input in the variable num3 b. stores the keyboard input into the pointer num3 c. is illegal in C++ d. stores the keyboard input into the variable pointed to by num3 e. None of these

D

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

D

This function accepts a C-string containing a number as its argument and returns the integer equivalent. A. int_from B. strToInt C. itoa D. atoi E. None of these

D

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. strintcpy B. copystring C. strcpy D. strncpy E. none of these

D

This member function reads a single character from a file. A. put B. read C. input D. get E. None of these

D

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

D

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

D

What does the following statement do? double *num2; a. Declares a double variable named num2 b. Declares and initializes a pointer variable named num2 c. Initializes a pointer variable named num2 d. Declares a pointer variable named num2 e. None of these

D

What is the output of the following statement? cout << tolower(toupper('Z')) << endl; A. a lower case z followed by an upper case Z B. upper case Z C. a compiler error D. lower case z E. None of these

D

What will the following code output? int *numbers = new int[5]; for (int i = 0; i <= 4; i++) *(numbers + i) = i; cout << numbers[2] << endl; a.five memory addresses b.0 c. 3 d. 2 e. 1

D

Which of the following assigns a value to the hourlyWage member of employee[2]? a. employee[2] -> hourlyWage = 50.00; b. employee2.hourlyWage = 7.50; c. hourlyWage[2].employee = 29.75; d. employee[2].hourlyWage = 75.00; e. None of these

D

Which of the following defines a unique_ptr named uniq that points to a dynamically allocated int? a. unique_ptr<uniq> int( new int ); b. unique_ptr<int> int( new uniq ); c. unique_ptr<uniq> uniq( new int ); d. unique_ptr<int> uniq( new int ); e. None of these

D

Which of the following is an example of a C++ primitive data type? a. unsigned short int b. long double c. unsigned char d. All of these e. None of these

D

Which of the following statements displays the address of the variable numb? a. cout << numb; b. cout << *numb; c. cin >> &numb; d. cout << &numb; e. None of these

D

Which of the following statements outputs the value of the gpa member of element 1 of the student array? A. cout << student1.gpa; B. cout << firstStudent.gpa; C. cout << student1->gpa; D. cout << student[1].gpa;

D

With an enumerated data type, the enumerators are stored in memory as a. strings b. integers c. characters d. doubles

D

You may use a pointer to a structure as a ________. A. function return type B. structure member C. function parameter D. all of these E. None of these

D

When the less than ( < ) operator is used between two pointer variables, the expression is testing whether ________. A. the value pointed to by the first is less than the value pointed to by the second B. the first variable was declared before the second variable C. the value pointed to by the first is greater than the value pointed to by the second D. the address of the first variable comes before the address of the second variable in the computer's memory E. None of these

D. the address of the first variable comes before the address of the second variable in the computer's memory

Look at the following declaration. enum Tree { OAK, MAPLE, PINE }; In memory, what value will the MAPLE enumerator be stored as? A. 'M' B. "MAPLE" C. 2 D. 1.0 E. 1

E

The function that reverses the order of a C-string is a. reversstr b. strrev c. reverseit d. back e. None of these

E

The name of a structure is referred to as its a. data type b. argument c. parameter d. tag e. None of these

E

This data type can be used to create files and read information from them into memory. A. ifstream B. istream C. ofstream D. instream E. None of these

E

When you pass a pointer as an argument to a function, you must a. declare the pointer value again in the function call b. dereference the pointer value in the function prototype c. use the #include<func.ptr.h> statement d. not dereference the pointer in the function's body e. None of these

E

Which of the following statements is not valid C++ code? a. int ptr = &num1; b. int ptr = int *num1; c. float num1 = &ptr2; d. All of these are valid e. All of these are invalid

E

What will the following code output? int *numbers = new int[5]; for (int i = 0; i <= 4; i++) *(numbers + i) = i; cout << numbers[2] << endl; A. Five memory addresses B. 1 C. 3 D. 0 E. 2

E. 2

Which of the following statements is not valid C++ code? A. float num1 = &ptr2; B. int ptr = int *num1; C. int ptr = &num1; D. All of these are valid. E. All of these are invalid.

E. All of these are invalid.

TRE/FALSE: To write to a file, you use the file_write function.

F

TRUE/ FALSE: A function cannot modify the members of a structure.

F

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

F

TRUE/ FALSE: Only one file stream object can be declared per C++ program.

F

TRUE/ FALSE: The C++ compiler performs strict array bounds checking when it encounters an array of characters.

F

TRUE/ FALSE: The following string that uses a semicolon as a delimiter contains four tokens: "apple;cherry;lemon cream"

F

TRUE/ FALSE: The ftoa function converts a floating-point value to an ASCII value.

F

TRUE/ FALSE: The strlen function returns a C-string's length and adds one for \0.

F

TRUE/FALSE: A test using the isupper function will return false if the argument is an uppercase character.

F

TRUE/FALSE: An alternative to using the open member function is to use the file stream object declaration itself to open the file. For example: fstream DataFile("names.dat", ios::in | ios::out);

F

TRUE/FALSE: Given the structure definition shown, assume that circle1 and circle2 are variables of the Circle type and their members have been initialized. struct Circle { double centerX; double centerY; double radius; }; Then, is it true or false that the following statement correctly determines whether the two variables' members contain the same data? if (circle1 == circle2)

F

TRUE/FALSE: It is possible to output the contents of all members of a structure variable using a cout << statement followed by the name of the structure variable.

F

TRUE/FALSE: The names of enumerators in an enumerated data type must be enclosed in quotation marks.

F

TRUE/FALSE: When used by itself, the ios::app flag causes the file's existing contents to be deleted if the file already exists.

F

True/ False: The ampersand (&) is used to dereference a pointer variable in C++.

F

True/ False: The weak_ptr can share ownership of a piece of dynamically allocated memory.

F

True/ False: With pointer variables you can access but not modify data in other variables.

F

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

F

True/False: By default, files are opened in binary mode.

F

True/False: The setprecision manipulator cannot be used to format data written to a file.

F

True/False: When data is read from a file, it is automatically stored in a variable.

F

True/False: When you store data in a variable, it is automatically saved in a file.

F

True/False: You cannot directly assign an enumerator to an int variable.

F

When you pass a pointer as an argument to a function, you must ________ - dereference the pointer variable in the function prototype - declare the pointer variable again in the function call - use the #include <func_ptr.h> statement - not dereference the pointer in the function's body - None of these

None of these

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

T

TRUE/ FALSE: C++11 introduces a function named to_string that converts a numeric value to a string object.

T

TRUE/ FALSE: If an uppercase character is passed as an argument to the toupper function, the result will be an uppercase character.

T

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

T

TRUE/ FALSE: The isdigit function will return true if the argument is a digit between 0 and 9.

T

True/False: An array name is a pointer constant because the address stored in it cannot be changed during runtime.

True

True/False: Assuming myValues is an array of int values, and index is an int variable, both of the following statements do the same thing. cout << myValues[index] << endl; cout << *(myValues + index) << endl;

True


Ensembles d'études connexes

Chapters 4.3 & 4.4: Optical Microscopy/ Electron Microscopy

View Set

Chapter 20. Pediatric Variations of Nursing Interventions

View Set

L4 - Life Insurance Premiums, Proceeds, and Beneficiaries

View Set

Code of Ethics and Standards of Professional Conduct

View Set

Chapter 02. The Founding and the Constitution Federal Government - We The People 10th Edition - InQuizitive

View Set