Exam 1 COMSC study guide

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

Preprocessor directives begin with a

#

A conditionally executed statement should be indented one level from the if statement. T/F

True

A left brace in a C++ program should always be followed by a right brace later in the program. T/F

True

A variable must be defined before it can be used. T/F

True

All lines in a block should be indented one level. T/F

True

The scope of a variable is limited to the block in which it is defined. T/F

True

When C++ is working with an operator, it strives to convert the operands to the same type. T/F

True

When an if statement is nested in the if part of another statement, the only time the inner if is executed is when the expression of the outer if is true. T/F

True

You can use the relational operators to compare string objects. T/F

True

You cannot initialize a named constant that is declared with the const modifier. T/F

True

Assume a program has the following variable definitions: int a, b = 2; float c = 4.2; and the following statement: a = b * c; What value will be stored in a?

8

The ______ operator always follows the cin object.

>>

A variable defined in an inner block may not have the same name as a variable defined in the outer block. T/F

False

It's safe to assume that all uninitialized variables automatically start with 0 as their value. T/F

False

The = operator and the == operator perform the same operation when used in a Boolean expression. T/F

False

Variable names may begin with a number. T/F

False

When a program uses the setw manipulator, the iosetwidth header file must be included in a preprocessor directive. T/F

False

When an if statement is nested in the else part of another statement, as in an if/else if , the only time the inner if is executed is when the expression of the outer if is true. T/F

False

y < x is the same as x >= y. T/F

False

The _________ causes a program to wait until information is typed at the keyboard and the Enter key is pressed.

cin object

Rewrite the following variable definition so the variable is a named constant. int rate;

const int RATE = 5;

Write a cout statement so the variable divSales is displayed in a field of 8 spaces, in fixed point notation, with a precision of 2 decimal places. The decimal point should always be displayed.

cout << fixed << showpoint << setprecision(2) << setw(8) << divSales;

Convert the following pseudocode to C++ code: Ask the user for a number. Store the response in a variable named x. If the number is less than 0,Tell the user "No negative numbers allowed."Otherwise,Tell the user "Number accepted."

double d; cout << "Enter a number: "; cin >> d; if(d < 0) cout << "No negative numbers allowed."; else cout << "Number accepted.";

Ask the user to enter a number. Then, display the number back to the user using fixed point notation and 5 decimal places of precision.

double num; cout << "Enter an number: "; cin >> num; cout << setprecision(5) << fixed; cout << "You entered: " << num;

Every C++ program must have a

function main

Write a code snippet that asks the user for an integer and then tells the user whether the number they entered was even or odd.

int x; cout << "Enter an integer: "; cin >> x; if(x % 2 == 0) cout << "The number is even."; else cout << "The number is odd.";

In any program that uses the cin object, you must include the ___________.

iostream header file

The following data: 72 'A' "Hello World" 2.8712 are all examples of

literals or constants

An ____________ is like a variable, but its value is read-only and cannot be changed during the program's execution

named constant

Every complete statement ends with a

semicolon

The negation operator is

unary

Assume a program has the following variable definitions: int units; float mass; double weight; and the following statement: weight = mass * units; Which automatic data type conversion will take place?

units is promoted to a float, mass remains a float, and the result of mass * units is a double.

Assume that qty and salesReps are both integers. Use a type cast expression to rewrite the following statement so it will no longer perform integer division. unitsEach = qty / salesReps;

unitsEach = static_cast< double>(qty) / salesReps;


Ensembles d'études connexes

The synthesis and degradation of nucleotides

View Set

Chapter 9 Life Policy Provisions

View Set

Consumer Ed, Chapter 12, Savings

View Set

ADN 106 exam 3: topic: Allergic disorders

View Set

AEST AA - Standard 6 - Animal terminology

View Set