Computer Programming Ch1 - Ch4

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

In the C++ instruction, cookies = number % children; given the following declaration statement: int number = 38, children = 4, cookies; what is the value of cookies after the execution of the statement?

2

What will the value of result be after the following statement executes? result = 6 - 3 * 2 + 7 - 10 / 2 ;

2

in programming terms, a group of characters inside a set of quotation marks is called a :

string literal.

This statement lets the value of a variable or expression determine where the program will branch to.

switch

If the sub-expression on the left side of an && operator is false, the expression on the right side will not be checked. (T/F)

true

If the sub-expression on the left side of the || operator is true, the expression on the right side will not be checked. (T/F)

true

What is the value of the following expression? false || true

true

What is the value of the following expression? true && true

true

What is the value of the following expression? true || true

true

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

true

You should be careful when using the equality operator to compare floating point values because of potential round-off errors. (T/F)

true

programmer defined names of memory locations that may hold data are

variables

Which of the following expressions will determine whether x is less than or equal to y?

x <= y

When a relational expression is false, it has the value _____

zero

This operator is known as the logical OR operator

||

The _____ causes the contents of another file to be inserted into a program

#include directive

What is the modulus operator?

%

Character constants in C++ are always enclosed in ______

'single quotation marks'

Which one of the following would be an illegal variable name? A) dayOfWeek B) 3dGraph C) _employee_num D) June1997 E) itemsorderedforthemonth

B) 3dGraph

Which of the following defines a double-precision floating point variable named payCheck? A) float payCheck; B) double payCheck; C) payCheck double; D) Double payCheck;

B) double payCheck;

The fixed manipulator causes a number to be displayed in scientific notation. (T/F)

False

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

False

Associativity is either right to left or

Left to right

What will the following code display? cout << "Monday"; cout << "Tuesday"; cout << "Wednesday";

MondayTuesdayWednesday

This is used to mark the end of a complete C++ programming statement.

Semicolon

This is a set of rules that must be followed when constructing a program.

Syntax

Internally, the CPU consists of two parts:

The Control Unit and the Arithmetic and Logic Unit

If you place a semicolon after the statement if (x < y)

The compiler will interpret the semicolon as a null statement.

The name for a memory location that may hold data is:

Variable

a set of well defined steps for performing a task or solving a problem is known as

algorithm

Input values should always be checked for A) Appropriate range B) Reasonableness C) Division by zero, if division is taking place D) All of these E) None of these

all of these

In C++ the = operator indicates

assignment

The ______ is/are used to display information on the computer's screen

cout object

To use the rand() function, you must #include this header file in your program.

cstdlib

If you intend to place a block of statements within an if statement, you must place these around the block.

curly braces { }

You must have a ___________ for every variable you intend to use in a program

definition

The default section is required in a switch statement (T/F)

false

What is the value of the following expression? true && false

false

Whereas < is called a relational operator, x < y is called a(n)________________

relational expression

The ________ of a variable is limited to the block in which it is declared.

scope

The default section of a switch statement performs a similar task as the _______ portion of an if/else if statement.

trailing else

What will the value of x be after the following statements execute int x; x = 18 / 4;

4

This operator is used in C++ to represent equality

==

If you use a C++ key word as an identifier, your program will:

not compile

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

true

This operator performs a logical NOT operation.

!

This operator takes an operand and reverses its truth or falsehood.

!

Which of the following is a preprocessor directive?

#include <iostream>

This operator represents the logical AND.

&&

You can use these to override the rules of operator precedence in a mathematical expression

(Parentheses)

When this operator is used with string operands it concatenates them, or joins them together

+

At the heart of a computer is its central processing unit. The CPU's job is:

fetch, carry , produce ( To fetch instructions & To carry out the operations commanded by the instructions & To produce some outcome or resultant information )

This is a variable, usually a boolean or an integer, that signals when a condition exists.

flag

This manipulator causes the field to be left-justified with padding spaces printed to the right.

left

These are data items whose values do not change while the program is running

literals

These operators connect two or more relational expressions into one, or reverse the logic of an expression.

logical

When an if statement is placed within the conditionally-executed code of another if statement, this is known as:

nesting

A character literal is enclosed in ________ quotation marks, whereas a string literal is enclosed in ________ quotation marks

single , double

An expression that has any value other than 0 is considered true by an if statement. (T/F)

true

As a rule of style, when writing an if statement you should indent the conditionally-executed statements. (T/F)

true

Both of the following if statements perform the same operation. if (sales > 10000) commissionRate = 0.15; if (sales > 10000) commissionRate = 0.15; (T/F)

true

Assume that x is an int variable. What value is assigned to x after the following assignment statement is executed? x = -3 + 4 % 6 / 5;

-3

What is assigned to the variable a given the statement below with the following assumptions: x = 10, y = 7, and z, a, and b are all int variables. a = x >= y;

1

a variable whose value can be either true or false is of this data type

bool

Without this statement appearing in a switch construct, the program "falls through" all of the statements below the one with the matching case expression.

break

When using the sqrt function you must include this header file.

cmath

When converting some algebraic expressions to C++, you may need to insert ___________ that do not appear in the algebraic expression.

Parentheses

This is used in a program to mark the beginning or ending of a statement, or separate items in a list.

Punctuation

Relational operators allow you to ____________ numbers

compare

A statement that starts with a # is called a:

Preprocessor directive

These are used to declare variables that can hold real numbers

floating point data types

Every complete C++ program must have a _____________.

function named main

___________reads a line of input, including leading and embedded spaces, and stores it in a string object.

getline

Which statement will read an entire line of input into the following string object? string address;

getline(cin, address);

Which statement allows you to properly check the char variable code to determine whether it is equal to a "C" and then output "This is a check" and then advance to a new line? A) if code is equal to C cout << "This is a check\n"; B) if (code = "C") cout << "This is a check" << endl; C) if (code == 'C') cout << "This is a check\n"; D) if (code == C) cout << "This is a check" << endl;

if (code == 'C') cout << "This is a check\n";

When a program lets the user know that an invalid choice has been made, this is known as:

input validation

What will the following code display? int x = 0, y = 1, z = 2; cout << x << y << z << endl;

012

The statement cin >> setw(10) >> str; will read up to this many characters into str

10

What is the output of the following statement? cout << 4 * (15 / (1 + 3)) << endl;

12

What will the value of x be after the following statements execute? int x = 0; int y = 5; int z = 4; x = y + z * 2;

13

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 } Which line(s) in this program cause output to be displayed on the screen?

14

What will the value of x be after the following statements execute? int x; x = 18 % 4;

2

What will the value of x be after the following statements execute? int x; x = 18.0 / 4;

4

Assuming you are using a system with 1-byte characters, how many bytes of memory will the following string literal occupy? "William"

8

The ______ operator always follows the cin object, and the ______ operator follows the cout object

>> , <<

Which of the following best describes an operator?

An operator allows you to perform operations on one or more pieces of data

The programming process consists of several steps, which include:

Design, Creation, Testing, and Debugging

This term refers to the programmer reading the program from the beginning and steping through each statement.

Desk Checking

What will the following code display? cout << "Four " << "score "; cout << "and " << "seven/n"; cout << "years" << "ago" << endl;

Four score and seven/nyearsago

What will the following code display? cout << "Four" << "score" << endl; cout << "and" << "seven" << endl; cout << "years" << "ago" << endl;

Fourscore andseven yearsago

Unix and Windows 2000 are examples of _______________ operating systems

Multitasking

In memory, C++ automatically places a ___________ at the end of string literals.

Null terminator

A(n) ____________ is a set of instructions that the computer follows to solve a problem.

Program

This is a volatile type of memory, used for temporary storage.

RAM

the computers main memory is commonly known as:

RAM

Even when there is no power to the computer, data can be held ine

Secondary storage

The statements written by the programmer are called:

Source code

In the process of translating a source file into an executable file, which of the following is the correct sequence?

Source code, preprocessor, modified source code, compiler, object code, linker, executable code.

In a C++ program, two slash marks ( // ) indicate:

The beginning of a comment

When the final value of an expression is assigned to a variable, it will be converted to:

The data type of the variable

____________ must be included in any program that uses the cout object.

The header file iostream

What will the following code display? int number = 7; cout << "The number is " << "number" << endl;

The number is number

What does the term hardware refer to?

The physical components that a computer is made of

A variable declaration announces the name of a variable that will be used in a program, as well as:

The type of data it will be used to hold

The only difference between the get function and the >> operator is that get reads the first character typed, even if it is a space, tab, or the [Enter] key. (T/F)

True

When the fixed manipulator is used, the value specified by the setprecision manipulator will be the number of digits to appear after the decimal point. (T/F)

True

Which character signifies the beginning of an escape sequence?

\

An example of a secondary storage device is:

a hard disk

on the following, which is a valid C++ identifier A) June1997 B) _employee_number C) ___department D) myExtraLongVariableName E) All of these are valid identifiers.

all of these are valid

which data type typically requires only one byte of storage

char

You want the user to enter the length, width, and height from the keyboard. Which cin statement is correctly written?

cin >> length >> width >> height;

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

cin object

This statement will pause the screen, until the [Enter] key is pressed

cin.get();

During which stage does the central processing unit analyze the instruction and encode it in the form of a number, and then generate an electronic signal?

decode

Machine language is an example of a high level language (T/F)

false

the preprocessor executes after the compiler (T/F)

false

This stream manipulator forces cout to print the digits in fixed-point notation.

fixed

How would you consolidate the following declaration statements into one statement? int x = 7; int y = 16; int z = 28;

int x = 7, y = 16, z = 28;

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

iostream header file

Assume that a program has the following variable definition: char letter; Which of the following statements correctly assigns the character Z to the variable?

letter = 'Z';

This manipulator is used to establish a field width for the value immediately following it.

setw

the function in C++ allows you to identify how many bytes of storage on your computer system an integer data value requires

sizeof

Computer programs are also known a

software

The first step in using the string class is to #include the ___________ header file.

string

software engineering is a field that encompasses designing ,writing , testing , debugging , documenting , modifying , and maintaining computer programs (T/F)

true

Which statement is equivalent to the following? x = x * 2;

x *= 2;

An Integrated Development Environment typically consists of:

A text editor ,A compiler , and A debugger

What statement best describes a variable and its primary purpose?

A variable is a named storage location in the computer's memory used for holding a piece of information.

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

Arithmetic operators that share the same precedence have right to left associativity (T/F)

False

Besides decimal, two other number systems you might encounter in C++ programs are:

Hexadecimal and Octal

The purpose of a memory address is:

To identify the location of a byte in memory

This function tells the cin object to skip one or more characters in the keyboard buffer.

cin.ignore

For every opening brace in a C++ program, there must be a:

closing brace

The function, pow(x, 5.0), requires this header file

cmath

_______________ are used to translate each source code instruction into the appropriate machine language instruction

compilers

This step will uncover any syntax errors in your program

compiling

The ________ decodes an instruction and generates electrical signals

control unit

Mistakes that cause a running program to produce incorrect results are called:

logic errors

Assume that a program has the following string object definition: string name; Which of the following statements correctly assigns a string literal to the string object?

name = "Jane";

Which statement is equivalent to the following? number += 1;

number= number+ 1

Characters or symbols that perform operations on one or more operands are

operators

When a variable is assigned a number that is too large for its data type, it:

overflows

If you want to know the length of the string that is stored in a string object, you can call the object's size member function. (T/F)

true


Ensembles d'études connexes

Organizational Behavior - Chapter 7 : Positive Organizational Behavior- Quiz 4

View Set

MLT130 CC Osmolality & Electrolytes & Trace Elements

View Set

mgmt 340: Content is King quiz ~fInAl~

View Set

Chapter 8 positive/routine messages

View Set

Lesson 8-G: Musculoskeletal System

View Set

RN Nursing Care of Children 2016 Bgood

View Set

Chapter 14: Business Forms/ Arrangements

View Set

anatomy-Peripheral and central nervous system

View Set