C++ Chapter 2

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Because C++ is case-sensitive, all programs must have a function called main or Main. (T/F)

F

C++ 11 introduced an alternative way to define variables, using the template key word and an initialization value. (T/F)

F

In C++ you are required to name your variables so they indicate the purpose they will be used for. (T/F)

F

In programming, the terms "line" and "statement" always mean the same thing. (T/F)

F

The preprocessor executes after the compiler. (T/F)

F

A named constant is like a variable, but it its content cannot be changed while the program is running. (T/F)

T

A value is stored in a variable with an assignment statement. (T/F)

T

C++ does not have a built-in data type for storing strings of data. (T/F)

T

Escape sequences are always stored internally as a single character. (T/F)

T

Floating point constants are normally stored in memory as doubles. (T/F)

T

In C++, key words are written in all lowercase letters. (T/F)

T

Programming style refers to the way a programmer uses elements such as identifiers, spaces, and blank lines. (T/F)

T

The preprocessor reads a program before it is compiled and only executes those lines beginning with # symbol. (T/F)

T

When typing your source code into the computer, you should be careful since most of your C++ instructions, header files, and variable names are case sensitive. (T/F)

T

"Which of the following is not a valid C++ identifier? a. 43191 b. employee_number b. employee_number c. _1user d. 1user e. theLittleBrownFoxWhoRanAway"

d. 1user

"What will the following code display? int x = 23, y = 34, z = 45; cout << x << y << z << endl; a. 23 34 45 b. 23 34 45 b. 23 34 45 c. xyz d. 233445 "

d. 233445

"A multi-line comment a. begins with /* and ends with */ b. can be used to mark as many lines as desired as comments b. can be used to mark as many lines as desired as comments c. allows everything in the selected lines to be ignored d. All of these are true "

d. All of these are true

"In C++11, if you want an integer literal to be treated as a long long int, you can append __________ at the end of the number. a. L b. <L L> b. <L L> c. LONG LONG d. LL e. <LONG>"

d. LL

"Which data type typically requires only one byte of storage? a. short b. int b. int c. float d. char e. string"

d. char

"For every opening brace ({) in a C++ program, there must be a a. string literal b. function b. function c. comment d. closing brace e. None of these"

d. closing brace

"A character literal is __________, whereas a string literal is __________ a. enclosed in quotation marks, enclosed in brackets b. enclosed in brackets, enclosed in quotation marks b. enclosed in brackets, enclosed in quotation marks c. enclosed in double quotation marks, enclosed in single quotation marks d. enclosed in single quotation marks, enclosed in double quotation marks e. None of these"

d. enclosed in single quotation marks, enclosed in double quotation marks

"What will the following code display? cout << ""Four\n"" << ""score\n""; cout << ""and"" << ""\nseven""; cout << ""\nyears"" << "" ago"" << endl; a. Four score and seven years ago b. Four score and seven years ago b. Four score and seven years ago c. Four score and seven years ago d. Four score and seven years ago "

"a. Four score and seven years ago

"What is the value of cookies after the following statements execute? nt number = 38, children = 4, cookies; cookies = number % children; a. 2 b. 4 b. 4 c. 9 d. 9.5 e. 0.5"

a. 2

"What is the value stored in the variable myNum after the following assignment statement executes? myNum = 23 % 5 a. 3 b. 4 b. 4 c. 4.6 d. 115 e. None of these"

a. 3

"In a cout statement, which of the following will advance the output position to the beginning of the next line? a. endl or \n b. end1 or /n b. end1 or /n c. \n or \t d. \t or \b e. \\ or \'"

a. endl or \n

Select all that apply. Using C++11: Which of the following can be used to initialize an integer variable named dozen with the value of 12? a. int dozen = 12; b. int dozen(12); b. int dozen(12); c. int dozen = {12}; d. int dozen = (12); e. int dozen {12};"

a. int dozen = 12; b. int dozen(12); e. int dozen {12};

"The float data type is considered ___________ precision and the double data type is considered __________ precision. a. single, double b. double, single b. double, single c. floating-point, double d. floating-point, integer e. None of these"

a. single, double

"The data type of a variable whose value can be either true or false is a. int b. binary b. binary c. bool d. Boolean e. T/F"

c. bool

"What is output of the following statement? cout << 4 * (15 / (1 + 3)) << endl; a. 15 b. 12 b. 12 c. 63 d. 72 e. None of these"

b. 12

"What is the value of number after the following statements execute? int number; number = 18 % 4 + 2; a. 3 b. 4 b. 4 c. 6.5 d. 0 e. unknown"

b. 4

"What is the value of number after the following statements execute? int number; number = 18 / 4; a. 4.5 b. 4 b. 4 c. 2 d. 0 e. unknown"

b. 4

"Select all that apply. Which of the following statements is(are) true about named constants? a. A named constant must be all uppercase. b. The content of a named constant is read-only. b. The content of a named constant is read-only. c. The value of a named constant cannot be changed while the program is running. d. A named constant is defined using the const qualifier. e. None of these"

b. The content of a named constant is read-only. c. The value of a named constant cannot be changed while the program is running. d. A named constant is defined using the const qualifier.

"Using C++11: What data type does the compiler determine for the variable cost in the following statement? auto cost = 14.95; a. int b. double b. double c. bool d. char e. string"

b. double

"Which of the following defines a double-precision floating-point variable named payCheck? a. float payCheck; b. double payCheck; b. double payCheck; c. payCheck double; d. Double payCheck; "

b. double payCheck;

"Every complete C++ program must have a a. comment b. function named main b. function named main c. symbolic constant d. cout statement e. None of these"

b. function named main

"Besides the decimal number system that is most common (base 10), two other number systems that can be used in C++ programs are a. octal and fractal b. octal and hexadecimal b. octal and hexadecimal c. base 2 and base 4 d. base 2 and binary e. None of these"

b. octal and hexadecimal

"In the following statement, the characters Hello! are a(n) cout << ""Hello!""; a. variable a. variable b. string literal c. comment d. object"

b. string literal

"In a C++ program, two slash marks (//) indicate a. the end of a statement b. the beginning of a comment b. the beginning of a comment c. the end of a program d. the beginning of a block of code e. None of these"

b. the beginning of a comment

"Which of the following must be included in any program that uses the cout object? a. opening and closing braces b. the header file iostream b. the header file iostream c. comments d. a namespace e. None of these"

b. the header file iostream

"A(n) __________ represents a storage location in the computer's memory. a. literal b. variable b. variable c. comment d. integer e. None of these"

b. variable

"You must have a _____________ for every variable you intend to use in a program. a. purpose b. variable definition b. variable definition c. memory space d. literal value e. None of these"

b. variable definition

"Which of the following lines must be included in a program that has string variables? a. #include (string class) b. #include namespace std; b. #include namespace std; c. #include <string> d. string var; e. None of these"

c. #include <string>

"The __________ causes the content of another file to be inserted into a program. a. cout object b. double slash (//) b. double slash (//) c. #include directive d. semicolon (;) e. None of these"

c. #include directive

"What will the following code display? cout << ""Monday""; cout << ""Tuesday""; cout << ""Wednesday""; a. Monday Tuesday Wednesday b. Monday Tuesday Wednesday b. Monday Tuesday Wednesday c. MondayTuesdayWednesday d. ""Monday"" ""Tuesday"" ""Wednesday"" e. ""Monday"" ""Tuesday"" ""Wednesday"""

c. MondayTuesdayWednesday

" "What will the following code display? cout << ""Four\n"" << ""score\n""; cout << ""and"" << ""\nseven""; cout << ""\nyears"" << "" ago"" << endl; a. Roses are red and violets are blue b. Roses are red and violets/nare blue b. Roses are red and violets/nare blue c. Roses are redand violets/nareblue d. Roses are red and violets/n are blue "

c. Roses are redand violets/nareblue

"What will the following code display? int number = 23; cout << ""The number is "" << ""number"" << endl; a. The number is 23 b. The number is23 b. The number is23 c. The number is number d. The number is null e. The number is "

c. The number is number

"What will be the output after the following lines of code execute? bool choice; choice = true; cout << ""Your choice is "" << choice << endl; a. TRUE b. Your choice is true b. Your choice is true c. Your choice is 1 d. Your choice is choice e. None of these"

c. Your choice is 1

"Which control sequence is used to skip over to the next horizontal tab stop? a. \n b. end1 b. end1 c. \t d. \b e. \'"

c. \t

"Which of the following statements correctly defines a named constant named TAX_RATE that holds the value 0.075? a. double TAX_RATE = 0.075; b. const TAX_RATE; double TAX_RATE = 0.075; b. const TAX_RATE; double TAX_RATE = 0.075; c. const double TAX_RATE = 0.075; d. double TAX_RATE; const TAX_RATE = 0.075; e. const TAX_RATE = 0.075;"

c. const double TAX_RATE = 0.075;

"The __________ is(are) used to display information on the computer's screen. a. opening and closing braces b. opening and closing quotation marks b. opening and closing quotation marks c. cout object d. backslash e. None of these"

c. cout object

"The data type used to declare variables that can hold real numbers is a. short b. int b. int c. float d. char e. double"

c. float

"The numeric data types in C++ can be broken into two general categories which are a. numbers and characters b. singles and doubles b. singles and doubles c. integers and floating-point numbers d. real and unreal numbers e. numbers and literals"

c. integers and floating-point numbers

"Which of the following statements correctly assigns the character M to the variable named letter? a. letter = M b. letter = ""M""; b. letter = ""M""; c. letter = 'M'; d. letter = (M); e. letter = M;"

c. letter = 'M';

"Given the following program, which line(s) cause(s) output to be displayed on the screen? // This program displays my gross wages. 2 // I worked 40 hours and I make $20.00 per hour. 3 #include <iostream> 4 using namespace std; 5 6 int main() 7 { 8 int hours; 9 double payRate, grossPay; 10 11 hours = 40; 12 payRate = 20.0; 13 grossPay = hours * payRate; 14 cout << ""My gross pay is $"" << grossPay << endl; 15 return 0; 16 } a. lines 13 and 14 b. lines 8 and 9 b. lines 8 and 9 c. line 14 d. lines 14 and 15 e. line 15"

c. line 14

"Assuming that a program has the following string object definition, which statement correctly assigns the string literal ""Jane"" to the string object? string name; a. name = Jane; b. name = 'Jane'; b. name = 'Jane'; c. name = ""Jane""; d. name = <Jane>; e. string name = {Jane};"

c. name = "Jane";

"In memory, C++ automatically places a(n) __________ at the end of string literals which __________. a. semicolon, indicates the end of the statement b. \n, indicates an escape sequence b. \n, indicates an escape sequence c. null terminator, marks the end of the string d. bracket, marks the end of the string e. None of these"

c. null terminator, marks the end of the string

"A statement that starts with a hashtag (or pound) symbol (#) is called a a. comment b. function b. function c. preprocessor directive d. header file e. None of these"

c. preprocessor directive

"A variable's __________ is the part of the program that has access to the variable. a. data type b. value b. value c. scope d. assignment e. None of these"

c. scope

"Character constants in C++ are always enclosed in a. brackets ( < > ) b. braces ( { } ) b. braces ( { } ) c. single quotation marks ( ' ' ) d. pound sign and semicolon ( # ; ) e. Any of these"

c. single quotation marks ( ' ' )

"A variable definition tells the computer a. the variable's name and its value b. the variable's data type and its value b. the variable's data type and its value c. the variable's name and the type of data it will hold d. whether the variable is an integer or a floating-point number e. None of these"

c. the variable's name and the type of data it will hold

"Which part of the following line is ignored by the compiler? double userName = ""janedoe""; // user's name is janedoe a. ""janedoe"" b. user's name is b. user's name is c. user's name is janedoe d. // e. None of these"

c. user's name is janedoe


संबंधित स्टडी सेट्स

Unit 7 Disclosures in Real Estate: Seller's Statutory Disclosures

View Set

IB Geography Option D- Hazards and disasters - risk assessment and response

View Set

LIFE INSURANCE - TAXES AND OTHER INSURANCE CONCEPTS

View Set