C++ Final Ch 10 & 13

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

7) This directive is used to create an "include guard," which allows a program to be conditionally compiled. This prevents a header file from accidentally being included more than once. A) #include B) #guard C) #ifndef D) #endif E) None of these

#ifndef

19) When you dereference an object pointer, use the ________. A) -> operator B) <> operator C) dot operator D) & operator E) None of these

-> operator

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

0

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

1000

31) What is the output of the following program? #include <iostream> using namespace std; class TestClass { public: TestClass(int x) { cout << x << endl; } TestClass() { cout << "Hello!" << endl; } }; int main() { TestClass test(77); return 0; } A) The program runs, but with no output. B) 77 C) Hello! D) The program will not compile.

77

22) To use the strlen function in a program, you must also write #include ________. A) <strlen> B) <iostring> C) <cstring> D) <stringlib> E) None of these

<cstring>

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

A or B

14) "Whitespace" encompasses which of the following? A) tab B) newline C) space D) All of these E) None of these

All of these

30) What is the output of the following program? #include <iostream> using namespace std; class TestClass { public: TestClass(int x) { cout << x << endl; } TestClass() { cout << "Hello!" << endl; } }; int main() { TestClass test; return 0; } A) The program runs, but with no output. B) 0 C) Hello! D) The program will not compile.

Hello!

25) The process of object-oriented analysis can be viewed as the following steps: A) Identify objects, then define objects' attributes, behaviors, and relationships B) Define data members and member functions, then assign a class name C) Declare private and public variables, prototype functions, then write code D) Write the main() function, then determine which classes are needed E) None of these

Identify objects, then define objects' attributes, behaviors, and relationships

10) The constructor function's return type is ________. A) int B) float C) char D) structure pointer E) None of these

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

None of these

11) The destructor function's return type is ________. A) tilde B) int C) float D) Nothing. Destructors have no return type. E) None of the above

Nothing. Destructors have no return type.

32) What is the output of the following program? #include <iostream> using namespace std; class TestClass { private: int val; void showVal() { cout << val << endl; } public: TestClass(int x) { val = x; } }; int main() { TestClass test(77); test.showVal(); return 0; } A) The program runs, but with no output. B) 77 C) 0 D) The program will not compile.

The program will not compile

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

\0

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

atoi

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

atoi

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

atoi("10)

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

atol

2) In OOP terminology, an object's member variables are often called its ________, and its member functions are sometimes referred to as its behaviors, or ________. A) values, morals B) data, activities C) attributes, activities D) attributes, methods E) None of these

attributes, methods

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

both A and C

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

char lastName[26];

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

char str[50];

26) When a member function is defined outside of the class declaration, the function name must be qualified with the ________. A) class name, followed by a semicolon B) class name, followed by the scope resolution operator C) name of the first object D) private access specifier E) None of these

class name, followed by the scope resolution operator

9) A ________ is a member function that is automatically called when a class object is ________. A) destructor, created B) constructor, created C) static function, deallocated D) utility function, declared E) None of these

constructor, created

16) A class is a(n) ________ that is defined by the programmer. A) data type B) function C) method D) attribute E) None of these

data type

1) Objects are created from abstract data types that encapsulate ________ and ________ together. A) numbers, characters B) data, functions C) addresses, pointers D) integers, floats E) None of these

data, functions

15) In a procedural program, you typically have ________ stored in a collection of variables, and a set of ________ that perform operations on the data. A) numbers, arguments B) parameters, arguments C) strings, operators D) data, functions E) None of these

data, functions

12) When a constructor function accepts no arguments, or does not have to accept arguments because of default arguments, it is called a(n) ________. A) empty constructor B) default constructor C) stand-alone function D) arbitrator function E) None of these

default constructor

18) Assuming that Rectangle is a class name, the statement: Rectangle *BoxPtr; A) declares an object of class Rectangle B) assigns the value of *BoxPtr to the object Rectangle C) defines a Rectangle pointer variable called BoxPtr D) is illegal in C++ E) None of these

defines a Rectangle pointer variable called BoxPtr

22) This is automatically called when an object is destroyed. A) constructor function B) specification deallocator C) destructor function D) coroner function E) None of these

destructor function

17) Members of a class object are accessed with the ________. A) dot operator B) cin object C) extraction operator D) stream insertion operator E) None of these

dot operator

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

eleven characters and the null terminator

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

false

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.

false

2) True/False: Class objects can be defined prior to the class declaration.

false

3) True/False: The constructor function may not accept arguments.

false

4) True/False: A destructor function can have zero to many parameters.

false

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

false

6) True/False: More than one destructor function may be defined for a class.

false

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

false

8) True/False: You must declare all data members of a class before you declare member functions.

false

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

false

9) True/False: You must use the private access specification for all data members of a class.

false

6) Class declarations are usually stored here. A) on separate disk volumes B) in their own header files C) in .cpp files, along with function definitions D) under pseudonyms E) None of these

in their own header files

8) When the body of a member function is defined inside a class declaration, it is said to be ________. A) static B) global C) inline D) conditional E) None of these

inline

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

isalpha

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

isdigit

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

isprint

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

ispunct

18) To determine whether a character is whitespace, use this function. A) iswhite B) isspace C) iswhitespace D) isblank E) None of these

isspace

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

lower case z

29) Assume that myCar is an instance of the Car class, and that the Car class has a member function named accelerate. Which of the following is a valid call to the accelerate member function? A) Car->accelerate(); B) myCar::accelerate(); C) myCar.accelerate(); D) myCar:accelerate();

myCar.accelerate();

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

null terminator

23) A class may have this many default constructor(s). A) only one B) more than one C) a maximum of two D) any number E) None of these

only one

14) If you do not declare an access specification, the default for members of a class is ________. A) inline B) private C) public D) global E) None of these

private

20) This type of member function may be called only from a function that is a member of the same class. A) public B) private C) global D) local E) None of these

private

5) This is used to protect important data. A) public access specifier B) private access specifier C) protect() member function D) class protection operator, @ E) None of these

private access specifier

4) Examples of access specifiers are the key words: A) near and far B) opened and closed C) private and public D) table and row E) None of these

private and public

13) This type of member function may be called from a statement outside the class. A) public B) private C) undeclared D) global E) None of these

public

27) If a local variable and a global variable have the same name within the same program, the ________ resolution operator must be used. A) variable B) ambiguity C) scope D) global E) None of these

scope

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

strcat

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

strlen

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

strncpy

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

strstr

3) A C++ class is similar to one of these. A) inline function B) header file C) library function D) structure E) None of these

structure

24) Objects in an array are accessed with ________, just like any other data type in an array. A) subscripts B) parentheses C) #include statements D) output format manipulators E) None of these

subscripts

21) The constructor function always has the same name as ________. A) the first private data member B) the first public data member C) the class D) the first object of the class E) None of these

the class

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

toupper

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

toupper

1) True/False: Whereas object-oriented programming centers on the object, procedural programming centers on functions.

true

10) True/False: A private member function is useful for tasks that are internal to the class, but is not directly called by statements outside the class.

true

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

true

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

true

11) True/False: If you do not declare a destructor function, the compiler will furnish one automatically.

true

12) True/False: When an object is defined without an argument list for its constructor, the compiler automatically calls the object's default constructor.

true

13) True/False: One purpose that constructor functions are often used for is to allocate memory that will be needed by the object.

true

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

true

14) True/False: C++ 11 introduces a function named to_string that converts a numeric value to a string object.

true

14) True/False: One purpose that destructor functions are often used for is to free memory that was allocated by the object.

true

15) True/False: The string class's front and back member functions were introduced in C++ 11.

true

15) True/False: When using smart pointers to dynamically allocate objects in C++ 11, it is unnecessary to delete the dynamically allocated objects because the smart pointer will automatically delete them.

true

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

true

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

true

5) True/False: More than one constructor function may be defined for a class.

true

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

true

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

true

7) True/False: Object-oriented programming is centered around the object, which encapsulate together both the data and the functions that operate on the data.

true

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

true

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

two addresses

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

var1 storing the ASCII value for lower case 'a'.

28) For the following code, which statement is not true? class Point { private: double y; double z; public: double x; }; A) x is available to code that is written outside the class. B) The name of the class is Point. C) x, y, and z are called members of the class. D) z is available to code that is written outside the class.

z is available to code that is written outside the class.


Ensembles d'études connexes

Chapter 34: Management of Patients With Hematologic Neoplasms - N266 Sp2019

View Set

Geometry B-5, Geometry Ch. 4, Geometry Ch. 3, Geometry Ch. 2

View Set

Reading Explorer 4 Unit 4 Reading B

View Set

Reading Quiz 5: Geologic Time, Evolution, and Fossils (Ch. 5, 6 & 10) Week 6 & 7

View Set

Chapter one- American government and civic engagement

View Set

HIM 481 White Ch 5 Variance Analysis

View Set