C++ Chapter 2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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 c. bool d. char e. string ANS: B

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

ANS: B

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 c. Your choice is 1 d. Your choice is choice None of these

ANS: C

Data items whose values do not change while the program is running are a. literals b. variables c. characters d. integers e. None of these

ANS: A

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 c. \n or \t d. \t or \b e. \\ or \'

ANS: A

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

ANS: A

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

ANS: A

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

ANS: B

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

ANS: B

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

ANS: C

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.

ANS: T

What will the following code display?

cout << "Roses " << "are red"; cout << "and " << "violets/n" cout << "are" << "blue" << endl; a. Roses are red and violets are blue b. Roses are red and violets/nare blue c. Rosesareredandviolets/nareblue d. Roses are red and violets/n are blue ANS: C

What is the value of cookies after the following statements execute?

int number = 38, children = 4, cookies; cookies = number % children; a. 2 b. 4 c. 9 d. 9.5 e. .5 ANS: A

What is the value of number after the following statements execute? int number;

number = 18 % 4 + 2; a. 3 b. 4 c. 6.5 d. 0 e. unknown ANS: B

What will the following code display?

int number = 23; cout << "The number is " << "number" << endl; a. The number is 23 b. The number is23 c. Thenumberisnumber d. The number is null e. Thenumberis ANS: C

What is the value of number after the following statements execute? int number;

number = 18 / 4; a. 4.5 b. 4 c. 2 d. 0 e. unknown ANS: B

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

ANS: C

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

ANS: C

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

ANS: C

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 c. Four score and seven years ago d. Four score and seven years ago

ANS: A

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. intdozen=12; b. int dozen(12); c. int dozen = {12}; d. int dozen = (12); e. intdozen{12};

ANS: A,B,E

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 c. base 2 and base 4 d. base 2 and binary e. None of these

ANS: B

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

ANS: B

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

ANS: B

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

ANS: B

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 c. comments d. a namespace e. None of these

ANS: B

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

ANS: B

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

ANS: B,C,D

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

ANS: C

A variable definition tells the computer a. the variable's name 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

ANS: C

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

ANS: C

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'; c. name="Jane"; d. name = <Jane>; e. stringname={Jane};

ANS: C

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

ANS: C

Given the following program, which line(s) cause(s) output to be displayed on the screen? 1 // 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 c. line 14 d. lines 14 and 15 e. line 15

ANS: C

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 c. null terminator, marks the end of the string d. bracket, marks the end of the string e. None of these

ANS: C

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

ANS: C

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

ANS: C

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

ANS: C

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

ANS: C

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

ANS: C

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; c. constdoubleTAX_RATE=0.075; d. double TAX_RATE; const TAX_RATE = 0.075; e. const TAX_RATE = 0.075;

ANS: C

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 c. user's name is janedoe d. // e. None of these

ANS: C

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

ANS: D

A multi-line comment a. begins with /* and ends with */ 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

ANS: D

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

ANS: D

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. <LL> c. LONG LONG d. LL e. <LONG>

ANS: D

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

ANS: D

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

ANS: D

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

ANS: D

Because C++ is case-sensitive, all programs must have a function called main or Main.

ANS: F

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

ANS: F

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

ANS: F

In programming, the terms "line" and "statement" always mean the same thing.

ANS: F

The preprocessor executes after the compiler.

ANS: F

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

ANS: T

A value is stored in a variable with an assignment statement.

ANS: T

C++ does not have a built-in data type for storing strings of data.

ANS: T

Escape sequences are always stored internally as a single character.

ANS: T

Floating point constants are normally stored in memory as doubles.

ANS: T

In C++, key words are written in all lowercase letters.

ANS: T

Programming style refers to the way a programmer uses elements such as identifiers, spaces, and blank lines.

ANS: T

The preprocessor reads a program before it is compiled and only executes those lines beginning with # symbol.

ANS: T


Kaugnay na mga set ng pag-aaral

Chapter 32:Birth-Related Stressors

View Set

Agile Scrum Master Level 1 Certification Study Questions

View Set

Understanding Architecture Midterm

View Set

Psychology Exam 3 Practice Questions

View Set

Ch 2. Chemical Level of Organization - Dr. Deva Joseph

View Set

Testbank Questions: Programming for End Users

View Set

Chapter 15: Absolutism and Constitutionalism Study Guide

View Set

أسئلة الفصل الثالث - أكمل

View Set