Combo with "Chapter 7: Starting out with C++ Definitions" and 26 others

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

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

+

{ }

-Opening and closing braces -Encloses a group of statements, such as the contents of a function.

" "

-Opening and closing quotation marks -Encloses a string of characters, such as a message that is to be printed on the screen.

If you add a value to a vector that is already full, the vector will automatically increase its size to accommodate the new value.

...

Its best to think of two-dimensional arrays as having rows and columns.

...

7.5 When using the increment and decrement operators, be careful not to...

... confuse the subscript with the array element. amount[count --]; // decrements the variable count but does nothing to the value in amount. p. 394

7.5 Individual array elements are processed...

... like any other variable. p. 394

7.2 Inputting data into an array must normally be done ...

... one element at a time. cin >> hours; // will not input data to the hours array You must use multiple cin statements to read data into each array element or use a loop to step through the array, reading data into its elements. p. 384

7.2 Outputting an arrays elements must be done...

... one element at a time. cout << hours; // will not work p. 384

7.3 C++ does not prevent you from...

... overwriting an arrays bounds. C++ does not provide many of the common safeguards to prevent unsafe memory access found in other languages. p. 386

7.4 If an array is partially initialized, the uninitialized elements will be...

... set to zero. The uninitialized elements of a string array will contain an empty string. This is true even if the string is defined locally. p. 393

To determine the number of elements in a vector, use the ___ member function.

.size()

What will the following loop display? int x = 0; while (x < 5) { cout << x << endl; x++; }

0 1 2 3 4

What will the following program display? #include <iostream> using namespace std; int main() { int a = 0, b = 2, x = 4, y = 0; cout << (a == b) << " "; cout << (a != b) << " "; cout << (b <=x) << " "; cout << (y > a) << endl; return 0; }

0 1 1 0

Given that x = 2, y = 1, and z = 0, what will the following cout statement display? cout << "answer = " << (x || !y && z) << endl;

1

Write the code to use function swap(a,b) using pass by value in c.

no

The _____ is automatically appended to a character array when it is initialized with a string constant.

null terminator

OOP

objet oriented programming

A function can have zero to many parameters, and it can return this many values.

only one

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

opened

false

operators must be friends of the class (T/F)

encapsulation

or data hiding; making fields in a class private and providing access through public methods

int x=1, y=2, z [10]; int *p, *q; p=&x; y=*p; *p=0; q=&z[0]; p=q;

p and q are pointers to an int p now points to x y is now 1 x is now 0 q now points to z [0] p now points to z[0]

Software patch

piece of code written on top of an existing piece of code intended to superficially fix a bug in the original code.

nesting

placing one control structure inside of another

Use the ________________ member function to remove the last element from a vector.

pop_back

use the ____ member functino to remove the last element from a vector.

pop_back

In C++, the array index begins at...

position 0

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

prefix increment

A loop that evaluates its test expression before each repetition is a(n) __________ loop.

pretest

Assume that pointer pp points to a "point" structure with members x and y. Print x and y.

printf("%d,%d\n", (*pp).x), (*pp).y);

Print maxpt's x and y

printf("%d,%d\n", maxpt.y, maxpt.x);

why is data hiding important

protects from outside corruption; hides details on how and object works;

To store a value in a vector that does not have a starting size, or that is already full, use the ________________ member function.

push_back

this function is used to insert an item into a vector

push_back

By default, arrays passed as parameters are ________ parameters

reference

Is an array passed to a function by value or by reference?

reference

A _________ is similar to a memory address. It is a value that identifies the object's ______ ______.

reference, memory location

stack

region of memory used for allocation of function data areas; variables on the stack occurs automatically when a block is entered, and deallocation occurs when the block is exited.

heap

region of memory used for data structures dynamically allocated and deallocated by operators new and delete.

::

Scope resolution symbol

fibonacci sequence

an = an-1 + an-2

Which line in the following program contains the prototype for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }

4

middle

A binary search begins with the _____ element of an array.

false

An array is always passed by value(true or false)

row number of element, column number of element

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

Sorting Algorithms

Are used to arrange data into some order. Scan through an array and rearrange its contents in some specific order.

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"

C) MondayTuesdayWednesday

A List object has a ______ property that holds the number of item stored in the List.

Count

Which of the following does counter-controlled repetition require?

Counter-controlled repetition requires all of the above.

End of File marker in Unix

Ctr + d

End of File marker in Windows

Ctrl + z

double *dbl_ptr;

Define a double pointer

call

Functions are ideal for menu-driven programs. When the user selects an item, the program can _____ the appropriate function.

function prototypes

Generally, a multi-file program consists of two types of files: ones that contain function definitions, and ones that contain _____?

Copying arrays

INCORRECT: int [] array2 = array1; CORRECT: int [] array1 = {...,}; int [] array2 = new int[5]; for (int i = 0; i < array1.length; i++) array2[i] = array1 [i];

!=

Not equal to

How to declare an array as a reference variable

Just use the name of the array. DO NOT include the & sign that would normally be used with regular reference parameters

Words that have special meaning in a programming language are called _____.

Keywords

What are the elements of a C++ program?

Keywords Programmer Defined Identifiers Operators Punctuation Syntax

<=

Less than or equal to

In a switch structure:

Multiple actions do not need to be enclosed in braces

Methods

Object code's Sub or Function procedures creates _______ for the object.

What do operators do?

Perform operations on one or more operands

What is a keyword also known as?

Reserved words

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

Secondary storage

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

Semicolon

while (i >= 10); ------cout << i << endl;

Semicolon after while condition. Nullifies the loop

The vector data type is a ____ container

Sequence

The two types of containers defined by the STL are _____ and ____

Sequence; associative

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

Single, Double

The_indicates the number of elements, or values, an array can hold

Size Declarator

Range-based for loop

Special type of for loop provided in C++11 to process the elements of an array.

A two-dimensional array is like several identical arrays put together.

T

An array's size declaratory can either be a literal, a named constant, or a variable.

T

Size declarator

The ___ indicates the number of elements, or values, an array can hold.

STL

The ___ is a collection of programmer-defined data types and algorithms that you may use in your programs.

exit()

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

selection, bubble

The _____ sort usually performs fewer exchanges than the _____ sort.

return

The _____ statement causes a function to end.

true

The module isStackfull is used if one uses an array implementation for the stack (true or false)

Subscript numbering in C++

begins with zero

What is a class?

blueprint for making objects; contains defintions of data and methods; can contain class and instance data and method types

The statement or block that is repeated is known as the __________ of the loop.

body

flag variable

bool variable that controls a while loop. The loop continues until this value becomes "false"

The __________ statement causes a loop to terminate immediately.

break

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

cstdlib

How to call a particular value in a matrix

call arrayName[row][column]

A function is executed when it is...

called

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

calls

Break statement

can be used in a switch or repetition structure and it provides immediate exit from that structure

Which of the following is correct when labeling cases in a switch structure?

case 1

return statement

causes method to end execution and retuns a value back to the statement that called the method

median

center value of a list with an odd number of values average of middle two values in a list with an even number of values.

7.1 Typical array sizes

char - 1 byte short - 2 bytes int - 4 bytes float - 4 bytes double 8 bytes p. 379

The __________ loop always iterates at least once.

do-while

This statement causes a function to end.

return

strVal.empty()

returns "true" if calling string is empty, false otherwise.

Malloc

returns a pointer to space for an object of size 'size' or NULL if the request cannot be satisfied. The space is uninitialized. void *malloc(size_t size);

strVal.c_str()

returns the equivalent c-string version of the string strVal.

The number inside the brackets of an array definition is the _________, but the number inside an array s brackets in an assignment statement, or any other statement that works with the contents of the array, is the _________.

size declarator, subscript

Get the size of array "arr"

sizeof(arr) or sizeof arr

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

This operator represents the logical AND

&&

T

(T/F) C++ allows you to partially initialize an array.

/ /

- Double slash. - Marks the beginning of a comment.

Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL; 7 MY_VAL = 77; 8 cout << MY_VAL << endl; 9 return 0; 10 }

6

Consider the following code, assuming that x is an int with an initial value of 12 if( x = 6 ) cout << x; What is the output?

6

What will the following code display? int number = 6; int x = 0; x = number--; cout << x << endl;

6

How many characters in the C-string "Hello"?

6. One for each letter, and then the terminating null character.

Code

A ______ object is an instance of user-defined type, called a class, which is defined similarly to a structure, but in a separate class block.

You cannot use the ___ operator to copy data from one array to another in a single statement.

Assignment(=)

When defining a parameter variable to hold a single-dimensional array argument, you do not have to include the size declarator.

F

Subscript numbers may be stored in variables.

F;value must be stored at the subscript.

T OR F: C++ limits the number of array dimensions to two.

FALSE

T OR F: The statement double money[25.00]; is a valid C++ array definition.

FALSE

Assume array1 and array2 are the names of arrays. To assign the contents of array2 to array1, you would use the following statement: array1 = array2;

False

True or False: A structure is passed by reference to a function.

False

Alist<float> ans;

One has declared a template class called Alist. Show how one would declare an object of Alist that is of type float.

data hiding

One of the strengths of using classes is ___.

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

Program

WriteAllLines

The __________ method is used to copy values from an array into a text file.

Extensible Markup Language

The acronym XML stands for what?

elements

The individual values contained in array are known as _____?

decision maker

The logical expression in a while loop. If it is true, the loop will execute.

Size declarator, Subscript

The number inside the brackets of an array definition is the ___, but the number inside an array's brackets in an assignment statement, or any other statement that works with the contents of the array, is the ___.

true

The number of comparisons made by a binary search is expressed in powers of two. true or false?

Source Code and Source File

The state-ments written by the programmer are called source code, and the file they are saved in is called the source file.

false

The statement float money[25.00]; is a valid C++ array declaration. true or false?

implicit array sizing

The statement int grades[] = { 100, 90, 99, 80 }; is an example of _____?

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

True

the memory location the pointer is pointing at returns to the heap, should be no longer available or dangling reference, one should set int_ptr to NULL

What happens when one uses the following command, and what step should follow the delete command?(3 pts) delete int_ptr;

What happens when an array name is passed to a function?

What is passed is the location of the first element; Then within the function the argument is a local variable; thus, an array name parameter is a pointer.

Column

When a two-dimensional array is passed to a function, the ___ size must be specified.

sink hole

When no route in adjacency matrix

in the same directory

When one is using an external file for input, make sure that the file is located___.

ShowDialog

Which form method will open a form as modal?

Are arrays always passed by reference?

Yes

Can array elements be used as function parameters?

Yes

What is a class "Instance"?

a reference object whos type is some class. There can be may instances of the class; each instance has its own data Ex: keyboard is an instance of the scanner class

index

a value indicating a location inside an array

false

a void function can be used in an assignment

Difference between a while and a do...while loop

a while loop tests the condition first, then executes. A do...while loop executes, then checks the condition to see if it should execute again.

counter-controlled while loop

a while loop that is used when you know how many items of data are to be read; the loop will continue until the condition designated by the counter is met or evaluates to false

Parallel arrays

arrays whose corresponding components hold related information. Example: Student ID's and corresponding student's grades.

In C++ the = operator indicates:

assignment

sum +=*ptr++ does what?

assigns the dereferenced pointer's value, then increments the pointer's address

syntax to initialize a two dimensional array during declaration

dataType arrayName[rows][columns] = {{row1},{row2},{row3},...}

Syntax for two-dimensional array

dataType arrayName[rows][columns];

"Class" data and methods

declared using static; sharked by all instances; accessed by class name (outsideclass)

To __________ a value means to decrease it by one.

decrement

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

document

Look at the following function prototype: int myFunction(double); What is the data type of the function's parameter variable?

double

false

double *Pt1, *Pt2; and double* Pt1, Pt2; produce the same variable types(true or false)

8

given the following code fragment what is the final value of y? int x,y; x=-1; y=0; while(x<3) { y+=2; x+=1; }

Arrays may be ___________ at the time they are __________.

initialized, declared

Arrays may be _____ at the time they are _____.

initialized; called

a binary search begins with the ___ elements of an array

middle

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

subscript

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

C) 0

true

Dynamic data can be deallocated during program execution, but static data remains unti the block in which it was declared is done executing (true or false)

Field

Each column of a database is referred to as a _______.

true

The amount of memory used by an array depends upon the array's data type and the numbers elements in the array. (True of False)

int array1[4], array2[4] = {3, 6, 9, 12}; array1 = array2;

The assignment operator cannot be used to assign the contents of one array to another, in a single statement

N/2

The average number of comparisons in a linear (sequential) search. The maximum number of comparisons (elements/items) is always N.

true

The base address of an array is associated with the name of the array(true or false)

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

The beginning of a comment

T OR F: 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

The amount of memory used by an array depends upon the array's data type and the number of elements in the array

True

True or False: A structure can be returned by value from a function.

True

True or False: The rules that must be followed when constructing a program are called syntax.

True

When you pass an array as an arugment to a function, the function can modify the contents of the array

True

You can set the size of a dynamically allocated array using a variables value

True

7.2 How do you write the contents of an array into a file?

Use a loop to step through each element of the array, writing its contents to a file. p. 385

pop_back()

Use the ___ member function to remove the last element from a vector.

Everytime we create an instance of "struct student_details" we need to type "struct Studetn_details Josh= new struct student_details. How can we make this shorter?

Use typedef to create a shorter name for that type. eg: typedef structu student_details studentDet; now we can create Josh by studentDet Josh = new studentDet

Linear Search/Sequential Search

Uses a loop to sequentially step through an array, starting with the first element. It compares each element with the value being searched for, and stops when either the value is found or the end of the array is encountered.

19,999

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.

Contains

We say class A _______ class B when a member of class A makes use of an object of type class B.

dangling reference

We talked about two types of problems that deal with pointers. One type is garbage and the other type is ___.

AB- CD+/ E*F/G+, +/*/-AB+CDEFG

What are the postfix and prefix of the following? (A - B) / (C+D) * E/F+G (4 pts) POSTFIX -> PREFIX - >

O(N^3)

What is the order of the following code? Do not solve it. (1 pt) double product = 1.0; for (int i = 0; i < n; i++) for (int k = 0; k < n; k++) for (int m = 0; m < n; m++) product = product * i * k * m

true

When a variable is defined as a class object, that object has all the attributes and functions associated with it just by giving the object name. (true or false)

true

When an array is passed to a function, the function has access to the original array.(true or false)

constructor

When creating a stack class, instead of using Createstack, or use a ___ function

class.h, .h, class.cpp, main.cpp

When dealing with nontemplate classes, in which file would the following be located? 1. Inline functions 2. endif 3. :: 4. rectangle object1;

Braces

When initializing a two-dimensional array, it helps to enclose each row's initialization list in ___.

The one place where C++ allows aggregate operations

When inputting or outputting c-strings

When are loops used?

When it is necessary to repeat a set of statements several times.

row, column

When referencing a two-dimensional array, one must give the index of the ___ first, followed by the index of the ___.

actual

When using a template function, the actual type of the parameters is determined by the ___ parameters.

accessor

When using classes, a module (method) that does not change the attributes of an object of the class, is called a ___ module

all but the first dimension

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

true

When you pass an array as an argument to a function, the function can modify the contents of the array. true or false?

true

When you pass by value, the actual parameters need to evaluate to actual values(true or false)

d

Which of the following is a valid C++ array declaration? a. int array[0]; b. float $payments[10]; c. void numbers[5]; d. int array[10]; e. none of these

*

Which symbol is used to deference a pointer variable?

see path with 2 edges

Why would one multiply an adjacency matrix by itself?

Programmer-Defined Identifiers

Words or names defined by the programmer. They are symbolic names that refer to variables or programming routines.

Key Words

Words that have a special meaning. Key words may only be used for their intended purpose. Key words are also known as reserved words.

for(int num=0; num < 10; x+2) cout<<num<<endl;

Write as for loop num = 0; while (num < 10) { cout<<num << endl; num = num + 2; }

Can you reassign an array reference variable to another array?

Yes

Are fractional values allowed for loop control variables?

Yes, they are allowed, but not recommended. Different computers might produce different results.

can <iomanip> manipulators be used with strings?

Yes. The program will treat each string as a single object, and use the manipulators accordingly.

true

You cannot use the assignment operator to copy one non character array's contents to another in a single statement(true or false)

Which of the following is not true?

You must declare the control variable outside of the for loop.

How can you pass a part of an array to a function?

You need to pass a pointer to the beginning of the subarray. eg. f($a[2]) or f(a+2)

Which of the following is false?

You should always try to write the fastest, smallest code possible before attempting to make it simple and correct.

If an array is partially initialized, the uninitialized elements will be set to _________.

Zero

Subscript numbering in C++ always starts at _________.

Zero

array subscripting operator

[ ] operater used in C++ to define an array

Default

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

Two or more

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

AutomaticDelay

_______ setting determines the length of time required for a tooltip to appear.

OpenFileDialog

________ is an easy control to use to allow a user of a program select files for use within an application.

AutoPopDelay

________ setting determines the amount of time tooltip remains visible.

Polymorphism

_________ is when two classes can have methods that are named the same and do almost the same thing, but have different implimentations.

boolean

a ______ expression is an expression that can be thought of as being true or false

do while

a ______ loop always executes the loop body at least once, regardless of condition

STL/ Standard Template Library

a collection of data types and algorithms that you may use in your programs. These data types and algorithms are programmer-defined. They are not part of the C++ language, but were created in addition to the built-in data types. (Many older compilers do not support this).

data structure

a collection of related data values associated with one name

array

a data structure in which all the elements are of the same type

A collection of statements that perform a specific task.

a function

true

a function can return a structure (T/F)

one-dimensional array

a list of values under a single name, arranged in a row or column

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

a loop

posttest loop

a loop in which the loop condition is evaluated after executing the body of the loop

pretest loop

a loop in which the loop condition is evaluated before executing the body of the loop

infinite loop

a loop that continues to execute endlessly

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

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

while loop

a looping structure that continues as long as a particular condition is true

Search Algorithm

a method of locating a specific item in a larger collection of data.

initialization list

a set of values enclosed in curly braces used to initialize an array

element

a single value inside an array

toString method

a string that represents the state of an object , appropraite for displaying on the screen

For style purposes it is best to use ___________ to indicate the maximum size of an array

a symbolic constant

structured data type

a type of variable in which each item is a collection of other data items. Examples: arrays and structs

simple data type

a type of variable that can store only one value at a time

class

a type whose variables are objects

sentinel-controlled while loop

a while loop that uses a sentinel value to end the loop

EOF-controlled while loop

a while loop which will stop when it reaches the end of the file that it is reading

The expression if ( num != 65 ) cannot be replaced by:

if ( !( num - 65 ) ).

default argument

in the following function declaration, the istream object cin is called a __________ void output(istream& in=cin);

dereferencing operator

in the statement cout<< * p1; the * is the_________

true

it is possible to have multiple private labels in a class definition (T/F)

Each repetition of a loop is known as a(n) __________.

iteration

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

legal in C++

it is ____ to pass an argument to a function that contains an individual array element, such as numbers[3];

legal in C++

Find the error: for (i = 1; i <= 10; i++); -----cout << i << " "; cout << endl;

semicolon after the for statement. Causes the action of the for statement to be empty.

A(n) __________ is a special value that marks the end of a series of values.

sentinel

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

sentinel

The vector data type is a(n) ______________ container

sequence

The ____________, __________ and ____________ are the only three forms of control necessary.

sequence, selection, repetition.

full syntax of the "left" function

setiosflags(ios::left) usually, only the"left" portion is needed

Which of the following is a parameterized stream manipulator used to format output?

setw

A two-dimensional array is like ______________ put together

several identical arrays

When declaring a one-dimensional array as a formal parameter, the size...

should be omitted.

const

since accessor functions in a class do not modify or mutate the data members of the object the function should have the _______ modifier

To determine the number of elements in a vector, use the _____________ member function.

size

The _________ indicates the number of elements, or values, an array can hold.

size declarator

The _________ indicates the number of values that the array should be able to hold.

size declarator

The value in a _____ variable persists between functions.

static local

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

A two-dimensional array of characters can contain

strings of the same length strings of different lengths uninitialized elements

Write code to create an instance of point "max pt" with y=320 and x=200

struct point maxpt={320, 200};

Write code for an instance of point called pt.

struct point pt;

Write code to create a structure called point that has an integer 'x' and an integer 'y'.

struct point{ int y; int x; };

Create a structure rect with 2 point structure members pt1 and pt2.

struct rect{ struct point pt1; struct point pt2; };

How do you declare a structure that can be used without instantiniation? It should be called "student_details" and have a char firstname[10] and char lastname[10] and an int grade;

struct{ char firstname[10]; char lastname[10]; int grade; }student_details;

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

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

subscript

Each element in an array is assigned a unique number known as a ________.

subscript

Each element of an array is accessed and indexed by a number known as a(n)_________.

subscript

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

subscript

divisor

suppose that m and n are integers and m is nonzero. Then m is called a _______ of n if n = mt for some integer t; that is, when m divides n, the remainder is zero

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

switch

function postcondition

tells what wiil be true after the function executes

If an index goes out of bounds, some new compilers...

terminate the program and issue an error message

If you do not want a function to modify an array parameter, use...

the "const" keyword

address of operator

the & operator is called the ________

when you work with a dereferenced pointer, you are actually workign with

the actual value of the variable whose address is stored in the pointer variable

a pointer may be initialized with

the address of an existing object

if a variable uses more than one bye of memory, for pointer purposes its address is

the address of the first byte of storage

display next value in at least 10 characters

the command outFile.width(10) is used to

first

the computer remembers the address of which indexed variables in an array

scope reference

the double colon(::)operator is known as the_______operator

Which function is used to dynamically allocate memory?

the function "new"

To read strings with blanks, use...

the get function. Syntax: cin.get(str, m+1)

An array index is "out of bounds" if...

the index is less than 0 or greater than (Array_Size -1)

false

the indexed variables of an array must be integers (T/F)

elements

the individual variables that comprise an array are called ______

how do you define a vector object for holding integers

vector<int>v

Write code for copying string t to string s

void strcpy(char *s, char *t){ while((*s=*t)!='\0'){ s++;t++; } }

0 to 24

what are valid indexes for the array shown below int myArray[25];

((y<x)&&(x<z))

what is the correct way to write the condition y<x<z

(x>=20 || x<=12)

what is the opposite of (x<20 && x>12)

1 14 3

what is the output ? void something(int a, int& b) { int c; c=a+2; a=a*3; b=c+a; } int r=1; int s=2; int t=3; something(t,s); cout<<r<<' '<<s<<' '<<t<<endl;

value

what is the output of the following code float value; value=33.5; cout<<"value"<<endl;

large

what is the output of the following code fragment if x is 15 if (x<20) -------if(x<10) -------cout<<"less than 10 else cout<<"large"

0.0

what is the output of the following program fragment cout<<static_cast<float>(3/4)<<endl;

the integer 'g'

what is the output of? char ch='G'; cout<<tolower(ch)<<endl;

0

what is the value of i after the function call int doSomething(int value) { value = 35; return value; value=13 } int i=0; cout<<doSomthing(i)

2

what is the value of the following sqrt(sqrt(pow(2.0,4.0)));

true

what is the value of the following expression (true && (4/3 || !(6)))

11

what is the value of x after the following code executes int x = 10; if(x++>10) { x=13; }

3.75

what is the value of x after the following statement float x; x=3.0/4.0+3+2/5;

3.0

what is the value of x after the following statements float x; x = 15/4;

overloaded constructors

what member functions do you need to allow the compiler to perform automatic type conversions from a type different than the class to the class

function precondition

what must be true before the function executes

&

what symbol is used to signify that a parameter is a pass by reference parameter

pretest loop

while and for loops check the condition, then execute if condition is true.

counter-controlled while loop

while loop that goes for a fixed number of iterations. Uses an incrementing or decrementing variable to control the loop.

Flag-controlled while loop

while loop that is controlled by a bool variable. Will continue until the bool variable is "false"

EOF-controlled while loop

while loop that works through the values in a file until it reaches the end of the file.

paramater data type compatibility

will automatically perform widening conversions, but narrowing will cause error. Error: double d = 1.0; displayValue(d); BUT this works: double d = 1.0; displayValue((int)d);

hasNext()

will return true if another item can be read form the file: while (inputFile.hasNext) { }

p1=new string[arraysize];

write a code to declare a dynamic array of strings (use the pointer variable p1) that has as many elements as the variable arraysize

p1=new int;

write the code that assigns to p1 (an integer pointer variable) the pointer to a dynamically created integer

double list[10];

write the code to declare an array of 10 doubles named list

delete p1;

write the code to return the dynamic memory pointed to by p1 to the freestore

while(x<0)

write the loop condition to continue a while loop as long as x is negative

Character constants in C++ are always enclosed in ______

'single quotation marks'

< >

-Opening and closing brackets -Encloses a filename when used with the #include directive.

( )

-Opening and closing parentheses -Used in naming a function, as in int main().

The values in an initialization list are stored in the array in the order they appear in the list.

...

To calculate the amount of memory used by an array, multiply the number of elements by the number of bytes each element uses.

...

To pass an array to a function, pass the name of the array

...

When an array is passed to a function, the function has access to the original array.

...

7.5 Any time the name of an array is used without brackets and a subscript...

... it is seen as the array's beginning memory address. p. 396

If an array is partially initialized, the uninitialized elements will be set to___.

0

What is the output of the following code segment? n = 1; while (n <= 5) cout << n << ' '; n++;

1 1 1 ... and on forever

2 uses of break statement

1) exit early from a loop 2) Skip the remainder of a switch structure

3 Ways to process a two-dimensional array

1) process the entire array 2) process a single row at a time 3) process a single column at a time

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

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

20

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

20

What will be the value of result after the following code has been executed? int a = 60; int b = 15; int result = 10; if (a = b) result *= 2;

20

using a linear serach to find a value that is stored in the last element of an array of 20,000 elements, _____ elements must be compared

20,000

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

21

Which of the following statement will give the result as an integer value?

22 / 7

What is the last legal subscript that can be used with the following array? int values[5];

4

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

6

Whats some examples of punctuation?

; ,

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

<

search

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

driver

A _____ is a main program that only checks that functions execute

local

A _____ variable is declared inside a function and is not accessible outside the function.

stub

A ______ is a simplified version of a function used to test the main program

C-string

A character array that is null-terminated.

true

A class can have more than one constructor function(true or false)

Class

A code object is a specific instance of a user-defined type called a _____.

true

A double dimensional array can be considered as an array of arrays (True or false)

Table Control

A good way to align controls on a Web Page is by using a _____ _______.

An example of a secondary storage device is:

A hard disk

false

A local variable and a global variable may not have the same name within the same program. (True or False)?

false

A pointer that has not been initialized is automatically set to NULL(t or f)

true

A pointer variable is used to contain a binary address. (true or false)

false

A postfix expression is the reverse of its equivalent prefix expression(true or false)

LIFO, FIFO

A stack uses the idea of ___. An example of where it is used is ___.

True

A static variable that is declared within a function is initialized only once, the first time the function is called.

Members

A structure contains variables of different type that are referred to as _______.

Structure

A structure is a collection of one or more variables, possibly of different types grouped together under a single name for convenient handling.

7.2 What is a subscript?

A subscript is used as an index to pinpoint a specific element within an array. The first element is assigned subscript 0, the second element is assigned 1 and so on... short hours[6]; // Has subscripts 0-5 p. 379

true

A template queue class allows one to create queues of different types(true or false)

What will the following program display? #include <iostream> using namespace std; int main() { int a = 0, b = 2, x = 4, y = 0; cout << (a == b) << " "; cout << (a != b) << " "; cout << (b <=x) << " "; cout << (y > a) << endl; return 0; } A) 0 1 1 0 B) 0 0 1 0 C) 1 1 0 1 D) 1 0 0 1 E) None of these

A) 0 1 1 0

Two most widely used character sets

ASCII and EBCDIC

push_back( )(member function)

Accepts a value as an argument, and stores that value after the last element in the vector.

Sequential search

Algorithm used in C++. searches an array element by element. Also called linear search

Which of the following data types can be used to represent integers?

All of the above.

one pass, no parenthesis

An advantage of prefix over infix is ___.

false

An array initialization list must be placed on one single line. true or false?

true

An array is a collection of like objects(true or false)

true

Any mathematical operations that can be performed on regular C++ variables can be performed on structure members (True or false)

onsider the execution of the following for loop or (int x = 1; x < 5; increment ) cout << x + 1 << endl; If the last value printed is 5, which of the following might have been used for increment?

Any of the above

Address

Any time the name of an array is used without brackets and a subscript, it is seen as a(n) ___.

Which of the following is not one the rules for forming structured programs?

Any transition arrow can be reversed.

Internally, the CPU consists of ________ and ________.

Arithmetic Logic Unit & Control Unit

sorted

Array elements must be _____ before a binary search can be performed.

Any time the name of an array is used without brackets and a subscript, it is seen as _________.

Array's beginning memory address

What will the following code display? int number = 7; cout << "The number is " << "number" << endl; A) The number is 7 B) The number is number C) The number is7 D) The number is 0

B) The number is number

Why doesn't C++ allow arrays to be passed by value?

Because that would require that the function allocate sufficient memory, then copy every element of the array into the allocated memory, which would be a slow, inefficient process

Why can you omit arraySize if you initialize an array during declaration?

Because the compiler can deduce the needed size of the array from the number of elements in the initialization

Subscript

By using the same ___ for multiple arrays, you can build relationships between the data stored in the arrays.

subscript

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

How do you establish a parallel relationship between two or more arrays?

By using the same subscript value for each array.

string comparisons are performed...

Character by character, comparing collating sequences.

If you want to remove all the items in a List you can call the ________ method.

Clear

Consider the following declaration: char name[16]; If you store a string of length 10 in array "name", how is memory used?

Computer will store the string in the first 10 characters, store the null character in the 11th position, and leave the remaining 5 components unused.

The size declaratory must be a_____with a value greater than____.

Constant integer expression; zero

Library Classes

Containly only static data and methods; have no "instances" Ex: Math

What does syntax do?

Controls the use of key words, operators, programmer defined symbols and punctuation

strcpy(s1, s2)

Copies the string s2 into the string variable s1. The length of s1 should be at least as large as s2.

.empty (member function) (vector.empty())

Determines if a vector is empty.

In C++, the condition ( 4 > y > 1 ):

Does not evaluate correctly and should be replaced by ( 4 > y && y > 1 ).

EXIT_FAILURE and _____ are named constants that may be used to indicate success or failure when the exit() function is called.

EXIT_SUCCESS

EOF stands for...

End of File

==

Equal to

19

Evaluate the following postfix expression if possible. 3 4 + 5 2 - * 7 + 9 -

true

Every C++ program must have a module named main(true or false)

A vector is an associative container.

F

no negative sizes in array, should be less than 10, can't set arrays equal in one statement

Find the error(s), if there are any, in each of the following sections of code. (1 pt/each) a. int collection[-20]; b. int table[10]; for (int x = 0; x < 20; x++) { cout<<"Enter the next value: "; cin>> table[x]; } c. int array1[4], array2[4] = {3, 6, 9, 12}; array1 = array2;

float ratings[];

For the array to be implicitly sized there must be an initialization list.

false

Friend functions are members of the class (T/F)

9,3

Given the following array of numbers, how many comparisons will be needed before the value 99 is located using: (2 pts) a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9] -23 0 10 27 39 56 68 77 99 121 1. The linear search = _______ 2. The binary search = _______

false

Global variables should be used whenever possible(true or false)

>=

Greater than or equal to

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

Hexadecimal and Octal

________ languages are close to the level of humans in terms of readability.

High Level

true

If one initializes part of an array during declaration, the values of the uninitialized part of the array depend on whether the array was declared in the main or made global(True or false)

false

If one needs a parameter to be an in-out parameter, then that parameter should be passed by value(true or false)

true

If one opens a file to write to, then the original information in the file will be lost (True or false)

fstream

If one wants to use an external file, then they must include ___.

Initialization list

If the size declarator of an array definition is omitted, C++ counts the number of items in the ___ to determine how large the array should be.

accessor

In a class, modules that retrieve the contents of the attributes, but do not change their values are called ___ modules.

CreateText

In order to create a new text file with a StreamWriter, _________ is used.

range of array index values

Index values must be between 0 and (array size -1)

The three primary activities of a program are __________.

Input, Process, and Output

You can use the _______ method to insert an item at a specific index in a List.

Insert

A program is a set of ____.

Instructions

The size declarator must be a(n) _________ with a value greater than _________.

Integer with a value greater than zero

false

Integration testing is the same as unit testing(true or false)

Why should you not pass structures by value?

It can be very inefficient since they can have a lot of members which will occupy extra space when copied. A pointer to a structure can be used instead.

Rows, Columns

It's best to think of a two-dimensional array as having ___ and ___.

7.4 What is implicit array sizing?

It's possible to define an array without specifying an initialization list. C++ automatically makes the array large enough to hold all initialization values. double ratings [ ] = {1.0, 1.5, 2.0, 2.5, 3.0}; p. 393

How large is the u variable?

Large enough to hold the largest of its type members.

In C#, all arrays have a _____ property that is set to the number of elements in the array.

Length

_______ converts the object code to an executable.

Linker

Define the problem, create an algorithm, test by hand, convert to language of choice, test on computer using data from step 3, use and maintain

List the six steps involved in problem solving (according to me)

________ is the only language the computers really process.

Machine Language

How to avoid an infinite loop

Make sure the loop's body contains statements that will eventually set the entry condition to "false"

Spot the error: while i >= 10 ------cout << i << endl;

Missing parentheses around the condition: (i >= 10)

Unix and Windows 2000 are examples of _______________ operating systems.

Multi-tasking

What happens if your program goes ouside array index bounds?

No warning occurs. Program modifies a memory location that may have been reserved for something else, resulting in unpredictable program behavior.

When inputting c-strings, should you include quotation marks?

No.

What is the difference between a for loop and a counter-controlled while loop?

Nothing. They perform a certain action and increase a counter variable each time until the value reaches a certain point. However, for loops have a simplified syntax that make them easier and more efficient to use.

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

Null terminator

false

One can cin pointers(t or f)

false

One can directly access the private elements of a class in any program(true or false)

true

One can initialize all the elements in a double dimension during the declaration statement (True or False)

true

One can initialize all the memory locations of an array when the array is declared(true or false)

Sequence Container

Organizes data in a sequential fashion, similar to an array. (Vector data type).

Associative Container

Organizes data with keys, which allow rapid, random access to elements store in the container.

false

Our C++ compiler allows one to access memory outside of an array range without signaling an error(true or false)

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

Parentheses

When you pass an array name as an argument to a function, what is actually being passed?

Passing array name to function will pass address of array of integers

Why do we need to define a type for a pointer?

Pointers are constrained to point to a particular kind of object.

FIFO, print queues

Queues follow the principle of ___. One of its computer uses is ___.

The computer's main memory is commonly known as:

RAM

pop_back( ) (member function)

Removes the last element from a vector

What is the most common operation performed on lists and arrays?

Searching a list for a given value

When initialization a two-dimensional array, i helps to enclose each row's initialization list in a _____

Set of Braces({})

num = 0 - initialize, while- test, cout- execute, last line- modify

Show the four parts of a loop using the loop below and show the output. ( 4 pts) num = 0; while (num < 10) { cout<<num << endl; num = num + 2; }

Initialization

Starting values for an array may be specified with a(n) ___ list.

The OR (||) operator:

Stops evaluation upon finding one condition to be true.

dynamic

Storage that may be obtained during the run of the program is called ___.

reading a line from a file

String str = inputFile.nextLine();

Try-Catch-Finally

Structured Exception Handling make use of the __________ _____ to catch exceptions.

C++ allows you to create arrays with three or more dimensions.

T

The individual elements of an array are accessed and indexed by unique numbers.

T; subscripts

To define a two-dimensional array, __ size declaratory are required.

TWO

Chart

The ______ control is used to display a bar graph on a Web Page.

Table

The book describes a _______ as a rectangular array of data.

7.2 How do you access array elements?

The individual elements of an array are assigned unique subscripts. These subscripts are used to access the elements. Even though an entire array has only one name, the elements may be accessed and used as individual variables. p. 379

memory address

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

NULL

The one value that every pointer can be set equal to is ___.

true

The order of the operands determines if an equation is in infix, prefix or postfix form (t or f)

What does the term hardware refer to?

The physical components that a computer is made of

If a variable is declared in the initialization expression of a for structure, then:

The scope of the variable is restricted to that particular for loop.

true

The scope resolution operator tells the compiler that the function is a member function of a particular class. (t or f)

When writing a function that accepts a two-dimensional array as an argument, which size declarator must you provide in the parameter for the array?

The second size declarator, which is for the number of columns.

int collection[-20];

The size declarator cannot be negative.

Sequence, Associative

The two types of containers defined by the STL are ___ and ___.

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

What does the * sign do?

The unary * is the indirection or dereferencing operator. When applied to a pointer, it accesses the object the pointer points to.

#include <iostream> #include <string> using namespace std; int main() { int var1 = 10; int var2 = 2; int var3 = 20; var3 = var3 / (var1 % var2); cout << var3 << endl; return 0; }

There will be no output due to a run-time error.

Vector

To define a vector in your program, you must #include the ___ header file.

(rear + 1) % n ==front; front==rear;

To determine if a static circular queue with a buffer is full, the test is ___. To determine if it is empty the test is ___.

top==n-1; top==-1;

To determine if a static stack is full, the test is ___. To determine if it is empty the test is ___.

size()

To determine the number of elements in a vector, use the ___ member function.

new, delete

To get memory during run time, one must use the ___ command. To get rid of memory during run time, use the ___ command.

(T/F) An array's Length property is read only, you cannot change its value.

True

(T/F) Variables can only hold one value at a time.

True

A binary search of a 500 element array would require, at most, 9 array values to be tested

True

#include<fstream>; open and close file

Two changes that one must make to a program in order to use an external file are ___ and ___.

structures and classes

Two places in the language C++ where one will find } ; are ___ and ___.

A(n) _________ array is like several arrays of the same type put together.

Two-dimensional

Whats a typedef?

Typedef is a facility provided by C for creating new data type names.

A ___________ is an example of secondary storage device.

USB Drive

Of the following, which is not a logic error?

Using commas instead of the two required semicolons in a for header.

Which of the following is a bad programming practice?

Using floating-point values for counters in counter-controlled repetition

loop control variable (LCV)

Variable whose value determines whether the loop executes again or not. (controls the end of the loop)

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

Variables

cols needs to be sent not row, rows not declared, check other spelling and syntax can't put values in struct, semi-colon after struct, varray[0].a

What's wrong? a. void showValues (int nums[4] [ ]) { for(rows = 0; rows < 4; rows++) for (cols = 0; col<5: cols++) cout<< nums[rows] [cols]; } b. struct TwoVals { int a = 5; int b = 10; } int main() { TwoVals varray[10]; varray.a[0] = 1; varray[3] = varray[2]; return 0; }

RaiseEvent

When a code object has events those events are raised from within the class block code with the ______ keyword.

false

When a function is called, the flow of control moves to the function's prototype. (True/False)

true

When one creates a class using templates, then the definition and implementations are all put in the .h file.

reference

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

ReadLine

When using StreamReader to access a data file what method is used to retrieve the contents?

mutator function

a member function that allows the user of the class to change the value of a private data type is called a ________

accessor

a member function that allows the user of the class to find out the value of a private data type

constructor

a member function that gets called automatically when an object of the class is declared

A(n) __________ is a variable that is initialized to some starting value, usually zero, and then has numbers added to it in each iteration of a loop.

accumulator

The memory that is allocated for a value type variable is the ______ location that will hold any value that is assigned to that variable.

actual

every byte in the computers memory is assigned a unique

address

pointer

address of a memory location

character string

an array of 0 or more characters

offset or subscript

another name for index

aggregate operation

any operation that manipulates the entire array as a single unit

If the initializing sequence is shorter than the array size, then the extra values...

are automatically initialized to 0.

one-dimensional array

array in which components are arranged in a list form.

int[] numbers = new int [5];

array with 5 integers (index 0-4)

Concat

array1._______(array2).ToArray is an array containing the elements of array1 with array2 appended, possibly with duplicates.

Intersect

array1._______(array2).ToArray is an array containing the elements that are in both array1 and array2.

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

cin object

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

cin.ignore

UML Diagram

class, fields, method

To completely clear the contents of a vector, use the ___ member function.

clear

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

cmath

array

collection of a fixed number of components of the same data type and in contiguous memory space

To copy, read, or compare arrays, it must be done...

componentwise

The __________ statement causes a loop to skip the remaining statements in the current iteration.

continue

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

continue

type casting

converting from one type to another is called _________

Each time the foreach loop iterates, it ______ an array element to the _______ variable.

copies, iteration

Local Variables

declared inside the method and not accessible to statements outside the method; different methods can have variables with the same names; A method's local variables only exist while the method is executing; must be given a value before used.

"instance" data and methods

declared without static; each instance has its own data; accessed by instance references

Syntax of a do...while loop

do statement while (expression);

Creating 2D array

double [] [] scores = new double [3][4]; (rows, columns)

What defines a double-precision floating point variable named payCheck?

double payCheck;

Declare a double array named scores with row size 3 and column size 4.

double[ , ] scores = new double[3,4];

When can you initialize an array?

during or after array declaration

true

dynamically created variables have no name (T/F)

You cannot use the foreach loop if you need to do any of the following: Change the contents of an array _______. Work through the array elements in ________ order. Access some, but not all, of the _____ ________. Simultaneously work with _____ or more arrays within the loop.

element, reverse, array elements, two

The individual locations contained in an array are known as

elements

The individual values contained in an array are known as _____.

elements

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

exit( )

C++ limits the number of array dimensions to two

false

data in an objects

fields or variables

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

for

strVar.c_str()

function to convert a string to a null-terminated c-string

Stale Data

has potentional to become stale when it requires a calculation, so it is better to store data in a method

An array with no elements is

illegal in C++

To __________ a value means to increase it by one

increment

A loop that does not have a way of stopping is a(n) __________ loop.

infinite (or endless)

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

infinite loop

closing a file

inputFile.close();

Define a two-dimensional array of integers named grades. It should have 30 rows and 10 columns.

int grades[30][10];

int *ptr is the same as

int* ptr;

Create an integer array object that holds six items and associate it with a reference variable named "numbersArray".

int[ ] numbersArray = new int[6];

Declare a reference variable named "numbersArray" for an integer array.

int[ ] numbersArray;

Creating and Array

int[] numbers; //declare numbers = new int [6]; //create array

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

iostream header file

object created from a class

is an instance of the class

Void * pointer

is the generic pointer type. Pointers can be cast to void and back without loss of information.

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

false

it is illegal to call other functions from inside a function definition(T/F)

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

left

7.4 If a local array is completely uninitialized, its elements will contain "garbage", like all other local variables. p. 393

left blank intentionally

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

legal in C++

the ____ is adequate for searching through small arrays

linear search

sequential search

looking through an array one element at a time, starting at the beginning of the array

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

loop

destructor

member function named ~ClassName that is called automatically when an object is passing out of scope.

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

name

The ______________ is automatically appended to a character array when it is initialized with a string constant

null terminator

A two-dimensional array can have elements of _________ data type(s)

one

a two-dimensional array can have elements of ____ data types

one

Partial initialization

only initializing the first few values of an array

void method

performs a task and then terminates. ex: system.out.println("hi");

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

prototype

out-of-range reference

reference to an array element with an index < 0 or >= arraySize

strVal.size()

returns the length of the string strVal

strVal.substr(int start, int len)

returns the substring of length len starting at "start" extracted from strVal.

A jagged array is similar to a two-dimensional array, but the ______ in a jagged array can have different lengths.

rows

the ____ sort usually performs fewer exchanges than the ____ sort

selection, bubble

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

size

standard deviation

square root of the variance

The value in this type of local variable persists between function calls.

static

the statement cin>>*num3 does what?

stores the keyboard input into the variable pointer to by num3

scope

the _______ of a variable is where the variable can be used

struct

the keyword ________ defines a structure type definition

false

the locations of the various indexed variables in an array can be spread out all over the memory (T/F)

The last character in a C-string is always...

the null character

c-style strings are terminated by....

the null character '\0'

If you specify the size of an array when it is declared as a formal parameter...

the size is ignored by the compiler

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

true

Continue statement

used in while, for, and do...while structures for the purpose of skipping the remaining statements in the loop and proceeding to the next iteration of the loop

Arguments

values sent into a method

gators is an empty vector of int s. Statement that stores the value 27 in gators .

vector <int> gators; gators.push_back(27);

sentinel-controlled while loop

while loop that continues until it reads a special character or value called a sentinel

true

you can assign an array to a pointer variable (T/F)

false

you may not have more than one input and one output stream open at any one time (T/F)

If you leave out the size declarator in an array definition

you must furnish an initialization list

What is input, output, process?

The "how to"/formula to find output

DrawString

What Graphics method would be used to put text in a PictureBox control?

fibonacci number

a number in the Fibonacci sequence

nesting

a process that involves putting one control structure inside another

When inputting a string that contains blanks, use...

getline(cin, strVal, terminator)

scores[24]

given an array named scores with 25 elements what is the correct way to access the 25th element

7

given following enumerated data type definition what is the value of SAT enum myType[sun=3,mon=1,tue=3,wed,thur,fri,SAT,numdays]

x is not zero

given the following code fragment and an input value of 0, what is the output that is generated int x; cout<<"enter a value" cin>>x; if(x=0) { cout<<"x is zero"; } else { cout<<"x is not zero" }

This vector function removes an item from a vector.

pop_back

The do-while loop is considered a(n) _________ loop.

post-test

When the increment or decrement operator is placed after the operand (or to the operand's right), the operator is being used in __________ mode.

postfix

array indexes begin at...

0

What are some examples of operators?

<< >> = *

insertion operator

<< is called the ____

To define a vector in your program, you must #include the ____________ header file.

<Vector>

To define a vector in you program, you must #include the ____ header file.

<vector>

You cannot use the _________ operator to copy data from one array to another in a single statement.

=

extraction operator

>> is called the _________________

An operator that associates from right to left is:

?:

true

An algorithm should be language independent(true or false)

Element

An individual variable in an array variable is referred to as an _________.

What is the value stored at x, given the statements: int x; x = 3 / static_cast<int>(4.5 + 6.4); A) .3 B) 0 C) .275229 D) 3.3 E) None of these

B) 0

What is the value of average after the following code executes? double average; average = 1.0 + 2.0 + 3.0 / 3.0; A) 2.0 B) 4.0 C) 1.5 D) 6.0

B) 4.0

Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 int number = 5; 7 8 if (number >= 0 && <= 100) 9 cout << "passed.\n"; 10 else 11 cout << "failed.\n"; 12 return 0; 13 } A) 6 B) 8 C) 10 D) 9

B) 8

The following code correctly determines whether x contains a value in the range of 0 through 100 . if (x >= 0 && <= 100) A) True B) False

B) False

The statement cout << setprecision(5) << dollars << endl; will output $5.00 to the screen. A) True B) False

B) False

When a two-dimensional array is passed to a function the _________ size must be specified.

Column

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; A) Nothing will be displayed B) false C) x D) true

B) False

Given that x = 2, y = 1, and z = 0, what will the following cout statement display? cout << "answer = " << (x || !y && z) << endl; A) answer = 0 B) answer = 1 C) answer = 2 D) None of these

B) answer = 1

Suppose the following declarations: int myList [5] = {0, 4, 8, 12, 16} int yourList [5]; Why is this statement illegal? yourList = myList;

Because C++ prohibits aggregate operations. myList cannot be treated as a single unit.

Assuming that array1 and array2 are both arrays, why is it not possible to assign the contents of array2 to array1 with the following statement? array1 = array2;

Because an array name without brackets and a subscript represents the array's beginning memory address. The statement shown attempts to assign the address of array2 to array1, which is not permitted.

Why won't a program generate a syntax error if aggregate operations are used?

Because the computer will use the address of the identifiers as the requested values. This results in a logic error

true

Black box testing is when the tester cannot see the code(true or false)

What will the following code display? int x = 0, y = 1, z = 2; cout << x << y << z << endl; A) 0 1 2 B) 0 1 2 C) xyz D) 012

D) 012

What is the output of the following code? int w = 98; int x = 99; int y = 0; int z = 1; if (x >= 99) { if (x < 99) cout << y << endl; else cout << z << endl; } else { if (x == 99) cout << x << endl; else cout << w << endl; } A) 98 B) 99 C) 0 D) 1

D) 1

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; A) 0 B) 1 C) 2 D) 3 E) None of these

D) 3

A variable must be _____ before it can be used in a program.

Defined

What happens when we declare a struct with no list of variables following after its closing bracket?

The struct reserves no storage. It merely describes a template or the shape of a structure. If the declaration has a tag the tag can be used later to define instances of the structure.

nodes, edges

The two parts of a computer graph are ___ and ___.

Each individual element of an array can be accessed by the array name and an element number, called a subscript

True

If an array is partially initialized, the uninitialized elements will be set to zero

True

When you pass an array as an argument to a function, the function can modify the contents of the array

True

7.5 True or False: Array elements may also be used in relational expressions.

True p. 396

true

Unit testing is done for each module(true or false)

arrays

Unlike regular variables, _____ can hold multiple values.

7.2 You can use any array integer expression as...

You can use any integer expression as an array subscript. for (int count = 1; count <= NUM_EMPLOYEES; count++) { cout << "Enter the hours worked by the employee " << count <<": "; cin >> hours[count - 1]; } In this expression the cin statement uses the expression, count - 1 , as a subscript p. 384

Assignment

You cannot use the ___ operator to copy data from one array to another in a single statement.

How do you pass by value in C?

You pass pointers that point to the objects you want to change.

To pass an array to a function, pass the _________ of the array.

address, or name

selection sort

algorithm for organizing a list from smallest to largest. finds the smallest remaining value each time it iterates through the loop

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

all but the first dimension

C++ has no array___ checking, which means you can inadvertently store data past the end of an array.

boundary

When initializing a two-dimensional array, it helps to enclose each row s initialization list in _________.

braces []

Look at the following array definition. double sales[8][10]; How many rows does the array have? How many columns does the array have? How many elements does the array have? Write a statement that stores a number in the last column of the last row in the array

double sales[8][10]; How many rows does the array have? 8 Rows How many columns does the array have? 10 columns How many elements does the array have? 80 elements Sales[7][9] = 53.1; stores double in the last column of the last row in the array

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?

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

An array with no elements is _____.

illegal in C++

Look at the following array definition. int numbers[5] = { 1, 2, 3 }; What value is stored in numbers[2]? What value is stored in numbers[4]?

int numbers[5] = { 1, 2, 3 }; What value is stored in numbers[2]? 3 What value is stored in numbers[4]? 0, its value is not initialized

Which of the following is a valid C++ array definition?

int scores [10];

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

name

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

name

calling a method

name of method + parentheses. ex: displayMessage();

adding to Array list

nameList.add("James"); namesList.add("Catherine");

get array list size

nameList.size() //returns number

toString method code

public String toString() string str = "words:" + variable

selection sort method

sorting mechanism that searches through the array, finds the smallest number, then switches it to the top of the array. this process is repeated for each consecutive array cell until the array ends.

Syntax for converting a string variable to a c-string

strVar.c_str()

Create a pointer to a point structure called pp.

struct point *pp

When information in an array is passed to a function, which two parameters are usually used?

the array Name and the array size.

member

the assignment operator must be a ______ of the class

default

the code following the ________ case is executed if none of the other case conditions are met

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

When initializing an array during declaration, you can omit...

the size of the array. However, you need empty brackets.

maximum size of an array

the total number of elements that can be assigned to an array

false

the types of parameters are optional in the function declaration(T/F)

for loop control variable (indexed variable)

the variable initialized by the initial statement

Flag variable

the variable which is used to control the execution of the flag-controlled while loop

Charter One, Pentagon Federal Credit Union, and Boeing Employees Credit Union, are all primarily:

thrifts

how to "instantiate"

use new. Ex: Student mark - new Student("mark");

reference

when passing a stream to a function it must always be pass by _________

pass by reference

when the address of the actual argument is passed to the formal parameter this is called _______

false

when you return a dynamic array to the freestore you must include the number of elements in the array(T/F)

.get

which command reads one character even if that character is a blank space

This is a pre-test loop that is ideal in situations where you do not want the loop to iterate if the condition is false from the beginning:

while

while ( --counter >= 1 ) counter % 2 ? cout << "A" : cout << "B"; cannot be rewritten as:

while ( counter >= 1 ) if ( counter % 2 ) cout << "A"; else cout << "B";. --counter;

Syntax of while loop

while (expression) statement;

CSV

while (list.hasNextLine()) string input = list.nextLine(); string[] cols = input.split(",");

The __________ and __________ loops will not iterate at all if their test expressions are false to start with.

while and for

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

x *= 2;

The statement: int grades [ ] = {100, 90, 99, 80}; shows an example of:

implicit array sizing

It is legal to subtract a pointer variable from another pointer variable

true

This operator performs a logical NOT operation.

!

7.2 How would you pronounce this? hours[0] = 20;

"hours sub zero is assigned twenty" or "hours sub zero gets twenty" p. 380

22, 12, 42

#include <iostream> #include <string> using namespace std; void scramble(int i, int &j, int &k) { i = 17 + i; j = 34 + k; k = 51 - i; } int main() { int i = 8; int j = 12; int k = 16; scramble(j, k, i); cout << i << " " << j << " " << k << endl; System("pause"); return 0; }

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

#include directive

Which one of the following operators computes the remainder of an integer division?

%

F

(T/F) 2D arrays may be passed to functions, but the row size must be specified in the definition of the parameter variable.

T

(T/F) A two-dimensional array is like several identical arrays put together.

F

(T/F) A vector is an associative container.

F

(T/F) An array's size declarator can either be a literal, a named constant, or a variable.

F

(T/F) Arrays cannot be initialized when they are defined. A loop or other means must be used.

T

(T/F) C++ allows you to create arrays with three or more dimensions.

F

(T/F) If an array is partially initialized, the uninitialized elements will contain "garbage."

T

(T/F) If you add a value to a vector that is already full, the vector will automatically increase its size to accommodate the new value.

F

(T/F) If you leave an element uninitialized, you do not have to leave all the ones that follow it uninitialized.

F

(T/F) If you leave out the size declarator of an array definition, you do not have to include an initialization list.

T

(T/F) It's best to think of 2D arrays as having rows and columns.

T

(T/F) Subscript numbers may be stored in variables.

F

(T/F) The contents of an array element cannot be displayed with cout.

F

(T/F) The first element in an array is accessed by the subscript 1.

F

(T/F) The first size declarator (in the declaration of the 2D array) represents the number of columns. The second size definition represents the number of rows.

T

(T/F) The individual elements of an array are accessed and indexed by unique numbers.

T

(T/F) The subscript of the last element in a single-dimensional array is one less than the total number of elements in the array.

F

(T/F) The uninitialized elements of a string array will automatically be set to the value "0."

T

(T/F) The values in an initialization list are stored in the array in the order they appear in the list.

T

(T/F) To calculate the amount of memory used by an array, multiply the number of elements by the number of bytes each element uses.

T

(T/F) To pass an array to a function, pass the name of the array.

T

(T/F) To use a vector, you must include the vector header file.

T

(T/F) When an array is passed to a function, the function has access to the original array.

F

(T/F) When an array name is used without brackets and a subscript, it is seen as the value of the first element in the array.

T

(T/F) When defining a parameter variable to hold a single-dimensional array argument, you do not have to include the size declarator.

F

(T/F) You can use the [] operator to insert a value into a vector that has no elements.

T

(T/F) You can write programs that use invalid subscripts for an array.

T

(T/F) You cannot use the assignment operator to copy one array's contents to another in a single statement.

T

(T/F) vectors can report the number of elements they contain.

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

++ and --

UML Notation

- (private) or + (public); variable types are placed after variable name with colon

#

- Pound sign. - Marks the beginning of a preprocessor directive.

Let Operator

The ______ ________ in a LINQ query is used to give a name to an expression.

Preprocessor

- Reads the source code. - Searches for special lines that begin with the # symbol. These lines contain commands, or directives, that cause the preprocessor to amend or process the source code in some way

Why write methods?

-Divide and conquer a problem into small manageable pieces -simplify programs; code reuse for a specific task used in many places

You can write programs that use invalid subscripts for an array.

...

7.5 The only way to assign one array to another is...

... to assign the individual elements in the arrays. Usually, this is done best with a loop for(int count = 0; count < SIZE; count++0 newValues[count] = oldValues[count]; p. 396

7.4 If you leave an element uninitialized...

... you must leave all the elements that follow it uninitialized as well. C++ does not provide a way to skip elements in the initialization list. int array[6] = {2, 4, 8, , 12]; // Not legal! p.393

Subscript numbering in C++ always starts at___.

0

What will the following code display? int numbers[4] = { 99, 87 }; cout << numbers[3] << endl;

0

What will the following program segment display? int funny = 7, serious = 15; funny = serious % 2; if (funny != 1) { funny = 0; serious = 0; } else if (funny == 2) { funny = 10; serious = 10; } else { funny = 1; serious = 1; } cout << funny << " " << serious << endl; A) 7 15 B) 0 0 C) 10 10 D) 1 1 E) None of these

1 1

What is the output of the following code segment? n = 1; for ( ; n <= 5; ) cout << n << ' '; n++;

1 1 1 ... and on forever

Consider the following declaration: char name[16]; What is the length of the largest string that can be stored in C-string 'name'?

15

How to choose which loop structure to use

1) if you know how many times the loop executes, use FOR 2) if you don't know how many times, but you know it executes at least once, use DO...WHILE 3) if you don't know how many times, use WHILE

Basic array operations

1) initializing 2) inputting/outputting data 3) finding largest/smallest value in the array

Strings can be manipulated in C++ in which 2 ways?

1) string data type (easiest to use) 2) c-strings

3 looping structures in C++

1) while loop 2) do...while loop 3) for loop

What is the process of converting C++ source code to executable file?

1. Create the file using a text editor 2. Run pre-processor to convert source file directives to source code program statements 3. Run complier to convert source program into machine instructions 4. Run linker to connect hardware specific code to machine instructions, producing an executable file

What are the five major components of a computer system?

1. The CPU (central processing unit) 2. Main Memory 3. Secondary Memory / Storage 4. Input Devices 5. Output Devices

What advantages does a vector offer over an array?

1. You do not have to declare the number of elements that the vector will have. 2. If you had value to a full vector, it will automatically increase it size, rather than go over like an array. 3. A vector can report the number of elements it contains

Which line in the following program contains a call to the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }

10

Look at the following array definition. int values[10]; How many elements does the array have? What is the subscript of the 1st element in the array? What is the subscript of the last element in the array? Assuming that an int uses four bytes of memory, how much memory does the array use?

10 elements Subscript of the 1st element is zero Subscript of the last element is 9 The array used 40 bytes of memory

How many elements does the following array have? int bugs[1000];

1000

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

12

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

12

Which line in the following program contains the header for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }

15 (end chapter 6)

Given the following function definition: void calc (int a, int& b) { int c; c = a + 2; a = a * 3; b = c + a; } What is the output of the following code fragment that invokes calc? (All variables are of type int) x = 1; y = 2; z = 3; calc(x, y); cout << x << " " << y << " " << z << endl;

163

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

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

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 2

void- can stand alone in call, returns none or multiple through parameter list nonvoid- returns one value, call must be part of another statement

2 differences between void and nonvoid

int [] [] number = new int [2][3];

2D array with 2 rows and 3 columns

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

3

What will the following code display? int x = 0; for (int count = 0; count < 3; count++) x += count; cout << x << endl;

3

In the following C++ statement, what will be executed first according to the order of precedence? result = 6 - 3 * 2 + 7 - 10 / 2 ;

3 * 2

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

What is the last legal subscript that can be used with the following array? int values [5];

4

What is the output of the following code snippet? #include <iostream> using namespace std; int main() { int value = 3; value++; cout << value << endl; return 0; }

4

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

4

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

4 2

What is the value of average after the following code executes? double average; average = 1.0 + 2.0 + 3.0 / 3.0;

4.0

What will the following code display? int number = 6; int x = 0; x = --number; cout << x << endl;

5

What will the following code display? int numbers [ ] = {99, 87, 66, 55, 101}; cout << numbers[3] << endl;

55

What will the following code display? int numbers[] = {99, 87, 66, 55, 101 }; cout << numbers[3] << endl;

55

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

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

7

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

7 (chapter 5 end)

What will the following code display? int numbers[] = { 99, 87, 66, 55, 101 }; for (int i = 1; i < 4; i++) cout << numbers[i] << endl;

87 66 55

What will the following code display? int numbers[ ] = {99, 87, 66, 55, 101}; for (int i = 1; i < 4; i++) cout << numbers[i] << " ";

87 66 55

Relational Database

A ________ ________contains a collection of one or more related tables created with a database-managemennt application.

Structure

A ________ is a way for a programmer to build a user defined data type.

data hiding

A big advantage that a class object has over a structured variables is ___.

n-dimensional array

A collection of a fixed number of components arranged in n dimensions (n >= 1).

Two-dimensional array

A collection of a fixed number of components arranged in rows and columns (that is, in two dimensions), wherein all components are of the same type.

Function

A collection of statements that perform a specific task.

true

A component of a structure can be another structure or an array, as well as a simple data type. (True or false)

Modal

A form is considered _______ when it must be closed before a user can enter data on other forms.

Definition

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

Only one

A function can have zero to many parameters, but it can have _____ return value(s).

called

A function is executed when it is ______?

false

A function's return data type must be the same as the function's paramter(s) True or false?

true

A nonvoid module can return a structure through the module name (True or false)

true

A nonvoid module must return a value to the calling statement(true or false)

true

A parameter is a special-purpose variable that is declared inside the parentheses of a function definition.

false

A pretest loop will always be executed at least once(True or false)

Which of the following options correctly describes what a class is?

A programmer-defined data type

priority

A queue that has a queue in it in which the most important things are stored is called a ___ queue.

Vector Object

A sequence container.

The programmer usually enters source code into a computer using:

A text editor

rows, columns

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

several identical arrays

A two-dimensional array is like _____ put together.

Union in C

A union is a variable that may hold (at different times) objects of different types and sizes with the compiler keeping track of size and alignment requirements. For example it can be used to store a string, an int and a char pointer. So the system can assign any of these types to it at each one time.

Primary Key

A well-designed table will have a field referred to as a ______ ____ that will uniquely identify each record.

Multi-dimensional

A(n) ___ array is like several arrays of the same type put together.

binary, linear

A(n) _____ search is more efficient than a(n) _____ search

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

A) 12

After execution of the following code, what will be the value of input_value if the value 0 is entered at the keyboard at run time? cin >> input_value; if (input_value > 5) input_value = input_value + 5; else if (input_value > 2) input_value = input_value + 10; else input_value = input_value + 15; A) 15 B) 10 C) 25 D) 0 E) 5

A) 15

What will be the value of result after the following code has been executed? int a = 60; int b = 15; int result = 10; if (a = b) result *= 2; A) 10 B) 120 C) 20 D) This code will not compile

A) 20

Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL; 7 MY_VAL = 77; 8 cout << MY_VAL << endl; 9 return 0; 10 } A) 6 B) 8 C) 9 D) 7

A) 6

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

A) C++ is fun

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

A) Four score and seven years ago

Which is true about the following statement? cout << setw(4) << num4 << " "; A) It allows four spaces for the value in the variable num4. B) It outputs "setw(4)" before the value in the variable num4. C) It should use setw(10) to output the value in the variable num10. D) It inputs up to four characters stored in the variable num4. E) None of these

A) It allows four spaces for the value in the variable num4.

Upper bound

The value of n in an array is called the ______ ________.

Distinct Operator

The _______ _______ in a LINQ query is used to eliminate duplicate variables.

7.1 What is an array?

An array allows you to store and work with multiple value of the same data type. An array works like a variable that can store a group of values, all of the same type. The values are stored together in consecutive memory locations p. 377

7.1 What is an arrays size declarator?

An arrays size declarator indicates the number of elements, or values, that an array can hold. The size declarator must be a constant integer expression with a value greater than zero. It can be either a literal or a named constant. const int NUM_DAYS = 6; <-- Size declarator int days[NUM_DAYS];

Bubble Sort

An easy way to arrange data in ascending or descending order. It starts by comparing the first two elements in the array. If element 0 is greater than element 1, they are exchanged. The sort repeatedly passes through the array until no exchanges are made.

attributes, methods

An object consists of two parts. These two parts are ___ and ___.

Any time the name of an array is used without brackets and a subscript, it is seen as the____

Array's beginning memory address

How are arrays passed as parameters to functions?

Arrays are passed by reference only. You do NOT include the & sign when declaring an array as a formal parameter.

7.4 Talk about array definitions.

Arrays may be initialized when they are defined. p. 389

A switch statement should be used:

As a multiple-selection structure.

float and double variables should be used:

As imprecise representations of decimal numbers

7.2 What do question marks mean with regard to arrays?

Because values have not been assigned to other elements of the array, question marks will be used to indicate that the contents of those elements are unknown. If an array is defined globally, all of its elements are initialized to zero, by default. Local arrays, however, have no default initialization value. P. 380

Why should a function that accepts an array as an argument, and processes that array, also accept an argument specifying the arrays size?

Because, with the array alone the function has no way of determining the number of elements it has.

The Remove method returns a _______ value.

Boolean

C++ has no array _________ checking, which means you can inadvertently store data past the end of an array.

Bounds

How can you prevent a function from changing an array used as an actual parameter?

By declaring the corresponding formal parameter as a constant

true

By default, if there are no public or private sections in a class definition, it will be private(true or false)

false

By default, things declared in the declaration section of a class are public (true or false)

How do you define an array without providing a size declarator?

By providing an initialization list. The array is sized to hold the number of values in the list.

simplicity

The advantage of a linear search is its _____.

What is the output of the following segment of code if 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; A) 0 B) 3 C) 13 D) 28 E) None of these

C) 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? A) 13 and 14 B) 8 and 9 C) 14 e. 15 D) 13

C) 14

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) A) 3, 4, 6, 7 are False B) Only 5 is False C) 3 and 4 are False D) All are False E) None of these are False

C) 3 and 4 are false

Which value can be entered to cause the following code segment to display the message "That number is acceptable." int number; cin >> number; if (number > 10 && number < 100) cout << "That number is acceptable.\n"; else cout << "That number is not acceptable.\n"; A) 100 B) 10 C) 99 D) 0 E) All of these

C) 99

What will the following code display? cout << "Four " << "score "; cout << "and " << "seven/n"; cout << "years" << "ago" << endl; A) Four score and seven yearsago B) Four score and seven years ago C) Four score and seven/nyearsago D) Four score and seven yearsago

C) Four score and seven/nyearsago

What will the following segment of code output? score = 40; if (score > 95) cout << "Congratulations!\n"; cout << "That's a high score!\n"; cout << "This is a test question!" << endl; A) This is a test question! B) Congratulations! That's a high score! This is a test question! C) That's a high score! This is a test question! D) Congratulations! That's a high score! E) None of these

C) That's a high score! This is a test question!

What will the following segment of code output? You can 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!"; A) You failed the test! B) You passed the test! C) You failed the test! You passed the test! D) You failed the test! You did poorly on the test! E) None of the above

C) You failed the test! You passed the test!

Bounds

C++ has no array ___ checking, which means you can inadvertently store data past the end of an array.

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

C++ is fun

false

C++ limits the number of array dimensions to two. true or false?

false

C++ stores a double dimensional array column by column(True or false)

\r

Causes the cursor to go to the beginning of the current line, not the next line.

To completely clear the contents of a vector, use the ___________ member function.

Clear

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

Closing brace

When a two-dimensional array is passed to a function the ___ size must be specified.

Column

_______ converts a source code to object code.

Compiler

This step will uncover any syntax errors in your program:

Compiling

What will the following code display? cout << "Four" << "score" << endl; cout << "and" << "seven" << endl; cout << "years" << "ago" << endl; A) Four score and seven years ago B) Four score and seven years ago C) Fourscoreandsevenyearsago D) Fourscore andseven yearsago

D) Fourscore andseven yearsago

int settings[3][4]={{12,24,32,48}, {-3,67,71,0}, {0,0,0,0}};

Define a two-dimensional array named settings large enough to hold the table of data below. Initialize the array with the values in the table. (2 pts) 12 24 32 48 -3 67 71 0 0 0 0 0

vector<float> amounts;

Defines "amounts" as an empty vector of floats.

vector<char> letters(25, 'A');

Defines "letters as a vector of 25 characters. Each element is initialized with 'A'.

vector<string> names;

Defines "names" as an empty vector of string objects.

vector<int> scores (15);

Defines "scores" as a vector of 15 ints.

vector<double> values2 (values1);

Defines "values2" as a vector of doubles. All of the elements of "values1", which is also a vector of doubles, are copied to "values2".

What will the following code do? const int SIZE = 5; double x[SIZE]; for(int i = 2; i <= SIZE; i++) { x[i] = 0.0; }

Each element in the array, except the first and the last, is initialized to 0.0

Subscript

Each element of an array is accessed and indexed by a number known as a(n) ___.

Record

Each row of a database is referred to as a _______.

Arrays cannot be initialized when they are defined. A loop or other means must be used.

F; can be defined

The first size declarator (in the declaration of a two-dimensional array) represents the number of columns. The second size definition represents the number of rows.

F; first is rows then column.

When an array name is used without brackets and a subscript, it is seen as the value of the first element in the array.

F; it is passed by as a reference to the address of the array.

Two-dimensional arrays may be passed to functions, but the row size must be specified in the definition of the parameter variable

F; it is the column that must be specified.

IF an array is partially initialized, the uninitialized elements will contain "garbage".

F; only if it is not initialized at all will it be with garbage.

The uninitialized elements of a string array will automatically be set to the value "0".

F; the are set to empty strings.

The first element in an array is accessed by the subscript 1.

F; the subscript is 0

If you leave an element uninitialized, you do not have to leave all the ones that follow it uninitialized.

F; you cannot skip numbers in initialization stage.

If you leave out the size declaratory of an array definition, you do not have to include an initialization list.

F; you have to include it or else the program wont know how big the array is.

T OR F: Assume array1 and array2 are the names of arrays. To assign the contents of array2 to array1, you would use the following statement. array1 = array2;

FALSE

Although two-dimensional arrays are a novel idea, there is no known way to pass one to a function

False

Assume array1 and array2 are the names of arrays. To assign the contents of array2 to array1 you would use the following statement: array1 = array2

False

If you attempt to store data past an array's boundaries, it is guaranteed that the compiler will issue an error

False

T OR F: In C++, it is impossible to display the number 34.789 in a field of 9 spaces with 2 decimal places of precision.

False

T OR F: The C++ language requires that you give variables names that indicate what the variables are used for.

False

T OR F: The default section is required in a switch statement.

False

T OR F: The preprocessor executes after the compiler.

False

T OR F: The scope of a variable declared in a for loop's initialization expression always extends beyond the body of the loop.

False

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

False

T OR F: You may not use the break and continue statements within the same set of nested loops.

False

The statement: double money[25.00]; is a valid C++ array definition.

False

True or Flase: A structure can be compared to another structure.

False

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

False

7.4 True or False: C++ does not allow you to spread the initialization list across multiple lines.

False. C++ does all you to spread the initialization list across multiple lines. p. 391

True or False: Input is information a program sends to the outside world.

False. Output is the information a program sends to the outside world.

The paper money used in the United States is:

Federal Reserve Notes.

Reading Data from file

File myFile = new File("name.txt"); Scanner inputFile = new Scanner(myFile); *Use File class and Scanner Class

v,n,v,v,v,n

For each of the following, indicate whether one should use a void module (V) or a nonvoid (N) to solve the problem. (1/2 pt each) 1. __ A module that explains how one would play a game. 2. __ A module that will receive two numbers and returns the smaller of the two numbers. 3. __ A module that will receive the radius of a circle and return to the caller the area and the circumference of the circle. 4. __ A module that will return the total cost of a purchase, given the price of an item, how many items purchased and the tax rate in the given area. 5. __ A module that receives two items and returns the results of the two items switched. 6. __ A module that will return the number of yards when the number of inches is sent to the module.

________ is a class in the .NET Framework that is similar to an array. Unlike an array, a ______ object's size is automatically adjusted to accommodate the number of items being stored in it.

List, List

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

Four score and seven years ago

Which of the following is not a part of a UML state diagram?

Fractions beside each state indicating the likelihood of entering that state.

Ptr=&num; Ptr=new int;

Given int num, *Ptr; show two different ways to give Ptr a value

true

Given the following header: void showArray(const int array[ ] [COLS], int rows) if COLS is a global named constant which is set to 4, then the function can accept any two dimensional integer array, as long as it consists of four columns. (True or false)

900, 580

Given the following, determine the address for each of the following: (show all work!!!!!!!!!) int List[30]; where the base address is 800 and each integer uses 4 bytes. double score[15]; where the base address is 500 and each double uses 8 bytes. 1. List [25] 2. score [10]

42, 1000, 42, 1004

Given the following: int num, *ptr1, *ptr2; (3 pt) The address location of num is 1000. The address location of ptr1 is 1004. Show what will be printed out given the following code: num = 42; ptr1 = &num; ptr2 = ptr1; cout<<num<<" " <<ptr1<<" "<<*ptr2<<" "<<&ptr1<<endl;

<cstring>

Header file needed to access c-string operations

Array

Holds multiple values of the same data type simultaneously

false

If a program compiles with no errors, then it will run with no errors(true or false)

Abstract

If a property or method consists of just a header with no code following it, it is referred to as being ______.

0

If an array is partially initialized, the uninitialized elements will be set to ___.

a

If you leave out the size declarator in an array declaration: a. you must furnish an initialization list b. you are not required to initialize the array elements c. all array elements default to zero values d. your array will contain no elements.

Member

In a code object when a variable is declared with the Private keywork they are called ________ variables.

Function header line

In a function header line you are required to furnish: data types of parameters, data type of return value, name of function, and variable names of parameters.

Set

In order to write a value to a Private variable there must be a _____ property block.

true

In the average case, an item is just as likely to be found near the beginning of an array as near the end. true or false?

7.3 What are off-by-one errors?

In working with arrays, a common type of mistake is the off-by-one error. This is an easy mistake to make because array subscripts start at zero, rather than one. p. 388

Starting values for an array may be specified with an ____ list.

Initiialization

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.

true

It is possible for a function to have parameters with default arguments and some without.

false

It is possible to output the contents of all members of a structure variable using a cout << statement followed by the name of the structure variable (True or False)

Create a List object that hold integers referenced by the numberList variable.

List <int> numberList = new List <int> ( );

enque- add to rear of queue deque- remove from front of queue createque- create circular que with a buffer IsQueEmpty- check if queue is empty(when front==rear)

List and explain the four functions that can be performed on any queue

The individual elements of an array are accessed and indexed by ______.

Literal or named constant

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

Literals

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

Logic errors

column processing

Manipulating the values within a given column of a matrix

row processing

Manipulating the values within a given row of a matrix

What does punctuation do?

Marks the beginning or end of a statement or separate items in a list

To pass an array to a function, pass the__of the array.

Name

What are programmer defined identifiers?

Names made up by the programmer that refer to variables or programming routines

Can you use the == operator to compare two array reference variables and determine if the arrays are equal?

No

Does this copy array1 to array2? int[ ] array1 = { 2, 4, 6, 8, 10 }; int[ ] array2 = array1;

No

Can you access all members of a Union at the same time?

No since they share the same memory, only one value is valid at any given time.

Can return functions return an array?

No. Any changes to an array must be returned via reference parameters.

Does the computer issue a warning when indexes go out of bounds?

No. Whatever value is at that position in memory is modified, leading to strange, unwanted results.

false

One can set one stack equal to another stack, by simply setting the one stack variable equal to the other stack variable(t or f)

true

One can set one structure equal to the contents of another structure of the same type in a single assignment statement(True or False)

true

One should have another person test their module(true or false)

true

One should not dereference a NULL pointer(true or false)

Operator

Operators perform operations on one or more operands. An operand is usually a piece of data, like a number.

How to initialize an array during declaration

Place the initializing values in braces. Example: double sales[5] = {12,32,16,23,45};

Pointer

Pointer is a variable that contains the address of another variable

What will the following program segment do? int counter = 1; do { cout << counter << " "; } while ( ++counter <= 10 );

Print the numbers 1 through 10.

Writing in File

PrintWrite outputFile = new PrintWriter("name.txt"); outputFile.println("Mark"); ... outputFIle.close();

Computers can do many different jobs because they can be _________?

Programmable

Words or names defined by the programmer are called ______.

Programmer Defined Identifiers

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

Punctuation

To store a value in a vector that does not have a starting size, or that is already full, use the___ member function.

Push_back

Create a Random object in memory that returns a reference named rand to that object.

Random rand = new Random( );

Declare a variable named rand that will reference an object of type Random.

Random rand;

7.2 How do you read data from a file to an array?

Reading the contents of a file into an array is straight forward. - Open the file and use a loop to read each item from the file, storing each item in an array element. - The loop should iterate until either the array is filled or the end of the file has been reached. p. 384

An activity diagram for modeling the actions involved in executing a balance inquiry transaction using the BalanceInquiry object should not include:

Receiving the user's main menu input indicating a desire to inquire the amount of his or her balance.

false

Regardless of array data type, the first element of an array always contains a value of zero. true or false?

If you know the value of the item that you want to remove from a List, but you do not know the item's index, you can use the ______ method.

Remove

You can use the _______ method to remove an item at a specific index in a List.

RemoveAt

strcmp(s1, s2)

Returns a value < 0 if s1 is less than s2 Returns 0 if s1 and s2 are the same Returns a value > 0 if s1 is greater than s2

strlen(s)

Returns the length of the c-string s, excluding the null character

It's best to think of a two-dimensional array as having___and ___.

Row's; Columns

Primary

Rule of Referential Integrity: Each value in the foreign key must also appear as a value in the ________-key field of another table.

Syntax

Rules that must be followed when constructing a program. Syntax dictates how key words and operators may be used, and where punctuation symbols must appear.

What is syntax?

Rules that must be followed when writing a program

The two types of containers defined by the STL are ___________ and______________.

Sequence container and associative container

true

The amount of memory used by an array depends upon the array's data type and the number of elements in the array. true or false?

The number inside the brackets of an array definition is the _____, but the number inside an array's bracket is an assignment statement, or any other statement that works with the contents of the array, is the___.

Size declaratory; subscript

sentinel

Special value that tells a loop when to stop. Usually placed at the end of a list

The ____________________ is a collection of programmer-defined data types and algorithms that you may use in your programs

Standard Template Library (or STL)

The____is a collection of programmer-defined data types and algorithms that you may use in your programs.

Standard template library (STL)

By using the same _________ for multiple arrays, you can build relationships between the data stored in the arrays.

Subscript

By using the same___ for multiple arrays, you can build relationships between the data stored in the arrays.

Subscript

Each element of an array is accessed and indexed by a number known as a____.

Subscript

0

Subscript numbering in C++ always starts at ___.

C++ allows you to partially initialize an array.

T

If you add a value to a vector that is already full, the vector will automatically increase its size to accommodate the new value.

T

The subscript of the last element in a single-dimensional array is one less than the total number of elements in the array.

T

The values in an initialization list are stored in the array in the order they appear in the list.

T

To calculate the amount of memory used by an array, multiply the number of elements by the number of bytes each element uses.

T

To pass an array to a function, pass the name of the array.

T

To use a vector, you must include the vector header file.

T

Vectors can report the number of elements they contain.

T

When an array is passed to a function, the function has access to the original array.

T

You can use the [] operator to insert a value into a vector that has no elements.

T

You cannot use the assignment operator to copy ones array's contents to another in a single statement.

T

IT's best to think of two-dimensional arrays as having rows and columns.

T. damn straight

You can write programs that use invalid subscripts for an array.

T; C++ has no bound checks, can accidentally cause the program to write pas the end of an array.

The contents of an array element cannot be displayed with cout.

T; must use a loop

To define a two-dimensional array, _________ size declarators are required

TWO

Control

Text boxes, list boxes, and buttons are examples of _______ objects.

An example of a unary operator is:

The ! logical operator.

If a do...while structure is used:

The body of the loop will execute at least once.

false

The bubble sort is an easy way to arrange data into ascending order, but it cannot arrange data into descending order. true or false?

true

The constructor module is neither a void module or a nonvoid module (true or false)

char

The contents of an array of type_____ can be displayed with the cout operator.

containers

The data types that are defined in STL. They store and organize data.

Default

The default name of the first form/page in an ASP.NET Web Program is named ______.

false

The designer of a module is responsible to make sure that the preconditions are met(true or false)

7.2 What is the difference between the array size declarator and a subscript?

The number inside the brackets of an array definition is the size declarator. The number inside the brackets of an assignment statement, or any statement that works with the contents is a subscript. p. 380

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

The number is number

Size

The number of elements in an array, n+1, is the _______ of the array.

Subscripts (indexes)

The numbers inside the parenthesis of an array variable are called _______.

void showValues(int nums[4][]) { for (rows = 0; rows < 4; rows++) for (cols = 0; cols < 5; cols++) cout << nums[rows][cols]; }

The parameter must specify the number of columns, not the number of rows.

Data Normalization

The process of avoiding redundancy by splitting up a table into two or more tables is called _______ _________.

true

The purpose of using #ifndef and #endif when creating a class is to make sure that code that might be copied(True or false)

Rule of Entity Integrity

The requirement that no record may have a null entry in a primary key and that entries for primary keys be unique is called the ____ __ _______ ______.

body of the loop

The series of statements that are executed if the loop condition evaluates to "true". Can be a single statement or a compound statement.

What is the difference between a size declarator and a subscript?

The size declarator is used in a definition of an array to indicate the number of elements the array will have. A subscript is used to access a specific element in an array.

Integer, 0

The size declarator must be a(n) ___ with a value greater than ___.

false

The statement int scores[ ] = { 1, 2, 3, 4 }; is invalid because the size has not been declared(true or false)

When using a string variable as the name of a file...

The string must be converted to a c-string first.

What does & do?

The unary operator & gives the address of a variable and array elements; it cannot be applied to expressions, constants, or register variables.

After a "continue" statement is executed in a for loop, what is the next statement executed?

The update condition

Static

The value in a(n) _____ local variable persists between function calls.

Binary Search

The values must first be sorted in an order. This algorithm then starts its search in the middle of array. If that element happens to contain the desired value, then the search is over. Otherwise, the value in the middle element is either greater than or less than the value being searched for. The procedure is repeated until the value is found or there are no more elements to test.

Which are the Members of a Structure.

The variables named in the declarations within the braces.

Sequence

The vector data type is a(n) ___ container.

When you partially initialize an array, what happens to the uninitialized values?

They are automatically initialized to 0.

subscript

To access an array element, use the array name and the element's _____?

false

To assign the contents of one array to another, you must use the assignment operator. true or false?

clear()

To completely clear the contents of a vector, use the ___ member function.

2

To define a two-dimensional array, ___ size declarators are required.

The purpose of a memory address is:

To identify the location of a byte in memory

Address

To pass an array to a function, pass the ___ of the array.

address

To pass an array to a function, pass the ___ of the array.

const

To prevent an array parameter from being changed in a module, one should put ___ before the array declaration.

push_back()

To store a value in a vector that does not have a starting size, or that is already full, use the ___ member function.

Assuming myValues is an array of int values, and index is an int variable, both of the following statements do the same thing cout<<myValue[Index]<<endl; cout<<*(myValues + index)<<endl;

True

T OR F: A CPU really only understands instructions that are written in machine language.

True

T OR F: A vector object automatically expands in size to accommodate the items stored in it.

True

T OR F: An individual array element can be processed like any other type of C++ variable.

True

T OR F: An output file is a file that data is written to.

True

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

True

T OR F: C++ does not have a built in data type for storing strings of characters

True

T OR F: Each individual element of an array can be accessed by the array name and an element number, called a subscript.

True

T OR F: Escape sequences are always stored internally as a single character.

True

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

True

T OR F: Software engineering is a field that encompasses designing, writing, testing, debugging, documenting, modifying, and maintaining computer programs.

True

T OR F: The cin >> statement will stop reading input when it encounters a newline character.

True

T OR F: The update expression of a for loop can contain more than one statement, e.g. counter++, total+= sales.

True

syntax, driver, 120, subscript, const, search, small, large sorted, system("pause"); O(n^8), psuedocode, flowchart, one, green, addition, 6, actual, formal, parameter, return statement, index, parallel, 0, name, date, pretest, 0-24, work done, address of first location,

a. Misspelling the name of a variable in a C++ program is an example of a ___ error b. If one wants to test their module and the main has not been created, one can test their module by using a dummy main which is called a ___. c. If there are 120 elements in a sorted list, the maximum number of comparisons that will be needed for the linear search is ___. d.To access an array element, use the array name and the element's ___. e. If one wants to guarantee that an array location is not modified in a module, one should put ___ before the array declaration in the formal parameter list. An example of a module where this might be done is ___. f. One should use a linear search with ___ lists and a binary search with ___ lists. g. To make sure that the output of a program does not close quickly in our C++ compiler, one needs to insert the command ___ before the return 0; statement. h.The order of an algorithm that evaluates to 6x^8 - 25x^9 - 1000 is ___. i.Two ways to represent an algorithm are ___ and ___. j. Ideally, a module should have ___ job to do. k.In our compiler, comments are indicated by the color ___. l.The work done in an algorithm that finds the average of the elements in an array is ___. m.Given: int List[ ] = { -2, -1, 12, 34, -100, 42, 68}; what is the location of 68 in the array? n.The parameter list associated with the caller is called the ___ parameter list and that associated with the module itself is called the ___ parameter list. o. Two ways in which a module might return a value back to the caller are ___ and_____ p. By using the same ___, you can build relationships between data stored in two or more arrays of different types. This is an example of the use of ___ arrays. q. If an array is partially initialized, the uninitialized elements will be set to ___. r. Two things found in the prologue of a program are ___ and ___. s. The while loop and the for loop are examples of ___ loops. t. Given: char name[25]; what is the valid range for the subscripts? u. When comparing algorithms, the only thing that remains constant from one algorithm to another is ___. v. When one passes an array name as an argument to a function, one is actually passing the ___ of the array.

When writing functions that accept multi-dimensional arrays as arguments, _____ must be explicitly statement in the parameter list

all but the first dimension

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

all but the first dimension

false

all nested if-else statements can be converted into switch statements (T/F)

auto declaration

allows a programmer to declare and initialize a variable without specifying its type

sentinel

an arbitrary value used to stop the execution of a loop

array overflow

an attempt to store data in an array element with a subscript >= the array size

decision maker

an expression in an if statement or a loop which determines whether to execute the statement that follows it

When you pass an array as an ___________ to a method, the method has ________ _________ to the array through its ________ ________.

argument, direct access, parameter variable

An array can be passed as an ________ to a method. To pass an array, you pass the ________ that __________ the array.

argument, variable, references

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

argument; parameter

mean

arithmetic average

An ______ allows you to store a group of items of the same data type together in memory.

array

Union

array1._______(array2).ToArray is an array containing the elements of array1 with array2 appended, without duplicates.

Except

array1._______(array2).ToArray is an array containing the elements of array1 with the elements of array2 removed.

Syntax for accessing an array component

arrayName[index] This accesses the value stored at the position indicated by "index" in the array called arrayName

Syntax to access a particular element in an array

arrayName[index];

Unlike regular variables, these can hold multiple values.

arrays

false

arrays can be returned from a function (T/F)

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

Constructors

automatically called when object is created; perform initialization tasks and initalize instance fields

ArrayList Class

automatically expands wehn a new item is added or shrinks when removed. Indefinte size

variance

average squared deviation from the mean for a data set

functional decomposition

breaking a large, complex problem down into smaller pieces

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

buffer

null character

character '\0' that marks the end of a c-string

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

cin >> length >> width >> height;

In memory, an array's elements are stored in _________ locations.

consecutive

In a program you need to store the identification numbers of 10 employees (as ints) and their weekly gross pay (as doubles). Display their weekly pay.

const int SIZE = 10; int id[SIZE]; // To hold ID numbers double weeklyPay[SIZE]; // To hold weekly pay for (int i = 0; i < SIZE; i++) { cout << "The pay for employee " << id[i] << " is $" << fixed << showpoint << setprecision(2) << weeklyPay[i] << endl; }

syntax for declaring array parameter

const int arrayName[ ]

The arrays numberArray1 and numberArray2 have 100 elements. Write code that copies the values in numberArray1 to numberArray2.

const int size = 100; for(int i = 0; i < size; i++) numberArray1[i] = numberArray2[i];

names is an integer array with 20 elements. Write a for loop that prints each element of the array.

const int size = 20; for(int i = 0; i < size; i++) cout << names[i] << endl;

alternate syntax for declaring array parameter

const int* arrayName

An array's size declarator must be a(n)_________ with a value greater than _________.

constant integer expression, zero

An array's size declarator must be a _____ with a value greater than _____.

constant interger; zero

global

constant variables that might be used in different functions should be ______

A(n)__________ is a variable that "counts" the number of times a loop repeats.

counter

If you want to make a copy of an array, you must _____ the second array in _____ and then ______ the individual elements of the first array to the second. This is usually best done with a _____.

create, memory, copy, loop

In a function header, you must furnish:

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

syntax for declaring n-dimensional array

dataType arrayName [intExp1][intExp2]...[intExpN];

Syntax for fully initializing an array during declaration

dataType arrayName[ ] = {arrayValue1, arrayValue2, ...};

Syntax for partially initializing an array during declaration

dataType arrayName[arraySize] = {arrayValues};

Syntax for declaring a one-dimensional array

dataType arrayName[arraySize];

Syntax for declaring a one-dimensional array

dataType arrayName[intExp]; example: int numbers[5];

how to declare a two-dimensional array

dataType arrayName[rows][columns];

Free

deallocates space pointer to by 'p'; It does nothing if 'p' is NULL. 'p' must be pointed to space previously allocated by calloc(), malloc() or realloc(). void free(void *p)

How to use an array when you are unsure what size you will need

declare an array much larger than you think you will need, then fill it with the needed values, being careful to avoid array overflow

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

default

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

default

A function ____ contains the statements that make up a function.

definition

which of the following statements deletes memory that has been dynamically allocated for an array?

delete [] array;

posttest loop

do...while loop executes, then checks condition to see if it should execute again.

The individual values contained in array are known as

elements

The storage locations in an array are known as ________.

elements

This vector function returns true if the vector has no elements.

empty

If you attempt to store data past an array's boundaries, it is guaranteed that the complier will issue an error

false

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

false

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

using a binary search, you are more likely to find an item than if you use a linear search

false

During which stage does the central processing unit retrieve from main memory the next instruction in the sequence of program instructions?

fetch

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

flag

7.1 Valid array definitions

float temperatures[100); // An array of 100 floats string names[10]; // Array of 10 string objects long units[50]; // Array of 50 long integers double sizes[1200]; // Array of 1200 doubles p. 378

The __________ loop is ideal for situations that require a counter.

for

Which of the following for headers is not valid?

for ( int i = 0; int j = 5; ; i++ ).

syntax for range-based for loop

for (dataType identifier : arrayName) -----statements;

Syntax of for loop

for (initial; loop condition; update) statement;

finding 2D length field

for (int row=0; row < numbers.length; row++) for (int col=0; col < numbers[row].length; col++)

An array can easily be stepped through by using a

for loop

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

for loop

Since arrays are composed of several values, working with them requires the use of...

for loops

Code a for loop that displays each item in a nameList object.

for(index = 0; index<nameList.Count; index++){ MessageBox.Show(nameList[index]); }

The _____ loop is designed to work with a temporary, read-only variable known as the _______ ________.

foreach, iteration variable

This is a statement that causes a function to execute.

function call

Every complete C++ program must have a _________

function named main

true

functions may have multiple return statements (T/F)

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

getline(cin, address);

5

given the following code what is the final value of i int i; for(i=0;i<=4;i++) { cout<<i<<endl; }

A _____ variable is declared outside all functions.

global

properties of constructors

have same name as class; no return type (not even void); do not return any values; typically public

If a function does not have a prototype, default arguments may be specified in the function _____.

header

What are some examples of programmer defined identifiers?

hours rate pay

setDisplay();

how do you call the following function? void setDisplay();

index

in the expression cout<<score[i]<<endl; i is called the _______.

true

if a function is expecting a pass by reference parameter you can pass an index variable from an array of the same base type to the function(T/F)

1005

if p1 is an integer pointer that is pointing to memory location 1001, and an integer takes 4 bytes then (p1+1) evaluates to

3.4

if the variable x has the original value of 3.4, what is value of x after the following cout<<static_cast<int>(x);

Default constructor

if you do not write a constuctor java provides a default. all numeric fields set to 0, all boolean set to false, all refernce variables are null; JAVA only provides it when you do not write any constructor for a class

display(cout);

if you have a class with a member function called display(ostream& out), that will send the values in the class to the parameter stream, and you need to call that function from within another member function how would you call it to print the data to the screen

(2>number || number>5)

if you need to write a do while loop that will ask the user to enter a number between 2 and 5 inclusive and will keep asking until the user enters a correct number, what is the loop condition?

an array with no elements is

illegal in C++

The statement int grades[ ] = { 100, 90, 99, 80}; shows an example of

implicit array sizing

The statement: int grades[ ] = { 100, 90, 99, 80}; shows an example of

implicit array sizing

the statement int grades[] = {100,90,99,80} shows an example of

implicit array sizing

Reading URL

import.java.net.URL; ... URL nameURL = new URL("www..."); Scanner list = new Scanner(nameURL.openStream());

private

in a class all members are ___________ by defualt

public

in a struct all members are _______ by default

member names

in a structure definition the identifiers declared in the braces are called

iomanip

in order to use the stream manipulators you must include the ______ library

type

in the expression double score[10]; double is called the ______ of the array

When the "continue" statement is executed in a loop, what happens to the update statement?

in while and do...while loops, the update may not execute. in a for loop, the update always executes.

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

initialization

Starting values for an array may be specified with a(n) _________ list.

initialization

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

initialization list

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

initialization list

If the size declarator of an array definition is omitted, C++ counts the number of items in the _________ to determine how large the array should be.

initialization list

If the size declaratory of an array definition is omitted, C++ counts the number of items in the ____ to determine how large the array should be.

initialization list

7.4 You must provide an _______ if you leave out an array's size declarator.

initialization list. p. 394

Inside the for loop's parentheses, the first expression is the __________ , the second expression is the __________ , and the third expression is the __________.

initialization, test, update

Arrays may be ____ at the time they are ____

initialized, declared

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

input validation

Exceptions

insterted throws clause in method header: public static void main(String[] args) throws IOException

Look at the following function prototype. int myFunction(double); What is the data type of the funtion's return value?

int

Look at the following function prototype: int myFunction(double); What is the data type of the function's return value?

int

Write code to allocate space on the heap for an array of ints of size 10.

int *array=(int *)malloc(10*sizeof(int)); if (array==NULL) handle error; //when we are done we need to free the space free(array); array=NULL;//to make sure the freed pointer isn't used anymore.

Create a pointer 'pa' that points to a[0].

int *pa; pa=$a[0]

Define two arrays that may be used in parallel to store the 10 ID numbers and gross pay amounts.

int ID[10]; double Emp[10];

Which of the following options declares an integer variable?

int age;

What makes an array definition valid?

int array[10];

Which of the following is a valid C++ array definition?

int array[10];

switch can be used to test:

int constants.

How can a program read command line arguments? For example how can we get the information from a call such as ./program joe sventek ?

int main(int argc, char *argv[]); argv is an array of pointers to strings. argc is the number of pointers to strings. so in our case argc==3 is true. argv[0]="./program" argv[1]="joe" argv[2]="sventek"

Declare an array with 100 rows, each with 50 elements.

int matrix[100][50];

Initialize a 2 dimensional array with the first row being 1,2,3,4 and the second being 5,6,7,8

int matrix[2][4]={ {1,2,3,4},{5,6,7,8} };

variable declaration

int myValue is called a _______________

int numberArray[9][11]; a statement that assigns 145 to the first column of the first row of this array. a statement that assigns 18 to the last column of the last row of this array

int numberArray[0][0] = 145; int numberArray[8][10] = 18;

finding array length

int size = arrayName.length;

Write code for strcmp so that it returns <0 if s<t, 0 if s==t, >0 if s>t.

int strcmp(char *s, char *t){ int i; for (; *s==*t; s++, t++) if (*s=='\0') return 0; return *s-*t; }

write a function that takes an array object and returns its size. The array type is string.

int strlen(char *s){ char *p=s; while(*p++!='\0'){ ; } return p-s; }

2

int v1=2, v2=-1,*p1,*p2; p1=&v1; p2=&v2; p2=p1; cout<<*p2<<endl;

Write code that sums all the elements in the array and stores the sum in the variable total

int values[10][20]; int row, col; // loop counter float total = 0.0 // Accumlator for(row = 0, col = 0; row < 10, col < 20; row++, col++) total += values[row][col]

Consider the following array definition: int values[5] = { 4, 7, 6, 8, 2 }; What does each of the following statements display? cout << values[4] << endl; __________ cout << (values[2] + values[3]) << endl; __________ cout << ++values[1] << endl; __________

int values[5] = { 4, 7, 6, 8, 2 }; cout << values[4] << endl; 2 cout << (values[2] + values[3]) << endl; 14 cout << ++values[1] << endl; 8

Power of 2

is 2 raised to the power of some number. The way to calculate the average number of comparisons for a binary search.

true

it is acceptable to have both pass by value and pass by reference parameters in the same function declaration (T/F)

true

it is legal to declare more than one variable in a single statement

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

local

RemoveAt

lstBox.Items._______(n) Method: Delete item having index n.

Remove

lstBox.Items._______(strvalue) Method: Delete first occurence of this string value.

Variables are also known as:

lvalues, but can be used as rvalues.

Which of the following is not one of the C++ control structures?

main

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

memory address

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

memory address

base address

memory location of the first array component

parts of a method Header

method modifiers (public or static) Return type (void or data type from value-returning method) Method name Parentheses(contain nothing of a list of one or more variable declarations)

proceures in an object

methods

accessors or getters

methods that retrieve the data of fields

Objets

mix of data and procedures that manipulate that data

Selection Sort

moves items immediately to their final position in the array. The smallest value in the array is located and moved to element 0. This process continues until all of the elements have been place in their proper order.

Creating an Arraylist

need: import java.util.ArrayList; ArrayList<String> nameList = new ArrayList<String>(); name in <> determines objects it can hold

A loop that is inside another is called a(n) __________ loop.

nested

The _____ keyword returns a reference to the object that it creates.

new

The ______________ is automatically appended to a character array when it is initialized with a string constant.

null terminator

the ____ is automatically appended to a character array when it is initialized with a string constant

null terminator

When you are working with a reference type, you are using two things: An _____ that is created in ______. A _______ that references the object.

object, memory, variable

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

scores [2]

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

scores[2]

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

ofstream

Which of the following is false?

ontinue and break statements may be embedded within all C++ structures.

member

open is a ________ function of the ofstream and ifstream class

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;

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

overflows

Pointer p points to a[0]. Make it point to i elements beyond its current position.

p+i;

Make p point to c.

p=$c

Now make pointer pa point to the next location in the array 'a'. i.e. a[1]

pa++;

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

A loop that evaluates its test expression after each repetition is a(n) __________ loop.

posttest loop

An alternative way to access the members of the structure that pp points to?

pp->x and pp->y

When the increment or decrement operator is placed before the operand (or to the operand's left), the operator is being used in __________ mode.

prefix

Value-returning method

preforms a task, but also sends a value back to the code that called it.

passing arguments

primitive types are passed by value--only a copy of the value is passed to the parameter

binary search

search method for looking through ordered arrays. Begins at the middle of the array and compares that value with the sought value. If higher or lower, searches the middle of the corresponding section. This process continues until the value is found or the program determines the value is not in the list.

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

push_back

calling object cant be changed

putting the keyword const after the function declaration guarantees ______.

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

range variable

When you use either the ___ or _____ keywords with an array parameter, the receiving method not only has access to the array, but it also has access to the reference variable that was used to pass the array.

ref, out

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

reference

Two steps required to create and use a reference type object: You declare a ________ _________. You create the ______ and associate it with the _______ ________.

reference variable, object, reference variable

When passing whole arrays to a function, C++ automatically treats them as...

reference variables

Because arrays are always passed by _________, a _______ that receives an array as an argument has access to the ______ _______, not a _______.

reference, method, actual array, copy

int[ ] array1 = { 2, 4, 6, 8, 10 }; int array2 = array1; The second statement does what? This does not make a copy of the array referenced by array1. Rather, it assigns the ______ that is in array1 to array2. Both array1 and array2 variables will reference the _____ _______. This type of assignment operation is called a _____ _______. Only a ________ to the array object is copied, not the ________ of the array object.

reference, same array, reference copy, reference, contents

Its best to think of a two-dimensional array as having _________ and _________.

rows and columns

A two-dimensional array can be viewed as ___________ and _____________.

rows, columns

A(n) __________ is a sum of numbers that accumulates with each iteration of a loop.

running total

What part of a two-dimensional array size MUST be included in the declaration?

the number of columns must be included in a two-dimensional array declaration.

row order form

the order in which C++ stores two-dimensional matrices. The first row stored first, then the second, then the third, etc.

false

the parameters listed in the function declaration are considered global variables

sorting

the process of organizing the contents of an array in a particular order

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

the same data type

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

the same data type

cout<<*ptr what does it output?

the value stored at the address contained in ptr

2D array elements

to access one element in array must use both subscripts: socres [2][1] =90; programes process 2D arrays with nested loops

A pointer can be used as a function parameter, giving the function access to the original argument

true

A vector object automatically expands in size to accommodate the items stored in it

true

Given a search problem on a sorted array, Binary Search is more efficient than Linear search

true

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

two or more

parallel arrays

two or more same-size arrays that store related information in corresponding cells

A___ ____ array is like several arrays of the same type put together.

two- dimensional

Define a union that can hold an integer, a float and a character pointer. Call it u_tag and create an instance of it "u"

union u_tag{ int ival; float fval; char *sval; }u;

7.5 How do you decrements a value stored in an array?

use the following statement. amount[count]--; p. 394

To disable the "left" function...

use: unsetf(ios::left)

for loop (indexed loop)

used to simplify the writing of counter-controlled loops; consists of an initialization statement, the loop condition, and the update statement

What are some examples of keywords?

using namespace int double return

What is the easiest way to access each element of a given array

using a for loop

The most efficient form of performing componentwise operations

using a loop

after dynamically allocating an array, how do you return the memory cells to the heap?

using the delete command delete[] students;

The data types in C# and the .NET Framework fall into two categories: _____ types and ______ types.

value, reference

statistical measurements

values such as mean, median, mode, and standard deviation that can be obtained from a one-dimensional array.

false

variable names may begin with a number (T/F)

parameter variables

variable that holds the value being passed into a method; by using parameter variables in method declarations, you can design your own methods to accept data

local

variables defined inside a set of braces are said to be _______ to that block of code

local

variables that are detected inside a function are said to be _____ to that function

Write a definition statement for a vector named frogs . frogs should be an empty vector of int s.

vector <int> frogs;

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;

true

you must use a width statement before each variable you want to output with a certian width.(T/F)


Set pelajaran terkait

Med-Surge. Evolve chapter 47, 48, 49.

View Set

Spanish 1B: Unit 2: Chapters 6-10

View Set

Chapter 9 Introduction to the t Statistic

View Set

Ch. 5 Quiz Q's "Foundations of Employee Motivation"

View Set

28/14 The Female Reproductive System

View Set

MCAT Physics & Math - Chapter 8 - Light & Optics

View Set