CMPS Final

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

*false*

*if* (x > 0 && <= 100) correctly determines whether x contains a value in the range of 0 through 100, inclusive.

call.

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

private.

If you do not declare an access specification, the default for members of a class is ___.

*false.*

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

•an appropriate range. •reasonableness. •division by zero, if division is taking place.

What should input values always be checked for?

two or more.

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

structure.

a C++ class is similar to a ___.

data type.

a class is a ___ that is defined by the programmer.

function.

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

definition

a function ___ contains the statement that make up the function

prototype

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

only one.

a function can have no parameters, one parameter, or many parameters and can return ________ value.

called.

a function is executed when it is ___.

*false.*

a while loop is somewhat limited because the counter can only be incremented by one each time through the loop.

*true.*

a while loop's body can contain multiple statements, as long as they are enclosed in braces.

if statement.

an expression that has any value other than 0 is considered true by what kind of statement?

*true.*

an initialization expression may be omitted from the for loop if no initialization is required.

*true*

as a rule of style, when writing an if statement you should indent the conditionally-executed statements.

myCar .accelerate();

assume that myCar is an instance of the Car class and that the Car class has a member function named accelerate. Which of the following is a valid call to the accelerate member function?

*false.*

class objects can be defined prior to the class declaration.

yes.

do both statements perform the same if statements? *1* if (sales > 100000) comissionRate = 0.15; *2* if (sales > 100000) commissionRate = 0.15;

answer = 2

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

a < 5 ? b = 12 : d = 30;

given the if/else statement, what performs the same operation? if (a < 5) b = 12; else d =30;

function header.

if a function does NOT have a prototype, default arguments may be specified in the ___.

persist.

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.

*false.*

if the expression on the left side is false, then the expression on the right side will not be checked. (a > b) && (c == d)

*true.*

if the expression on the left side is true, then the expression on the right side will not be checked. (a > b) | | (c == d)

*true.*

if you want to stop a loop before it goes through all of its iterations, the break statement may be used.

attributes; methods

in OOP terminology, an object's member variables are often called its ___ and its member functions can be referred to as its behaviors or its ___.

data; functions.

in a procedural program you typically have ___ stored in a collection of variables and set of ___ that perform operations on the data.

*true.*

in object-oriented programming, the object encapsulates both the data and the functions that operate on the data.

document.

it is good programming practice to ___ your functions by writing comments that describe what they do.

dot operator.

members of the class object are accessed with the ___.

*true.*

more than one constructor function may be defined for a class.

data; functions

objects are created from abstract data types that encapsulate ___ and ___ together.

infinite loop results.

something within a while loop must eventually cause the condition to become false or a(n) _____.

*false.*

the condition that is tested by a while loop must be enclosed in parentheses and terminated with a semicolon.

the class

the constructor function always has the same name as ___.

*false.*

the default section is required in a switch statement.

trailing else.

the default section of a switch statement performs a task similar to the ___ portion of an if/else if statement.

*false*

the increment and decrement operators can be used in mathematical expression, however, they cannot be used in relational expression.

at least once.

the statements in the body of a while loop may never be executed while the statements in the body of a do-while loop will be executed ___.

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

the two important parts of a while loop are the expression that's tested for a true or false value and ___.

static local.

the value in a ___ variable persists between function calls.

static.

the value in this type of variable persists between function calls.

pre-test loop.

the while loop is a ____.

private and public.

what are examples of access specifiers are the key words?

•a global variable can have the same name as a variable that is declared locally within a function. •a global variable is declared in the highest-level block in which it is used. •if a function contains a local variable with the same name as a global variable, the global variable's name takes precedence within the function. •a global variable is accessible only to the main function.

what are some true statement about global variables?

*++* and *--*

what are the operators that add and subtract on from their operands?

a function call.

what causes a function to execute?

to increase a value.

what does increment mean?

exit ()

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

information that is passed to a function.

what is a argument?

a member function that is automatically called when a class object is created.

what is a constructor?

loop.

what is a control structure that causes a statement or group of statements to repeat?

information that is received by a function.

what is a parameter?

sentinel.

what is a special value that marks the end of a list of values?

break statement.

what is a statement that causes a loop to terminate early?

continue statement.

what is a statement that may be used to stop a loop's current iteration and begin the next one?

counter variable.

what is a variable that is regularly incremented or decremented each time a loop iterates?

when a program lets the user know that an invalid choice has been made.

what is input validation?

null statement.

what is it called if you place a semicolon after the test expression in a while loop?

none, it doesn't have a return type.

what is the destructor function's return type?

the program will not compile.

what is the output of the code? #include <iostream> using namespace std; class TestClass { private: int val; void showVal () { cout << val << endl; } public: TestClass (int x) { val = x; } }; int main () { TestClass test (77); test.showVal (); return 0; }

77

what is the output of the code? #include <iostream> using namespace std; class TestClass { public: TestClass (int x) { cout << x << endl; } TestClass () { cout << "Hello!" << endl; } }; int main () { TestClass test (77); return 0; }

Hello!

what is the output of the code? #include <iostream> using namespace std; class TestClass { public: TestClass (int x) { cout << x << endl; } TestClass () { cout << "Hello!" << endl; } }; int main () { TestClass test; return 0; }

1.

what is the output of the 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; }

23.

what is the output segment of the code if the value $ is input by the user? 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;

1 6 3

what is the output?

result = 3.

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

1 1 ... and on forever.

what is the output? n = 1; while (n <= 5) cout << n << ' '; n++;

default argument.

what kind of argument is passed down to a parameter when the actual argument is left out of the function?

global variable.

what kind of variable is declared outside all functions?

•the names of parameter variables. •the data type of the return value. •the name of the function. •the data type of each parameter.

what must be included in a function header?

prefix increment.

what operator increments the value of its operand and then uses the values in context?

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

what statement allows you to properly check the char variable code to determine whether it is equal to a C and then output *This* *is* *check*?

return.

what statement causes a function to end?

switch statement.

what statement uses the value of a variable or expression to determine where the program will branch to?

private.

what type of member function , may only be called from a function that is a member of the same class?

local variable.

what type of variable is defined inside a function and is not accessible outside the function?

default.

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

7

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

7

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

6

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

7

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

5

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

6

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

class name followed by the scope resolution operator.

when a member function is defined outside of the class declaration, the function name must be qualified with the ___.

incline.

when the body of a member function is defined inside a class declaration, it is said to be ___.

prefix mode.

when the increment operator preceds its operand, as*++num*, the expression is in?

reference.

when used as parameters, what type of variables allow a function to access the parameter's original argument?

in their own header files.

where are class declarations usually stored?

*true.*

whereas object-oriented programming centers on the object, procedural programming centers on functions.

line 9.

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

*<*

which operator is used first in the statement? while (x++ < 10)

because of potential round-off errors.

why should you be careful when using the equality operator to compare floating point values?

break.

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

*false.*

you may not use both break and continue statements within the same set of nested loops.

*false.*

you must declare all data members of a class before you declare member functions.

*false.*

you must use the private access specification for all data members of a class.


Set pelajaran terkait

Chapter 52 Sexually Transmitted Infections

View Set

NUR 240 EAQ - Physiological Adaptation

View Set

An Introduction to Autism Spectrum Disorder

View Set