Computer Programming 1

¡Supera tus tareas y exámenes ahora con Quizwiz!

A(n) ________ is information that is passed to a function, and a(n) ________ is information that is received by a function.

argument, parameter

The following statement: int *ptr = new int;

assigns an address to the variable named ptr

The statements in the body of a while loop may never be executed, whereas the statements in the body of a do-while loop will be executed:

at least once

In C++ 11, the ________ tells the compiler to determine the variable's data type from the initialization value.

auto key word

This is a variable that is regularly incremented or decremented each time a loop iterates.

counter

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

cout object

Use the delete operator only on pointers that were ________.

created with the new operator

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

cstdlib

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

not compile

A function ________ eliminates the need to place a function definition before all calls to the function.

prototype

This vector function is used to insert an item into a vector.

push_back

The range-based for loop, in C++ 11, is designed to work with a built-in variable known as the ________.

range variable

When used as parameters, these types of variables allow a function to access the parameter's original argument.

reference

This statement causes a function to end.

return

A two-dimensional array can be viewed as ________ and ________.

rows, columns

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

scope

Given the following declaration, where is the value 77 stored in the scores array? int scores[] = {83, 62, 77, 97};

scores[2]

A ________ algorithm is a method of locating a specific item of information in a larger collection of data.

search

To read data from a file, you define an object of this data type.

ifstream

Something within a while loop must eventually cause the condition to become false, or a(n) ________ results.

infinite loop

In a for statement, this expression is executed only once.

initialization

A(n) ________ can be used to specify the starting values of an array.

initialization list

Arrays may be ________ at the time they are ________.

initialized, declared

Look at the following function prototype. int myFunction(double);

int

The statement: int *ptr = nullptr; has the same meaning as ________.

int* ptr = nullptr;

The numeric data types in C++ can be broken into two general categories:

integer and floating point

With an enumerated data type, the enumerators are stored in memory as ________.

intergers

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

iostream header file

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

left

It is ________ to pass an argument to a function that contains an individual array element, such as numbers[3].

legal in C++

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

The ________ is adequate for searching through small arrays.

linear search

This type of variable is defined inside a function and is not accessible outside the function.

local

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

logical

This is a control structure that causes a statement or group of statements to repeat.

loop

A function ________ return a structure.

may

The name of an array stores the ________ of the first array element.

memory address

Not all arithmetic operations may be performed on pointers. For example, you cannot ________ or ________ a pointer.

multiply, divide

To pass an array as an argument to a function, pass the ________ of the array.

name

Assume that a program has the following string object definition:

name = "Jane";

The ________ sort usually performs fewer exchanges than the ________ sort

section, buuble

This is required after the closing brace of the structure declaration.

semicolon

This is a special value that marks the end of a list of values.

sentinel

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

setw

The total number of digits that appear before and after the decimal point is sometimes referred to as:

significant digits and precision

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

single, double

The float data type is considered ________ precision, and the double data type is considered ________ precision.

single, double

This vector function returns the number of elements in a vector.

size

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

sizeof

The value in a ________ variable persists between function calls.

static local

The following statement: cin >> *num3;

stores the keyboard input into the variable pointed to by num3

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

string

An array of string objects that will hold 5 names would be declared using which statement?

string names[5];

In C++ 11 you can use a new type of enum, known as a(n) ________, (also known as an enum class) to have multiple enumerators with the same name, within the same scope.

strongly typed enum

You may use a pointer to a structure as a ________.

structurefunction parameter structure member function return type

This is a dummy function that is called instead of the actual function it represents.

stub

By using the same ________ you can build relationships between data stored in two or more arrays.

subscript

To access an array element, use the array name and the element's ________.

subscript

If Circle is a structure tag, the statement: Circle doSomething(Circle c2) can be the header line for a function that ________

takes a Circle structure as a parameter, does something, and returns a Circle structure

When the less than ( < ) operator is used between two pointer variables, the expression is testing whether ________.

the address of the first variable comes before the address of the second variable in the computer's memory

An element of a two-dimensional array is referred to by ________ followed by ________.

the row subscript of the element, the column subscript of the element

An array can store a group of values, but the values must be:

the same data type

To dereference a structure pointer, the appropriate operator is ________.

the structure pointer operator, ->

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

trailing else

This is like a structure, except all members occupy the same memory area.

union

A for statement contains three expressions: initialization, test, and

update

You may define a ________ in the initialization expression of a for loop.

variable

Which statement correctly uses C++ 11 to initialize a vector of ints named n with the values 10 and 20?

vector<int> n { 10, 20 };

Which statement correctly defines a vector object for holding integers?

vector<int> v;

If you leave out the size declarator in an array definition:

you must furnish an initialization list

When a relational expression is false, it has the value ________.

zero

This operator is known as the logical OR operator.

||

The ________ operator always follows the cin object, and the ________ operator follows the cout object.

>>, <<

Which of the following statements about global variables is true?

A global variable can have the same name as a variable that is declared locally within a function.

An Integrated Development Environment typically consists of:

A text editor A compiler A debugger

Data types that are created by the programmer are known as ________.

Abstract Data Types (ADT)

A set of well-defined steps for performing a task or solving a problem is known as a(n):

Algorithm

Which of the following statements is not valid C++ code?

All of these are invalid.

What will be the output of the following code segment after the user enters 0 at the keyboard? int x = -1; cout << "Enter a 0 or a 1 from the keyboard: "; cin >> x; if (x) cout << "true" << endl; else cout << "false" << endl;

False

With pointer variables you can access, but you cannot modify, data in other variables.

False

This is a variable, usually a bool or an int, that signals when a condition exists.

Flag

What will the following code display? cout << "Four\n" << "score\n"; cout << "and" << "\nseven"; cout << "\nyears" << " ago" << endl;

Four score and seven years ago

The programming process consists of several steps, which include:

Design, Creation, Testing, and Debugging

A linear search can only be implemented with integer values.

False

A union can only have one member

False

Look at the following declaration. enum Tree { OAK, MAPLE, PINE }; What is the value of the following relational expression? OAK > PINE

False

The ampersand (&) is used to dereference a pointer variable in C++.

False

True/False: 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.

False

True/False: The fixed manipulator causes a number to be displayed in scientific notation.

False

True/False: When a program uses the setw manipulator, the iosetwidth header file must be included in a preprocessor directive.

False

Three primary activities of a program are:

Input, Processing, and Output

What does the following statement do? vector<int> v(10, 2);

It creates a vector object with a starting size of 10 and all elements are initialized with the value 2.

Words that have a special meaning and may be used only for their intended purpose are known as:

Key Words

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.

LL

Associativity is either right to left or:

Left to right

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

Logic errors

In a broad sense, the two primary categories of programming languages are:

Low-level and High-level

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

MondayTuesdayWednesday

Regardless of the algorithm being used, a search through an array is always performed _____________.

None of these

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

Null Terminator

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

Operators

In programming terms, a group of characters inside a set of quotation marks is called a(n):

String literal

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

Switch

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

Syntax

The name of the structure is referred to as its ________.

Tag

Internally, the CPU consists of two parts:

The Control Unit and the Arithmetic and Logic Unit

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 iosteam

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

The number is number

The number of comparisons made by a binary search is expressed in powers of two.

True

True/False: When C++ is working with an operator, it strives to convert the operands to the same type.

True

True/False: 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.

True

What is the value of the following expression?

True

When you use a strongly typed enumerator in C++ 11, you must prefix the enumerator with the name of the enum, followed by the :: operator.

True

You cannot directly assign an integer value to an enum variable.

True They must be initialized first.

________ functions may have the same name, as long as their parameter lists are different.

Two or more

Programmer-defined names of memory locations that may hold data are:

Variables

________ represent storage locations in the computer's memory.

Variables

What will the following segment of code output? Assume the user enters a grade of 90 from the keyboard. cout << "Enter a test score: "; cin >> test_score; if (test_score < 60); cout << "You failed the test!" << endl; if (test_score > 60) cout << "You passed the test!" << endl; else cout << "You need to study for the next test!" << endl;

You failed the test! You passed the test!

Which character signifies the beginning of an escape sequence?

\

Which escape sequence causes the cursor to move to the beginning of the current line?

\r

This control sequence is used to skip over to the next horizontal tab stop.

\t

To assign the contents of one array to another, you must use ________.

a loop to assign the elements of one array to the other array

Look at the following structure declaration. struct Employee { string name; int idNum; }; idNum in this declaration is:

a member

A pointer variable is designed to store ________.

a memory address

A loop that is inside another loop is called:

a nested loop

The while loop has two important parts: an expression that is tested for a true or false value, and:

a statement or block that is repeated as long as the expression is true

A pointer variable may be initialized with ________.

a valid address in the computer's memory

This describes only the general characteristics of an object.

abstraction

Every byte in the computer's memory is assigned a unique ________.

address

When writing functions that accept multi-dimensional arrays as arguments, ________ must be explicitly stated in the parameter list.

all but the first dimension

The ________, also known as the address operator, returns the memory address of a variable.

ampersand ( & )

When this is placed in front of a variable name, it returns the address of that variable.

ampersand ( & )

This operator is used in C++ to represent equality.

==

A function is executed when it is:

called

A structure ________ contain members of the same data type.

can

Which data type typically requires only one byte of storage?

char

This operator performs a logical NOT operation.

!

Which of the following is a preprocessor directive?

#include <iostream>

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

#include Directive

What is the modulus operator?

%

This operator represents the logical AND.

&&

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

(Paratheses)

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

+

These are operators that add and subtract one from their operands.

++ & --

What is the value of donuts after the following code executes? int donuts = 10; if (donuts = 1) donuts = 0; else donuts += 2;

0

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

012

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

What is the value of donuts after the following code executes? int donuts = 10; if (donuts != 10) donuts = 0; else donuts += 2;

12

What is the output of the following segment of code if the value 4 is input by the user when asked to enter a number? int num; int total = 0; cout << "Enter a number from 1 to 10: "; cin >> num; switch(num) { case 1: case 2: total = 5; case 3: total = 10; case 4: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout << total << endl;

13

Look at the following program and answer the question that follows it. 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 }

14

What is the value of cookies after the execution of the following statements? int number = 38, children = 4, cookies; cookies = number % children;

2

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

2

What is the output of the following program? #include <iostream> using namespace std; void doSomething(int &); int main() { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int &num) { num = 0; cout << num << endl; }

2 0 0

How many times will the following loop display "Hello"? for (int i = 0; i < 20; i++) cout << "Hello!" << endl;

20

Using a linear search to find a value that is stored in the last element of an array of 20,000 elements, ________ element(s) must be compared.

20,000

What will the following code output? int number = 22; int *var = &number; cout << *var << endl;

22

Given the following code segment, what is output after "result = "? int x = 1, y = 1, z = 1; y = y + z; x = x + y; cout << "result = " << (x < y ? y : x) << endl;

3

Look at the following function prototype. int myFunction(double, double, double); How many parameter variables does this function have?

3

Assuming x is 5, y is 6, and z is 8, which of the following is false? 1. x == 5; 2. 7 <= (x + 2); 3. z <= 4; 4. (1 + x) != y; 5. z >= 8; 6. x >= 0; 7. x <= (y * 2);

3 and 4

Which one of the following would be an illegal variable name? dayOfWeek 3dGraph _employee_num June1997 itemsorderedforthemonth

3dGraph

What will the following code output? int *numbers = new int[5]; for (int i = 0; i <= 4; i++) *(numbers + i) = i; cout << numbers[2] << endl;

4

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

4

What will the following code display? int number = 6; cout << number++ << endl;

6

What is the output of the following program? #include <iostream> using namespace std; int getValue(int); int main() { int x = 2; cout << getValue(x) << endl; return 0; } int getValue(int num) { return num + 5: }

7

What will the following code display? int number = 6; number++; cout << number << endl;

7

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

8

Look at the following statement. while (x++ < 10) Which operator is used first?

<

Which of the following best describes an operator?

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

________ can be used as pointers.

Array Names

In C++ the = operator indicates:

Assignment

What will the following segment of code output if the value 11 is entered at the keyboard? int number; cout << "Enter number: "; cin >> number; if (number > 0) cout << "C++"; else cout << "Soccer"; cout << " is "; cout << "fun" << endl;

C++ is fun

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

Closing brace

Relational operators allow you to ________ numbers.

Compare

This step will uncover any syntax errors in your program.

Compiling

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

Correct Compilers

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

Curly braces { }

These types of arguments are passed to parameters automatically if no argument is provided in the function call.

Default

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

Definition

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

Paratheses

A statement that starts with a # symbol is called a:

Preprocessor directive

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

Program

The computer's main memory is commonly known as:

RAM

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

RAM

A variable's ________ is the part of the program that has access to the variable.

Scope

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

Semicolon

The statements written by the programmer are called:

Source Code

This is a complete instruction that causes the computer to perform some action.

Statement

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

Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr;

The value stored in the variable whose address is contained in ptr.

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

To fetch instructions To carry out the operations commanded by the instructions To produce some outcome or resultant information

The purpose of a memory address is:

To identify the location of a byte in memory

A struct can contain members with varying data types.

True

An array name is a pointer constant because the address stored in it cannot be changed during runtime.

True

Subscript numbering in C++________.

begins with zero.

A(n) ________ search is more efficient than a ________ search.

binary, linear

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

bool

This statement causes a loop to terminate early.

break

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

A file ________ is a small holding section of memory that file-bound information is first written to.

buffer

When a structure is passed ________ to a function, its members are not copied.

by reference

Functions are ideal for use in menu-driven programs. When a user selects a menu item, the program can ________ the appropriate function.

call

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();

Assuming dataFile is a file stream object, the statement: dataFile.close();

closes a file

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

cmath

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

cmath

Here is the header for a function named computeValue: void computeValue(int value) Which of the following is a valid call to the function?

computeValue(10);

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

con.ignore

This statement may be used to stop a loop's current iteration and begin the next one.

continue

In a function header, you must furnish:

data type(s) of the parameters data type of the return value the name of function names of parameter variables

If Circle is a structure, the statement: Circle *pcirc = nullptr;

declares a structure pointer called pcirc initialized with a null pointer

A ________ argument is passed to a parameter when the actual argument is left out of the function call.

default

A function ________ contains the statements that make up the function.

definition

It is a good programming practice to ________ your functions by writing comments that describe what they do.

document

Which of the following defines a double-precision floating point variable named payCheck?

double payCheck;

The individual values contained in array are known as ________.

elements

This function causes a program to terminate, regardless of which function or control mechanism is executing

exit()

Before you can perform a bubble sort, the data must be stored in descending order.

false

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

false

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

fixed

A(n) ________ is a diagram that shows the logical flow of a program.

flowchart

If you want a user to enter exactly 20 values, which loop would be the best to use?

for

This loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop.

for

An array can easily be stepped through by using a ________.

for loop

Data that is sorted in ascending order is ordered ________.

from lowest to highest value

To allow file access in a program, you must #include this header file.

fstream

This is a collection of statements that performs a specific task.

function

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

A ________ variable is declared outside all functions.

global

In C++ 11, the ________ key word was introduced to represent the address 0.

nullptr

A file must be ________ before data can be written to or read from it.

opened

Assuming outFile is a file stream object and number is a variable, which statement writes the contents of number to the file associated with outFile?

outFile << number;

This may be used to write information to a file.

output object

To write data to a file, you define an object of this data type.

outputfile

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

overflows

If a function is called more than once in a program, the values stored in the function's local variables do not ________ between function calls.

persist

This vector function removes an item from a vector.

pop_back

The do-while loop is a(n) ________ loop that is ideal in situations where you always want the loop to iterate at least once.

post-tes

The while loop is this type of loop.

pre-test

When the increment operator precedes its operand, as in ++num1, the expression is in this mode.

prefix

This operator increments the value of its operand, then uses the value in context.

prefix increment


Conjuntos de estudio relacionados

World Geography Pre-A.P. Common Formative Assessment #4

View Set

Chapter 11: Physical & Chemical Control of Microbes

View Set

Components of the Computer Study Guide

View Set

IS-700.B: An Introduction to the National Incident Management System

View Set