Homework 2
Which of the following lines must be included in a program that has string variables?
#include <string>
The_____ causes the content of another file to be inserted into a program.
#include directive
What is the value of number after the following statements execute? int number; number = 18 % 4 + 2;
4
What is the value of number after the following statements execute? int number; number = 18 / 4;
4
What is the value stored in the variable myNum after the following assignment statement executes? myNum = 23 % 5
3
Which data type typically requires only one byte of storage?
char
Which of the following statements correctly defines a named constant named TAX_RATE that holds the value 0.075?
const double TAX_RATE = 0.075;
The ________ is(are) used to display information on the computer's screen.
cout object
Using C++11: What data type does the compiler determine for the variable cost in the following statement? auto cost = 14.95;
double
Which of the following defines a double-precision floating-point variable named payCheck?
double payCheck
The data type used to declare variables that can hold real numbers
float
The numeric data types in C++ can be broken into two general categories which are:
integers and floating-point numbers
The float data type is considered ________ precision and the double data type is considered ________ precision.
single, double
Which of the following must be included in any program that uses the cout object?
the header file iostream
Which part of the following line is ignored by the compiler? double userName = "janedoe"; // user's name is janedoe
user's name is janedoe
You must have a ________ for every variable you intend to use in a program.
variable definition
Which of the following is NOT a valid C++ identifier? _1user employee_number April2018 theLittleBrownFoxWhoRanAway 1user
1 user
What is output of the following statement? cout << 4 * (15 / (1 + 3)) << endl;
12
What is the value of cookies after the following statements execute? int number = 38, children = 4, cookies;cookies = number % children;
2
In C++ you are required to name your variables so they indicate the purpose they will be used for. True False
False
In programming, the terms "line" and "statement" always mean the same thing. TRUE OR FALSE
False
What will the following code display? cout << "Four\n" << "score\n"; cout << "and" << "\nseven"; cout << "\nyears" << " ago" << endl;
Four score and seven years ago
What will the following code display? cout << "Monday"; cout << "Tuesday"; cout << "Wednesday";
Monday Tuesday Wednesday
What will the following code display? cout << "Roses " << "are red"; cout << "and " << "violets/n" cout << "are" << "blue" << endl;
Roses are redand violets/nareblue
What will the following code display? int number = 23; cout << "The number is " << "number" << endl;
The number is number
In C++, key words are written in all lowercase letters. TRUE OR FALSE
True
Programming style refers to the way a programmer uses elements such as identifiers, spaces, and blank lines. True False
True
The preprocessor executes after the compiler. True False
True
When typing in your source code into the computer, you must be very careful since most of your C++ instructions, header files, and variable names are case sensitive. TRUE OR FALSE
True
What will be the output after the following lines of code execute? bool choice; choice = true;cout << "Your choice is " << choice << endl;
Your choice is 1
The data type of a variable whose value can be either true or false is
bool
Which of the following statements correctly assigns the character M to the variable named letter?
letter = 'M';