CMSC 202 - Final Exam Important Definitions and Concepts

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

[Ch4.3] What is an advantage of using the "assert" macro in C++?

"Assert" invocations can be turned off when not needed to debug a program. Turning the invocations off reduces the overhead performed by the program.

[Ch2.4] What are examples of how to read in from a file using the inputStream variable in C++?

"inputStream >> intVar" to read an integer from the file or "inputStream >> strVar" to read a string (up to a whitespace character) from the file.

[Ch7.3] What is required in a file in order to use vectors in C++?

#include <vector> using namespace std;

[Ch1.2] How much memory does the "bool" type use and what is its precision?

1 byte and N/a.

[Ch1.2] How much memory does the "char" type use and what is its precision?

1 byte and N/a.

[Ch7.1] What are the two requirements to define a constructor in C++?

1. A constructor must have the same name as the class. 2. A constructor definition cannot return a value. Moreover, no type, not even void can be given at the start of the function declaration or in the function header.

[Ch4.2] What is the complete set of rules for resolving overloading in C++?

1. Exact match 2. Matches using promotion within integer types or within floating-point types, such as short to int or float to double. (Note bool-to-int and char-to-int conversions are considered promotions within integer types.) 3. Matches using other conversions of predefined types, such as int to double. 4. Matches using conversions of user-defined types (Chapter 8) 5. Matches using ellipses ... (Not covered in this book, but not relevant)

[Ch3.3] What are the other terminologies associated with procedural abstraction in C++?

1. Functional abstraction 2. Black box principle 3. Principle of procedural abstraction 4. Information hiding

[Ch2.4] What setup is required in a program in order to read from a text file in C++?

1. Included the "fstream" library, 2. declared an "ifstream" object which is placed in the "std" namespace, and 3. connected the inputStream variable to a text file on the disk. Syntax: //1. #include <fstream> using namespace std; //2. ifstream inputStream; //3. inputStream.open("filename.txt");

[Ch5.2] What are the three components of an array in C+?

1. The address (location in memory) of the first indexed variable 2. The base type of the array (which determines how much memory each indexed variable uses) 3. The size of the array (i.e. the number of indexed variables the array has)

[Ch1.4] What are two ways to insert comments in C++?

1. with two slashes. //, which only comments all the text between the slashes and the end of the that line. 2. with symbol pairs /* and */ which comments all the text between the symbol pair and can span several lines.

[Ch1.2] What result occurs when computing integer division between ints and doubles in C++?

11/5 = 2.2 Integer division between ints looses precision by discarding the part after the decimal point and the result is not rounded no matter how large it is. Integer division between doubles works with exact precision.

[Ch2.2] What is the ratio in a switch statement between the keyword case and each label in C++?

1:1 meaning one keyword case for each label.

[Ch1.2] How much memory does the "float" type use and what is its precision?

4 bytes and 7 digits.

[Ch1.2] How much memory does the "integer" type use and what is its precision?

4 bytes and N/a.

[Ch1.2] How much memory does the "double" type use and what is its precision?

8 bytes and 15 digits.

[Ch1.2] How long can an identifier be?

A C++ identifier can be of any length, however some compilers will ignore all characters after some large specified number of initial characters.

[Ch4.1] What is a call-by-value parameter (aka mechanism) and how does it work when a function is invoked in C++?

A call-by-value parameter is a local variable. When the function is invoked, the value of a call-by-value argument is computed and the corresponding call-by-value parameter (which is a local variable) is initialized to this value. (e.g. above)

[Ch1.2] What are escape sequences in C++?

A character with a preceding backslash, \, that tells the compiler that the sequence following the backslash does not have the same meaning as the character appearing by itself.

[Ch1.5] What is a namespace in C++?

A collection of name definitions associated with a library.

[Ch6.2] What is a data type in C++?

A collection that consists of values together with a set of basic operations defined on these values. (e.g. the type int such as 0, 1, -1, 2 consists of operations such as +, -, *, /, %, etc.)

[Ch1.5] What is preprocessor in C++?

A component of C++ that handles some simple textual manipulation before the text of a program is given to the compiler.

[Ch3.2] What is a function body in C++?

A component of the function definition that follows the function header and completes the function definition by consisting up declarations and executable statements enclosed within a pair of curly braces. (e.g. the body of the main function of a program)

[Ch2.2] What is the conditional operator in C++?

A conditional inside an expression using a ternary operator (or arithmetic if).

[Ch5.2] What is an array parameter that is modified with a "const" referred to as in C++?

A constant array parameter.

[Ch7.1] What is the member function of a class that initializes member variables and all other required initializations in C++?

A constructor, which also is automatically called when an object of a class is declared.

[Ch2.2] What is the expression to determine which branch to execute of a switch statement called in C++?

A controlling expression given in the parentheses after the keyword "switch".

[Ch7.1] If a class is defined and does not include absolutely no constructors of any kind, then what is the result in C++?

A default constructor will automatically be created but it does do any initialization. Therefore, this constructor gives you an uninitialized object of that respective class type which can still be assigned to a variable of that class type.

[Ch7.1] What is a constructor that takes no arguments referred to as in C++?

A default constructor.

[Ch3.2] What is a function definition in C++?

A description of how a function computes the value it returns.

[Ch3.3] What is a black box in C++?

A figure of speech intended to convey the image of a physical device that is known for how to be used but whose method of operation (internally) is unknown.

[Ch3.2] What is required In order to make a function call in a program in C++?

A function declaration or a completely implemented function definition before the function call is executed.

[Ch3.2] What does a function definition consist of in C++?

A function header followed by a function body.

[Ch4.3] What is the "assert" macro in C++?

A function similar to those of void functions that takes one call-by-value parameter of type bool. Which means an assertion is the argument to assert macro.

[Ch6.2] What is a mutator function in a class in C++?

A function that allows you to change the data members of the class. Mutator functions usually are void functions. With mutator functions there is control and the ability to filter changes to the data members. Names for mutator functions include the word "set".

[Ch6.2] What is an accessor function in a class in C++?

A function that allows you to read the data members of the class. They do not need to return the values of each member variable, but they must return something equivalent to those values. Names for accessor functions include the word "get".

[Ch8.1] What is friend function in C++?

A function that are not members of a class but still have access to the private members of that class.

[Ch7.2] What is a static function in C++?

A function that does not access the data of any object of a class, but you want the function to be a member of that same class.

[Ch3.1] What is a predefined function in C++?

A function that that is already defined by a library you can import into your program. (e.g. square root function - sqrt() )

[Ch3.2] What is a function declaration or prototype in C++

A line of code that first specifies the type of value returned followed by the name function itself and any parameters and their types for that function. (e.g. double totalCost(int numberParameter, double priceParameter);)

[Ch5.1] What does a computer's memory consist of?

A list of numbered locations called bytes such that the number of a byte is known as its address.

[Ch2.2] What are compound statements for branching mechanisms in C++?

A list of statements enclosed in a pair of braces of a branching mechanism.

[Ch5.1] What is an array in C++?

A list of variables with a uniform naming mechanism that can be declared in a single line of code.

[Ch7.1] What is a constructor in C++?

A member function of a class that has the same name as the class. The constructor is automatically when an object of the class is declared. Constructor are used initialize objects. A constructor must have the same name as the class of which it is a member of.

[Ch4.1] What is an address in C++?

A number that is associated with a memory location of a program variable.

[Ch3.2] What are formal parameters in C++?

A placeholader to describe what arguments the function will take in for its declaration.

[Ch5.2] When an array argument is passed what is actually passed on to a function in C++?

A pointer to the first (zeroth) index variable of the array being passed.

[Ch4.3] When an assertion is converted to a Boolean expression then what can be used to check if a program satisfies the assertion in C++?

A predefined macro called "assert". (A macro is very similar to an inline function and is used just like a function is used.)

[Ch7.1] What is the initialization section of a constructor in C++?

A section of the constructor that consists of a colon followed by a list of some or all the member variables separated by commas. Each member variable is followed by its initializing value in parentheses. The initializing values can be given in terms of the constructor parameters. (e.g. DayOfYear::DayOfYear(int monthValue, int dayValue):month(monthValue), day(dayValue){ ... } )

[Ch4.3] What is a driver program in C++?

A special program to test a specific function of a program.

[Ch3.2] What is a precondition of a function declaration in C++?

A statement of what is assumed to be true when the function is called.

[Ch3.2] What is a return statement in C++?

A statement that consists of the keyword "return" followed by an expression.

[Ch3.2] What is a postcondition of a function declaration in C++?

A statement that describes the effect of the function call; i.e. what will be true after the function is executed in a situation in which the precondition holds. For a function that returns a value, the postcondition will describe the value returned by the function. For a function that changes the value of some argument variables, the postcondition will describe all the changes made to the values of the arguments.

[Ch2.3] What is an empty or null statement by itself and with regard to for loops in C++?

A statement that has just a semicolon by itself and for loop with a semi colon after the last parentheses whose body is an empty statement. (e.g. for (int count = 1; count <= 10; count++); )

[Ch4.3] What is an assertion and what are two examples in C++?

A statement that is either true or false. Assertions are used to document and check the correctness of programs. Preconditions and postconditions are examples of assertions. When expressed precisely and in the syntax of C++, an assertion is simply a Boolean expression.

[Ch6.1] How do you initialize a structure in C++?

A structure can initialized at the time at which it is declared. (e.g. Struct_Name object_name = {member_var1, member_var2, member_var3}; )

[Ch1.2] What are floating-point numbers in C++?

A type of number with a decimal point.

[Ch6.2] What is a class in C++?

A type whose values are called objects. These objects have both data and member functions which have special access to data of their object.

[Ch2.2] What is an enumeration type in C++?

A type whose values are defined by a list of declared constants of type int.

[Ch3.3] What is a global named constant in C++?

A variable declaration with the "const" modifier that appears at the beginning of a program outside the body of all the functions.

[Ch3.3] What is a global variable in C++?

A variable declaration without the "const" modifier, which is accessible to all function definitions in the file. Avoid using global variables.

[Ch1.2] What are declared constants in C++?

A variable declared using the "const" modifier.

[Ch8.1] What is the distinction between a variable and object of a class type in C++?

A variable of a class type and an object of a class type are not the same thing. An object is a value of a class type and may be stored in a variable of a class type, but the variable and the object once again are not the same thing. (e.g. In the code m3 = (m1 + m2); the variable m3 and its value (m1 + m2) are different things, just n and 5 are different things in int n = 5; or in int n = (2 + 3);

[Ch7.2] What are static variables in C++?

A variable that is shared by all the objects of a class and can be used by those objects of the class to communicate with each other or coordinate their actions.

[Ch1.2] What is an uninitialized variable in C++?

A variable with no meaningful value until a program assigns it one. Which means it has a garbage value until it is assigned.

[Ch1.2] What is a type cast in C++?

A way of changing a value of one type to a value of another type. Syntax: static_cast<Type> (Expression)

[Ch2.3] What is the comma operator in C++?

A way of evaluating a list of expressions and returning the value of the last expression.

[Ch4.2] What can default arguments represent about a function in C++?

A way of thinking of how the arguments should be established in the context of what actions the function does.

[Ch2.3] What is an infinite loop in C++?

A while, do-while, or for loop whose Boolean expression is always true and makes it run forever thus it never terminates to end the loop.

[Ch1.2] What is a modifier in C++?

A word that modifies or restricts the variables being declared. (e.g. const)

[Ch6.2] When class uses the private access specifier what kinds of member functions are required in order to access those data members in C++?

Accessors and Mutators functions.

[Ch1.2] How do you name constants properly in C++?

All capital letters with an underscore between each word. (e.g. BRANCH_COUNT)

[Ch4.2] What is the requirement when having more than one default argument in C++?

All default argument positions must be in the rightmost positions only or all arguments can have defaults.

[Ch8.1] Can a constructor return an object in C++?

Although it may thought that a constructor is a void function, a constructor constructs an object and can also be thought of as returning an object of the class.

[Ch8.1] What is a rule of thumb for return by constant value in C++?

Always return class types by "const" value unless you have an explicit reason not to do so.

[Ch6.2] What is a class whose interface and implementation are separated called in C++?

An ADT or Encapsulated class.

[Ch6.2] What is data type also called in C++?

An abstract data type (abbreviated ADT) if the programmers who use the type do not have access to the details of how the values and operations are implemented. (e.g. predefined types such as int, double, etc. are ADTs)

[Ch6.2] What is the term "private:" in a class definition in C++?

An access specifier that means all items that follow cannot be referenced by name anyplace except within the definitions of the member functions of their respective class.

[Ch6.2] What is the term "public:" in a class definition in C++?

An access specifier that means there are no restrictions on the members that follow and all items that follow can be referenced by name anyplace.

[Ch3.1] What can the characteristics of an argument of a function call be in C++?

An argument of a function can be a constant, a variable, or a more complicated expression.

[Ch5.3] What is a partially filled array in C++?

An array that when declared does not have a value to indicate its size but is declared to be of the largest size the program could possibly need. Then, the program is free to use as much or as little of the array as is needed.

[Ch5.4] What is a multidimensional array in C++?

An array with more than one index. (e.g. char page[30][100]; )

[Ch3.2] What is a void function call in C++?

An executable statement that ends with a semicolon which tells the compiler that the function call is what it is.

[Ch2.3] What is a comma expression in C++?

An expression that contains the comma operator or several comma operators between multiple subexpressions. Only use a list of expressions connected with commas when the order of evaluation is not important. Otherwise use parentheses in addition to commas. (e.g. result = ((first = 2, second = first + 1), third = second + 1); )

[Ch2.2] What kind of statement do you have when you omit the else part of an if-else statement in C++?

An if statement.

[Ch2.2] How do if-else statements compare to conditional operator in C++?

An if-else statement can be expressed using the conditional operator. (e.g. if (n1 > n2) max = n1; else max = n2; can be expressed as max = (n1 > n2) ? n1 : n2; )

[Ch5.1] What is the number inside the square brackets referred to as in C++?

An index or a subscript.

[Ch1.5] What is an "include" directive in C++?

An instruction to include the text found in a file at the location of the "include" directive.

[Ch2.3] What is the repetition of the loop body called in C++?

An iteration of the loop.

[Ch8.1] What is an anonymous object in C++?

An object that is created by a constructor without being associated by a variable name. Nevertheless, it is still a full-fledge object and can be used as a calling object for methods of its class type. (e.g. Money(finalDollars, finalCents) Money(finalDollars, finalCents).getDollars(); )

[Ch6.1] What is a structure in C++?

An object without any member functions and its data can be a collection of data items of diverse types.

[Ch8.1] What is an overloaded operator in C++?

An operator that performs differently than the standard operator configuration and is usually applied to objects that you define so that it will accept arguments of that class type.

[Ch8.1] What is a unary operator in C++?

An operator that takes only one operand (one argument). (e.g. The operator - which is used to mean negation)

[Ch1.2] If an integer type is unsigned what does that mean in C++?

An unsigned integer version only includes nonnegative values.

[Ch7.3] When iterating over a vector what type should the iterating variable be declared as in C++?

An unsigned integer. (e.g. for (unsigned int i = 0; i < v.size(); i++){ cout << v[i] << endl; } )

[Ch1.2] What is the rule for constants of type "double" in C++?

Any double constant must contain a decimal point and cannot contain a comma.

[Ch2.1] What is a Boolean expression in C++?

Any expression that is either true or false.

[Ch2.2] What are characteristics of enumeration types in C++?

Any int values can be used and can define any number of constants. If you do not specify any numeric values, then the identifiers in an enumeration type definition are assigned consecutive values beginning with zero. The default for first enumeration constant is 0 and the rest increase by 1 unless you set one or more of the enumeration constants. Enumeration types are separate and different from int types. Therefore, they should not be used in arithmetic.

[Ch1.2] What is the rule for constants of type "int" in C++?

Any integer type must not contain a decimal point and cannot contain a comma.

[Ch6.2] When programming with classes, how is a program interpreted in C++?

As a collection of interacting objects.

[Ch5.1] How is an array represented in memory?

As a shown above an array is represented as a contiguous block of memory such that depending on the declared array size there is just enough memory reserved to hold up to that size of the base type for that array.

[Ch5.4] How can a two-dimensional array be visualized as from C++?

As a two-dimensional display with the first index giving the row and the second index giving the column.

[Ch4.1] How should a function call be thought of in C++?

As an action and not in terms of substituting code for the function call.

[Ch8.1] What is a major restriction on overloading an binary operator in C++?

At least one operand must be of a class type. So, for example, you can overload the % operator to apply to two objects of type Money or to an object of type Money and a double, but not for combining two doubles.

[Ch5.1] When do array indexes most commonly get out of range in C++?

At the first or last iteration of a loop that processes the array.

[Ch1.1] What is a C++ Program?

Basically a function called main.

[Ch6.2] Why can objects interact in C++?

Because they are capable of actions, namely invocations of member functions.

[Ch1.2] When do you declare a variable in C++?

Before it is used else where in your program.

[Ch1.2] What is the difference between v++ and ++v in C++?

Both expressions evaluate to different values such that: If the ++ is before the variable, then the incrementing is done before the value is returned. If the ++ is after the variable, then the incrementing is done after the value is returned. (Same relationship for v-- and --v)

[Ch4.2] How does the compiler tell when function overloading occurs in C++?

By checking the number and types of arguments in a function call.

[Ch2.3] How can you alter the flow control of loops in C++?

By inserting a break or continue statement.

[Ch4.3] How can you include error checks within a program in the least amount of lines of code in C++?

By making calls to the "assert" macro.

[Ch7.1] How can you invoke the constructor with no arguments when declaring a class type variable in C++? What happens if you declare a class type variable with parentheses and no arguments in C++?

By not using any parentheses when the variable is declared. For example, DayOfYear date3(); is referred to as a function declaration that returns a value of type DayOfYear. This does not declare a class type object of DayOfYear.

[Ch1.2] How are constants of type "char" expressed in C++?

By placing the character in single quotes.

[Ch1.2] How are constants of type "string" expressed in C++?

By placing the string in. double quotes.

[Ch2.4] How does C++ read files in as input?

By reading from the beginning of the file and proceeding towards the end of as the data is read.

[Ch3.1] How do you store the return value of a function when it returns it in C++?

By setting the function call equal a compatible variable that can store that value. (e.g. sroot = sqrt(9.0) )

[Ch5.1] How is an array accessed in memory?

By the address of the very first index of an array.

[Ch1.2] How is multiplication expressed in C++?

By the asterisk, *.

[Ch5.1] When declaring an array how is its size determined in C++?

By the number in the square brackets after the array name which states how many indexed variables the array has which is its size.

[Ch7.2] How are static variables indicated when declared in C++?

By the qualifying keyword "static" at the start of their declaration.

[Ch5.1] How is a simple variable represented in memory?

By two pieces of information: 1. As an address in memory (giving the location of the first byte for that variable). 2. The type of the variable, which tells how many bytes of memory the variable requires.

[Ch5.1] How should the size of an array be defined in c++?

By using a defined constant. (e.g. const int NUMBER_OF_STUDENTS = 5; int i, score[NUMBER_OF_STUDENTS], max; )

[Ch1.5] What is normal way to make a library available to a program in C++?

By using an "include" directive with the following syntax: #include <Library_Name>

[Ch1.2] What is the most direct way to change the value of a variable?

By using an assignment statement. (e.g. Variable = Expression; )

[Ch1.5] How do you use a specific name of a namespace in a program in C++?

By using the "using" directive as follows: using namespace name::name; (e.g. using namespace std; To use the name cin only you could use the following: using std::cin; ) This applies to other names as well.

[Ch5.2] How can you prevent a function from changing the values of an array being passed by the array argument in C++?

By using the "const" modifier before the array parameter for that argument position of the function declaration.

[Ch7.3] How can you change the size of the vector in C++?

By using the "resize" member function. (e.g. v.resize(24); resizes a vector v to 24 elements.) If the previous size of the vector was smaller than 24, then the new elements are initialized as described for the constructor with an integer argument. If the the previous size of the vector was greater than 24, then all but first 24 elements are lost. The capacity is automatically increased if need be. Using "resize" and "reserve", you can shrink the size and capacity of a vector when there is no longer any need for some elements or some capacity.

[Ch5.1] How are the addresses of any other indexed variable of an array determined by a computer?

By using the address of the first index of an array and adding to it the number of bytes needed to hold a specific number of indexed variables of the base type of the array. This results in accessing a certain indexed variable based on the number of index being a valid number within the size of the array.

[Ch7.3] How do you initialize the number of positions of a vector when declaring it in C++?

By using the constructor that takes one integer argument. (e.g vector<int> v(10); This statement declares a vector of type integers whose name is v and has 10 positions. The first ten elements are initialized to zero and v.size() would return 10.)

[Ch2.4] How does a program take input from the file in C++?

By using the extraction operator, >>, on the inputStream variable in the same way the cin object uses the >>.

[Ch7.3] How can the capacity of a vector be found in C++?

By using the member function "cacpacity()".

[Ch2.4] How can you tell when the program has read all of the contents of a file in C++?

By using the stream extraction operator as a Boolean expression (inputStream >> text) which will return true if the read was successful and false if it was not. (e.g. string text; fstream inputStream; inputStream.open("filename.txt"); while (inputStream >> text){ cout << text << endl; } inputStream.close(); )

[Ch1.2] How is an uninitialized variable's value determined in C++?

By whatever pattern of zeroes and ones were left in its memory location by the last program that used that portion of memory.

[Ch3.3] When declaring a variable in a for loop is that variable local to that loop in C++?

C++ compilers will, likely comply with making the variable local to the loop but results can vary. (I believe GL complies from doing Project 3)

[Ch1.2] What does it mean for C++ to be case-sensitive language?

C++ distinguishes between uppercase and lowercase letters in the spelling of identifiers.

[Ch1.2] What are strings in double quotes called in C++?

C-strings.

[Ch4.1] What are the two types of formal parameters in C++?

Call-by-value and Call-by-reference parameters. With call-by-value parameters, only the value of the argument is plugged in. With call-by-reference parameters, the argument is the address of a variable that is plugged in.

[Ch6.2] What is encapsulation in C++?

Defining a class so that the implementation of the member functions and the implementation of the data in objects are not known, or is at least irrelevant to the programmer who uses the class.

[Ch4.3] What are the characteristics of a driver program in C++?

Driver programs are temporary tools and can be quite minimal. They need not have fancy input routines. All they need to do is obtain reasonable values for the function arguments in as simple of a way as possible - typically from the user - then execute the function and show the result.

[Ch7.2] How are static variables initialized in C++?

Each static variable must be initialized outside of the class definition, even private static variables. (e.g. given above)

[Ch6.2] What is one of the main tenets (principles) of object oriented programming (OOP) in C++?

Encapsulation for classes.

[Ch4.3] What is the fundamental rule for testing functions in C++?

Every function should be tested in a program in which every other function in that program has already been fully tested and debugged.

[Ch1.2] What are the Identifier Requirements in C++?

Every identifier must start with either a letter or the underscore symbol, and all the res of the characters be letters, digits, or the underscore symbol.

[Ch3.1] What are subparts of a program that have different functionality separately in C++?

Functions (aka procedures, sub programs, and methods in other programming languages).

[Ch3.3] What is a characteristic of how functions should work in C++?

Functions should be self-contained units that do not interfere with other functions or any other code at all.

[Ch5.3] What is an important characteristic of a partially filled array that must be kept tracked of in C++?

How much of the array is used. This makes sure no uninitialized indexed is referenced.

[Ch3.3] How does variable declaration work in blocks in C++?

If a variable is declared in a block, then the definition applies from the location of the declaration to the end of the block which is known as the scope of this declaration. If a variable is declared at the start of a block, then its scope is the entire block. If a variable is declared part way through the block, then the declaration does not take effect until the program reaches the location of the declaration.

[Ch1.2] What results occur when mixing types with arithmetic operators and expressions in C++?

If both operands are ints, then the result is an int. If both operands are doubles, then the result is a double. If at least one of the operands or subexpressions is of a floating-point type, then the result will be a floating-point type.

[Ch2.1] What is the condition for short-circuit evaluation of the "and" Operator, && in C++?

If the leftmost of the "and" Operator, && evaluates to false, then any other rightmost expressions are ignored.

[Ch2.1] What is the condition for short-circuit evaluation of the "or" Operator, || in C++?

If the leftmost of the "or" Operator, || evaluates to true, then any other rightmost expressions are ignored.

[Ch2.1] What always makes short-circuit evaluation occur when comparing two Boolean subexpression in C++?

If the second or rightmost expression is undefined as it does not have a meaningful value, then short-circuit evaluation is used always.

[Ch7.3] What happens when you use the constructor with an integer argument to declare a vector of class objects in C++?

If the vector base type is class type, then the default constructor of that class is used for initialization.

[Ch4.2] When are error messages issued when overloading function names in C++?

If two matches are found at stage 1 or if no matches are found at stage 1 and two matches are found at stage 2, then there is an ambiguous situation and an error message will be issued.

[Ch4.1] When should you use either call-by-reference mechanism or call-by-value mechanism in C++?

If you want a function to change the value of a variable, then the corresponding formal parameter must be a call-by-reference formal parameter and must be marked with the ampersand sign, &. In all other cases, you can use a call-by-value formal parameter.

[Ch2.4] When should the file be closed to release any resources that have been allocated in association with that file in C++?

Immediately after you read in the data with the extraction operators (if possible) but never later on in program. (Project 1 error)

[Ch4.1] Where is the ampersand sign, &, placed for a function to call-by-reference in C++?

In both the function declaration (function prototype) and the header of the function definition.

[Ch5.1] What are the individual variables that together make up an array referred to as in C++?

Indexed variables, subscripted variables, or elements of an array.

[Ch5.1] What do indexes start with in C++?

Indexes are numbered starting with 0 and no other value.

[Ch7.2] What are disadvantages of using inline functions in C++?

Inline functions can mix the interface and implementation of a class which can go against the principle of encapsulation. With many compilers, the inline function can only be called in the same file as the one in which it is defined.

[Ch5.2] How can a function return an Array in C++?

It cannot return an array in the same way any primitive data type can be return but instead what could be returned is a pointer to the array.

[Ch2.3] What does the Boolean expression do in a for statement in C++?

It checks for when the loop should end.

[Ch7.3] What happens when the assignment operator is used with vectors in C++?

It does an element-by-element assignment to the vector on the LHS of the assignment operator (increasing capacity if needed and resetting the size of the vector on the LHS of the assignment operator). Provided that the assignment operator, (depending on the base type) makes an independent copy of an element (of the base type), then the assignment operator on the vector will make an independent copy of the vector on RHS of the assignment operator. Thus, the vector assignment operator is using a copy constructor because it does an "element-by-element" assignment. NOTE: For the assignment operator to produce a totally independent copy of a vector on the RHS of the assignment operator requires that the assignment operator on the base type make completely independent copies. The assignment operator is only as good (or bad) as the assignment operator of the base type.

[Ch2.2] When does a switch statement end in C++?

It ends when either a break statement is encountered or the end of the switch statement is reached.

[Ch2.2] What is an if-else statement in C++?

It is a branching mechanism that chooses between two alternative statements based on the value of a Boolean expression.

[Ch3.1] Where is a function call legalin C++?

It is legal wherever any expression can be used but mainly for being assigned to the type specified by the return value of that function. (e.g. double sroot = sqrt(9.0) )

[Ch6.1] What is the dot operator used for with structure types in C++?

It is used to specify a member of a structure variable. Syntax: Structure_Variable_Name.Member_Variable_Name

[Ch3.1] What must a program contain in order to use a predefined function a library in C++?

It must contain an "include" directive that names that library. (e.g. to use the function sqrt() a program would have #include <cmath>)

[Ch3.2] What is the function declaration tell the programmer and compiler about that respective function in C++?

It says how many arguments the function needs and what type the arguments should be which is vital in order to write and use a call to that function.

[Ch6.2] What does the implementation of a class provided in C++?

It tells how the class interfaces is realized as C++ code. The implementation consists of the private members of the class and the definitions of both the public and private member functions.

[Ch2.3] What does the Update Action expression do in a for statement in C++?

It tells how the loop control variable is updated after each iteration of the loop body.

[Ch2.3] What does the Initialized Action expression do in a for statement in C++?

It tells how the variable, variables, or other things are initialized.

[Ch7.2] How can a nonmember function be defined inline in C++?

Just place the keyword "inline" before the function declaration and function definition.

[Ch2.3] When is it useful to use the comma operator in C++?

Mainly only for a for loop. However, it should not really be used for any other context but is not illegal in any expression.

[Ch6.1] What are the identifiers declared inside the braces {} of a struct in C++?

Member names.

[Ch1.2] What are examples for the alternative notation for initializing variables in C++?

Method 1: int count = 0, limit = 10; double distance = 999.99; Method 2: int count(0), limit(10); double distance(999.99);

[Ch1.5] Is it possible to write a C++ program without using at least one library?

No it is not.

[Ch7.1] Should constructors of a class be under the private access specifier in C++?

No it should not, because then there could not be any objects of that class type that could be declared which would make the class completely useless.

[Ch7.2] Does a static function NEED a calling object to be invoked in C++?

No static functions do not need a calling object, therefore the definition of a static function cannot use anything that depends on a calling object.

[Ch1.5] Can a "include" directive have extra space before or after the #, or inside of the <> in C++?

No there should not be any extra space at all. The include directive instruction has to follow the correct syntax to work properly.

[Ch7.1] If a class includes one or more constructors that each take one or more arguments, and a default constructor is excluded from the class definition, then can an object be declared with no arguments in C++?

No this is illegal. (e.g. SampleClass aVariable; is an illegal declaration as it asks the compiler to invoke the default constructor when there is none. The compiler always interprets the declaration above as a call to a constructor with no arguments. )

[Ch3.2] Do any statements after a return statement execute in C++?

No, a return statement ends every function call.

[Ch5.1] Can arrays have indexed variables of different types in C++?

No, all the indexed variables for one array, must be of the same type and this is called the base type of an array.

[Ch1.2] Can you apply the increment or decrement operators to more than a single variable in C++?

No, any compound expressions in C++ cannot use these operators and are illegal.

[Ch5.1] Does the index need to always be an integer constant in C++?

No, any expression can be used inside the square brackets as long as the it evaluates to one of the integers ranging from 0 through the integer one less than the size of the array.

[Ch7.2] Should long function definitions be implemented as inline function definitions in C++?

No, because the inline version can actually be less efficient, as a large piece of code is repeated frequently.

[Ch1.2] Does double quotes around a single character make the value of type char in C++?

No, for example 'A' and "A" mean that 'A' is value of type char and can be stored in a variable of type char. "A" is string of characters and does make "A" a value of type char.

[Ch4.1] Can you add variable declarations for the formal parameters in C++?

No, formal parameters should not be declared twice in a function definition.

[Ch7.3] Can a vector be assigned a value "i" greater than or equal to the size of the vector in C++?

No, if "i" is greater than the size of the vector then the that element v[i] does not yet exist. Therefore, that position needs to be created by using "push_back" to add elements up to and including position "i".

[Ch3.2] Is a function declaration required if a full function definition comes before a function call in C++?

No, it can be omitted.

[Ch3.2] Does the function declaration say what the return value is of a function? in C++?

No, it does not and never should. The function definition determines what the return value is.

[Ch5.2] Does the array argument tell a function being passed an array its size in C++?

No, it does not and this is why in the list of parameters of that function there must be a parameter that corresponds to the size of the array.

[Ch7.3] Does the vector member function "reserve" decrease the capacity of a vector if the argument is smaller than the current capacity in C++?

No, it does not necessarily decrease the capacity but you can rely on it to increase the capacity of a vector.

[Ch3.1] Does the order of include directives matter in in C++?

No, it does not.

[Ch7.1] Can a constructor be called like an ordinary member function of a class in C++?

No, it is illegal to the dot operator with constructor member function.

[Ch6.2] Is it required for public member to be listed first in a class definition in C++?

No, it is not required but in CMSC 202 this is our standard.

[Ch8.1] Is it possible to change the value's value in C++?

No, it is not this is why it is pointless to return primitive types such as int, by "const" value. Values of basic types cannot be changed whether there is a "const" before the returned type of not. On the other hand, values of a class type (objects) can be changed, since they have member variables and so the "const" modifier has an effect on the object returned.

[Ch3.2] Does C++ check for both function call argument to function declaration argument type and variable name?

No, it only checks for the type of each argument when a function call is made to its function declaration. Therefore, if arguments of the same type are mixed then their will be a logical error.

[Ch3.2] Should the main function be called recursively in C++?

No, it should not at all.

[Ch5.1] Can an array's size bet determined by a variable in C++?

No, not all compilers will allow...

[Ch6.2] When programming with classes in C++ would you use global functions?

No, only classes with member functions that can interact with other classes and member functions.

[Ch3.2] Can you place a function definition within the body of another function definition in C++?

No, only function calls can be nested.

[Ch3.2] Should a call to the main function be made in a program in C++?

No, only the system should be making any calls to the main function.

[Ch4.1] Can call-by-value formal parameters make changes to the variable that is substituted in C++?

No, only the value of the variable is substituted in place of the formal parameter.

[Ch4.2] Can you overload a function name solely by the "const" modifier or solely on call-by-value versus call-by-reference parameters in C++?

No, these factors do not cause a function to be overloaded.

[Ch8.1] When a class has overloaded binary operators such as + and - are they member operators (member functions) of that class in C++?

No, they are not member functions of that class and therefore do not have access to the private data members of that class. This is why the definition for the overloaded operators use accessor and mutator functions.

[Ch3.3] Do variables that are defined in a function definition and in the main function with the same name correspond to each other in C++?

No, they are two different variables that can have different values even thought they have the same name.

[Ch3.2] Are formal parameter names required in a function declaration in C++?

No, they can be either of following implementations which are both equivalent: double totalCost(int numberParameter, double priceParameter); and double totalCost(int, double);

[Ch3.1] Can functions have more than one value returned in C++?

No, they can have more than one argument, but only one value to return. (Depending on what the function returns that value returned can contain multiple other values (e.g. objects from classes) )

[Ch4.2] Can default arguments be used with call-by-reference parameters in C++?

No, they can only be used with call-by-value parameters.

[Ch7.2] Can static variables be initialized more than once in C++?

No, they cannot.

[Ch7.1] If a class includes multiple constructors of any kind, then is a constructor still automatically generated in C++?

No, this does not occur.

[Ch4.1] Is the ampersand sign needed to call-by-reference in a function call in C++?

No, this not legal syntax for the call-by-reference mechanism.

[Ch4.2] Can subsequent arguments give default arguments again in C++?

No, this will cause an error even if the arguments are consistent with the ones defined previously.

[Ch7.2] Can a static function definition use any non-static variables or member functions in C++?

No, unless the non-static variable or function has a calling object that is a local variable or some object otherwise created in the definition. In other words, the definition of a static function cannot use anything that depends on a calling object.

[Ch2.2] Can you have multiple occurrences of a case with the same constant value in a switch statement in C++?

No, you cannot because this would create ambiguous instruction and confuse the compiler.

[Ch4.2] Can you overload a function name by any difference in the number or types of parameters in C++?

No, you cannot.

[Ch4.2] Can you overload a function name by giving two definition that differ only in the type value returned in C++?

No, you cannot.

[Ch2.2] What is the result of the expression: x = 12 as the Boolean expression of an if statement in terms of Boolean value compatibility in C++?

Nonzero int values are converted to true in assignment statements like x = 12 when used as the Boolean expression in an if-else statement.

[Ch2.3] What is a nested loop and how do the break or continue statements work in this loop structure in C++?

One loop statement inside another loop statement. Any break or continue statement applies to the innermost loop (or switch) statement where the break or continue statement is contained.

[Ch4.2] Where is a default argument given to a function in C++?

Only in the function declaration and not in the function definition.

[Ch5.2] When an array is used as an array argument for a function which of the array's components is passed on in C++?

Only the address of first indexed variable.

[Ch6.1] Where are structure definitions placed in a program in C++?

Outside and before any function definition that intends to use this definition (in the same way that globally defined constant declarations are placed outside all function definitions).

[Ch1.2] How do you mark a variable declaration so that it cannot be changed?

Preceding the declaration with the word "const" (which is an abbreviation of constant).

[Ch3.2] What should be considered when designing functions in C++?

Preconditions and Postconditions.

[Ch1.1] What are Functions?

Procedure-like entities in C++.

[Ch8.1] What is returning by "const" or constant value and how is it implemented in C++?

Returning by constant value means that the returned object of a function cannot be changed. In order to implement this the "const" modifier must come first on the line of a function declaration and definition.

[Ch4.3] How should functions be tested in C++?

Separately, but a fully tested function can be used in a driver program for another untested function which will reveal bugs only of the untested function. Generally, each function should be tested in a program in which it is the only untested function.

[Ch3.2] What is a function header in C++?

Similar to the syntax of a function declaration except it does not end with a semicolon.

[Ch4.3] What are stubs in C++?

Simplified versions of a function that has not yet been written or tested that are used to test another function.

[Ch3.3] What is a block in C++?

Some C++ code enclosed in braces. The variables declared in a block are local to the block, and so the variable names can be reused outside the blow know for other variables.

[Ch7.2] What is an advantage of using static variables in C++?

Static variables allow some the features of global variables without exposing the opportunity for misuse that true global variables have. In particular, a static variable can be private so that only objects of the class can directly access it.

[Ch6.2] How do structures and classes differ in C++?

Structures are normally used with all member variables public with no member functions. However, in C++ a structure can have private member variables and both public and private member functions. Nevertheless, a C++ structure can do anything a class can do but structures should only be used as with public data members and no member functions. Structures and classes that an initial group of member that have neither a public nor private access specifier. Structures: Default groups to public Classes: Default groups to private

[Ch4.3] What are the characteristics of a stub in C++?

Stubs will not necessarily perform the correct calculation, but they will deliver values that suffice for testing, and they are simple enough that you can have confidence in their performance.

[Ch4.3] How do you syntactically turn off and on the "assert" invocations in C++?

Syntax: #define NDEBUG #include <cassert> Include the line #define NDEBUG to turn off invocations and comment this line out to turn on invocations.

[Ch2.1] What is the syntax for the "and" Operator, && in C++?

Syntax: (Boolean_Exp_1) && (Boolean_Exp_2)

[Ch2.1] What is the syntax for the "or" Operator, || in C++?

Syntax: (Boolean_Exp_1) || (Boolean_Exp_2)

[Ch7.2] How is a nested class syntactically denoted in C++?

Syntax: OuterClass::InnerClass

[Ch1.3] What is the syntax for cin Statements in C++?

Syntax: cin >> Variable_1 >> Variable_2 >> ...; Examples: cin >> number >> size; cin >> timeLeft >> pointsNeeded;

[Ch1.3] What is the "magic formula" for outputting values of type double in C++?

Syntax: cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); Any nonnegative whole number can replace the number 2 to specify a different number of digits after the decimal point or even a variable of type int.

[Ch2.2] What forms the ternary operator and how does it evaluate its Boolean expression in C++?

The "?" and ":" together form a ternary operator (aka the conditional operator) which starts with a Boolean expression followed by a ? and then followed by two expression separated with a colon. If the Boolean expression is true, then the first of the two expression is returned; otherwise the second of the two expression is returned.

[Ch1.5] In order to use the all of the standard libraries what directive needs to be used in a program in C++?

The "using" directive as follows: using namespace std;

[Ch1.2] What can the % (modulus) operator be used for when computing integer division between ints in C++?

The % operator can recover the remainder that is truncated by integer division with ints.

[Ch7.3] Where are vectors defined at in C++?

The Standard Template Library (STL).

[Ch3.2] What happens when a void function is called in C++?

The arguments are substituted for the formal parameters, and the statements in the function body are executed.

[Ch5.2] How is an array parameter different from a call-by-reference parameter in C++?

The array argument parameter passes the address of the first indexed variable but the size of the array is not also passed. Compared to a call-by-reference parameter which passes all the information a function requires to access the parameter being passed.

[Ch5.1] What happens when an array is initialized as it is declared but the value of the size is omitted in C++?

The array will automatically be declared to have the minimum size needed for the initialization values. (e.g. int b[] = {5, 12, 11}; is equivalent to int b[3] = {5, 12, 11}; )

[Ch2.4] What is an example of input stream in C++?

The cin object of the <iostream> library.

[Ch6.2] When a member function is defined what must the definition include in C++?

The class name because there may be two or more classes that member functions with the same name. (e.g. void DayOfYear::output(){} )

[Ch6.2] What is a type qualifier in C++?

The class name that precedes the scope resolution operator. The type qualifier specializes the function name to one particular type.

[Ch7.2] What is special about how the compiler treats inline functions in C++?

The code for an inline function declaration is inserted at each location where the function is invoked. This saves the overhead of a function invocation.

[Ch1.2] How does the compiler evaluate the expression n++ and can it be used with other arithmetic expressions in C++?

The compiler first returns the value of n, then the value of n is increased by 1 and yes, it can. (e.g. (2*n++) )

[Ch7.2] What are inline function definitions in C++?

The complete definition of a member function within the definition of its class.

[Ch7.1] When overloading constructors of a class what identifies the default constructor in C++?

The constructor without any arguments. (e.g. DayOfYear(); )

[Ch2.3] How does a continue statement affect a loop in C++?

The continue statement transfers control to the update action expression to end the current iteration of the loop; the next iteration (if any) continues the loop. In any loop the control variable will be updated immediately after the continue statement is executed.

[Ch2.2] What are the characteristics of the controlling expression of a switch statement in C++?

The controlling expression must always return either a bool value, an enum constant, one of the integer types, or a character.

[Ch4.1] What is a call-by-reference parameter (aka mechanism) and how does it work when a function is invoked in C++?

The corresponding argument in a function call must be a variable, and this argument variable is substituted directly as a variable for the formal parameter that is marked by the ampersand sign, &, to the and of the type name or parameter name in the formal parameter list. After the substitution, the code in the function body is executed and can change the value of the argument variable.

[Ch5.1] What is the number of indexed variables in an array referred to as in C++?

The declared size of an array or simply the size of an array.

[Ch8.1] What is the functionality of the assignment operator with objects of a class in C++?

The default assignment operator does not make the two object the same object, it only copies values of the member values from one object to another object.

[Ch7.3] What constructor is called when declaring a vector as follows: vector<int> v; in C++?

The default constructor for the class vector<int> which creates a vector object that has no elements.

[Ch7.1] When declaring a class type object if the object does not have any parentheses for arguments, which constructor is called in C++?

The default constructor.

[Ch2.3] When dealing with numbers in a Boolean expression of a loop to check a numeric quantity what operators should be avoided to prevent an infinite loop in C++?

The equals operator (==) and does not equal operator (!=).

[Ch2.2] What is the conditional operator expression in C++?

The expression on the right-hand side of the assignment statement.

[Ch3.2] What component of a function definition determines what the return value is in C++?

The function body.

[Ch6.2] What are the rules for how to use a class known as in C++?

The interface or API. Generally, API is associated to stand for application programmer interface or abstract programming interface.

[Ch2.2] What is a break statement, how does it work, and where is it legal to put it in C++?

The keyword "break" followed by a semicolon. The break statement completely ends the nearest enclosing switch or loop statement. A break statement is not legal anywhere else except for within a looping structure in C++.

[Ch2.3] What is a continue statement and how does it work in C++?

The keyword "continue" followed by a semicolon. The continue statement ends the current loop body iteration of nearest enclosing loop statement.

[Ch3.2] What is the difference between defining a void function and a function that returns a value in C++?

The keyword "void" is used where normally the type a function would return is and thus there are no return statements in void functions.

[Ch2.3] When dealing with numbers in a Boolean expression of a loop to check a numeric quantity what operators should be used to prevent an infinite loop in C++?

The less than operator (<), greater than operator (>), less than or equal to operator (<=) or the greater than or equal to operator (>=).

[Ch4.3] What library is required to use the "assert" macro in C++?

The library cassert. Syntax: #include <cassert>

[Ch2.3] What is the code repeated in every loop called in C++?

The loop body.

[Ch1.2] What is a literal (aka constant) in C++?

The name for one specific value.

[Ch1.2] What is an Identifier?

The name of a variable or item defined in a program.

[Ch6.1] What is a structure tag in C++?

The name of the structure type that usually begins with an uppercase letter.

[Ch4.1] How should formal parameters be named in C++?

The names of the parameters should be as meaningful to the context of what action the function does.

[Ch7.3] What is the capacity of a vector in C++?

The number of elements at any point in time a vector has allocated in memory.

[Ch1.2] What does precision mean in C++?

The number of meaningful digits, including digits in front of the decimal point.

[Ch6.2] What is scope resolution operator in C++?

The operator "::" serves a purpose similar to that of the dot operator which tells what member function is a member of. However, the scope resolution operator :: is used with a class name, whereas the dot operator is used with objects (i.e. class variables).

[Ch2.1] What is the order of precedence when order is not determined by parentheses and the operators have the same precedences in C++?

The order of the unary operations is done from right to left. Same for assignment operations. (e.g. x = y = z which means x = (y = z) )

[Ch6.1] If there are fewer initializer values than struct members, then how are the member variables initialized in C++?

The provided values are used to initialize data members in order. Each data member without an initialized value is set to a zero value of an appropriate type for that variable.

[Ch4.2] What are the two simple rules for resolving overloading in C++?

The rules the compiler uses for resolving which multiple overloaded definitions of a function name apply to a given function call are as follows: 1. Exact match: If the number and types of arguments exactly match a definition (without type conversion), then that definition is used. 2. Match using automatic type conversion: If there is no exact match but there is a match using automatic type conversion, then that match is used.

[Ch7.3] What is the difference between the vector member functions size and capacity in C++?

The size member function returns the number of elements in a vector, while the capacity member function returns the number of elements for which there is memory allocated for. Typically, the capacity is larger than the size, and the capacity is always greater than or equal to the size. Whenever a vector runs out of capacity and needs room for an additional member, the capacity is automatically increased. The exact amount of the increase is implementation dependent, but always allows for more capacity than is immediately needed.

[Ch7.3] What is the number of elements in a vector referred to as in C++?

The size of the vector. There is member function size that can be used to determined how many elements are in a vector. The member function size returns a value of type "unsigned int" which is only consists of positive integers as a vector's size will never be negative.

[Ch4.3] How are stubs replaced by functions when testing in C++?

The stubs are replaced by functions one at a time: One stub is replaced by a complete function and tested. Once the function is fully tested, another stub is replaced by a full function definition and so forth, until the final program is produced.

[Ch2.2] Besides a multiway if-else statement, what other statement implements multiway branching in C++?

The switch statement.

[Ch3.1] What is a function call or invocation in C++?

The syntactical expression where a function takes in one or more arguments separated by commas. (e.g. sqrt(9.0) )

[Ch1.1] What is a String (aka C-String)?

The text inside quotation marks.

[Ch8.1] What are examples of unary operators in C++?

The unary operator - is used to set the value of a variable x equal to the negative value of the variable y: x = -y; The increment and decrement operators, ++ and --

[Ch6.2] What is an object of a class in C++?

The value of a class type that has both data members and function members.

[Ch3.1] What is the value returned of a functionin C++?

The value the function computes and returns.

[Ch3.1] What is an argument of a function in C++?

The value the function starts out with before returning the computed value.

[Ch5.1] How can an array be initialized in C++?

There are two methods of initializing an array given by the following two examples: 1. int children[3] = {2, 12, 1}; 2. int children[3]; children[0] = 2; children[1] = 12; children[2] = 1;

[Ch8.1] What is the difference between overloading an operator such as + and defining an ordinary function in C++?

There is only a slight change in syntax: You would use the symbol "+" as the function name and precede this with the keyword "operator". The operator declaration (function declaration) for the plus sign would be as follows: const Money operator +(const Money& amount1, const Money& amount2);

[Ch8.1] When you overload a binary operator as a member operator (member function) how many parameters does it use in C++?

There is only one parameter, not two. The calling object serves as the first parameter. (e.g. Money cost (1, 50), tax(0, 15), total; total = cost + tax; When + is overloaded as a member operator, then in the expression "cost + tax" the variable "cost" is the calling object and "tax" is the single argument to +.

[Ch1.2] What are is the special class of identifiers in C++?

These are called "keywords" or "reserved words" which have a predefined meaning in C++ and cannot be used as names for variables or anything else.

[Ch6.2] How are member functions of classes called in C++?

They are invoked using the dot operator in the way that is similar to how you specify a member variable. (e.g. DayOfYear today, birthday; today.output(); birthday.output(); )

[Ch8.1] How can the ++ and -- operators be overloaded in C++?

They are overloaded in the same way the negation operator is overloaded (as shown in the image above) If the ++ and -- operators are overloaded based on the method of overloading the negation operator, then the overloading definition will apply to the operator when it is used in the prefix position, as in ++x and --x.

[Ch1.2] What can both the increment and decrement operators be used with in C++?

They can be used with any numeric type but usually are used with variables of type int.

[Ch7.3] What are vectors comparable to in C++?

They compare to arrays but the only difference is that they can grow and shrink in length while a program is running.

[Ch5.1] What happens when fewer values than the number of indexed variables are initialized in C++?

They may or may not be initialized to a zero of the array base type.

[Ch3.2] What rules must formal parameters of function declarations follow in C++?

They must follow the C++ valid identifier rules.

[Ch5.4] What is the following declaration of a two-dimensional array: char page[30][100]; in C++?

This declaration declares a one-dimensional array of size 30 whose base type is a one-dimensional of characters of size 100.

[Ch6.1] What is the keyword "struct" used for in C++?

This keyword announces that the contents inside the braces {} is a structure-type definition.

[Ch8.1] What is the purpose of returning by constant value in C++?

This method provides a kind of automatic error checking to ensure operations like addition with the + operator do not inadvertently change the object that is the sum. (e.g. (m1 + m2) = an object as the sum ) In this case changing the object (m1 + m2) would not matter, but if the retuned object is a reference to an existing object then this can cause problems.

[Ch1.2] What does declaring a variable do in C++?

This tells the compiler what kind of data you will be storing in that variable.

[Ch3.3] If any variable is declared within the body of a function definition then what characteristic do those variables have in C++?

Those variables are local to that function or have that function as their scope.

[Ch1.2] What does the assignment statement instruct the computer to do?

To compute the value of the expression on the right-hand side of the equal sign and to set the value of the variable on the left-hand side equal to the value of that expression.

[Ch2.2] What is the purpose of the default label in a switch statement in C++?

To execute its section of code when no other case above it is met.

[Ch7.3] When increasing the capacity of a vector what is the common implementation scheme used in C++?

To increase the capacity to double whenever it needs to increase. However, this implementation may not always be the most efficient and it may be better to manage the capacity of the vectors manually. In order to explicitly increase the capacity of a vector the member function "reserve" can be used. (e.g. v.reserve(32); sets the capacity to at least 32 elements and v.reserve(v.size() + 10); sets the capacity to at least 10 more than the number of elements currently in the vector.)

[Ch2.3] What is the for statement used commonly for in C++?

To step through some integer variable in equal increments, step through an array or vector.

[Ch4.3] What is a common approach to using driver programs in C++?

To test some basic functions such as input and output, and then a program with stubs to test the remaining functions.

[Ch4.3] What is usually the most efficient method of testing in C++?

Using a program outline with stubs which allows you to test and then flesh out the basic program outline, rather than write a completely new program to test each function.

[Ch8.1] How are operators such as +, -, %, ==, etc. defined in C++?

Usually the invocation of these functions is written as x+7 rather than +(x,7) but like most operators it is a function that takes two arguments (often called operands) and returns a single value.

[Ch6.2] In a class definition are member functions contained as declarations or definitions in C++?

Usually they are declarations (prototypes)

[Ch7.3] What is the difference between vectors and arrays in how they are initialized in C++?

Vectors generally cannot be initialized by using the square brackets [] like arrays. To add an element to a vector you have to use the member function "push_back". (e.g. vector<double> sample; sample.push_back(0.0); sample.push_back(1.1); sample.push_back(2.2); )

[Ch7.3] What are similar characteristics of vectors to arrays in C++?

Vectors have a base type which stores a collection of values of that same base type. Vector elects are indexed starting with zero. The square brackets notation [] can be used to read or change the elements in the vector.

[Ch7.3] What happens when you use the constructor with an integer argument to declare a vector of numbers in C++?

Vectors of numbers are initialized to zero of the number type (e.g. integers, doubles, and floats)

[Ch7.2] When are inline function definitions generally used in C++?

Very short function definitions.

[Ch3.1] What are functions called that do no return a value in C++?

Void functions.

[Ch4.1] What are inadvertent variables and how can you avoid them in C++?

When a function declaration is supposed to use the call-by-reference mechanism but does not and instead uses the call-by-value mechanism. This makes the variables in the scope of that function local to the block of that function. Make sure each function declaration that requires the call-by-reference mechanism has the ampersand symbol, &, for each formal parameter required.

[Ch3.2] What determines the return value of a function in C++?

When a function executes a return statement.

[Ch3.3] What is information hiding in C++?

When a function is designed so that it can be used as a black box which emphasizes the fact that the programmer acts as if the body of the function is hidden from view.

[Ch4.2] What are default arguments for functions in C++?

When a function is specified to use a certain value for one or more call-by-value parameters in a function. If the corresponding argument is omitted, then it is replaced by the default argument.

[Ch1.3] How does the cin object work in a cin statement in C++?

When a program reaches a cin statement, it waits for input to be entered from the keyboard. The program sets the 1st variable equal to thirst value typed at the keyboard and 2nd variable, and so forth. However, input is not read until the user presses the Return key which allows for correction of mistakes with backspace when entering a line of input.

[Ch3.2] When does a function call end in C++?

When a return statement is executed.

[Ch5.1] How can an array index be out of range, or simply illegal in C++?

When an index expression evaluates to some value other than those allowed by the array declaration.

[Ch2.1] What determines one operation having higher precedence over another in C++?

When an operation is performed before another, then the operation that was first performed has higher precedence.

[Ch4.3] What are the evaluation conditions of the "assert" macro in C++?

When the "assert" macro is invoked, its assertion argument is evaluated. If it evaluates to true, then nothing happens. IF the argument evaluates to false, then the program ends and an error message is issued.

[Ch7.1] How does calling a constructor of a class explicity work in C++?

When the constructor is called it creates an anonymous class type object with new values. That object does not have a name by a variable until assigned to a variable. (e.g. holiday = DayOfYear(5, 5); )

[Ch2.3] What is the important difference between the while and do-while loops in C++?

When the controlling Boolean expression is checked which determines when each loop type's body is executed. For a while statement the Boolean expression is checked before the loop body is executed. For a do-while statement the body of the loop is executed first and then the Boolean expression is checker after the loop body is executed. A do-while loop always executes the loop body at least once.

[Ch7.2] What is a nested class in C++?

When you define a class within a class. (e.g. class OuterClass { public: ... private: class InnerClass { ... }; ... }; )

[Ch3.3] What is procedural abstraction in C++?

Writing functions and using functions as if they were black boxes.

[Ch2.3] Is it possible to use the increment and decrement operators in controlling Boolean expression of a while or do-while statement in C++?

Yes it is, and above is a syntactical example.

[Ch7.2] Can static functions be invoked like normal functions in C++?

Yes static functions can be invoked by using a calling object of the class. However, it is more common and clearer to invoke a static function using the class name and scope resolution operator. (e.g. Server::getTurn() )

[Ch2.1] Can a variable of type "bool" store the value of a Boolean expression in C++?

Yes, a variable of type bool can be set equal to a Boolean expression. (e.g. bool result = (x < z) && (z < y); )

[Ch7.1] Should a default constructor always be included in any class in C++?

Yes, always but if it does not require implementation then the function body can be left blank. (e.g. SampleClass::SampleClass(){/*Do nothing.*/} )

[Ch5.2] Can an indexed variable be an argument to a function in exactly the same way that any variable of the array base type can be an argument in C++?

Yes, an example is given above with a program that declaration at the top of the image.

[Ch6.1] Can and how does a structure definition declare structure variables in C++?

Yes, and by typing the names of the structure variables between the last {} and the semi colon separated by a comma if more than one variable is desired. (e.g. struct WeatherData { double temperature; double windVelocity; } dataPoint1, dataPoint2; )

[Ch7.2] Is it required for all member functions of a class who do not change the value of its calling object to use the "const" modifier in C++?

Yes, and it is because of the possibility of function calls within functions calls. When a member function who uses the const modifier is called within another function, the compiler knows about the other function. Additionally, if the current function does not contain a "const" then the compiler will assume that the calling object will be changed.

[Ch5.2] Can a function have formal parameter for an entire array in C++?

Yes, and it is referred to as an array parameter which is nether a call-by-value or call-by-reference formal parameter.

[Ch4.1] Can a call-by-reference parameter of a function declaration use the "const" modifier in C++?

Yes, and this prevents the memory address of the variable being substituted from being changed.

[Ch4.2] Is using a default argument comparable to overloading in C++?

Yes, anything you can do with default arguments can be done using overloading, although the default argument version will probably be shorter than the overloading version.

[Ch1.2] For integers in division should you use nonnegative values in C++?

Yes, because each implementation of C++ is different and can have different results when negative. Therefore, nonnegative values have more consistency.

[Ch1.2] Can assignment statements be used as expressions in C++?

Yes, but it is not recommended to be used this way as it can result in a coding error.

[Ch7.2] If you use the "const" modifier for one parameter of a particular type, then should use it for ever other parameter that has that type and is not changed by a function call in C++?

Yes, especially if the type is a class type, then you should also use the const modifier for every member function that does not change the value of its calling object. The reason for this has to deal with function calls within function calls. (e.g. void welcome(const BankAccount& yourAccount){ cout << "Welcome..." << "Your account is:\n"; yourAccount.output(); } ) The declaration for the member function output should include the "const" modifier.

[Ch7.2] Does the "const" modifier behave the same when calling object methods and when it is used with parameters in C++?

Yes, if a member function should not change the value of a calling object, it can be marked with the "const" modifier. (e.g. class BankAccount{ public: ... void output() const; ... }; ) The computer will issue an error message if the respective function inadvertently changes the value of the calling object.

[Ch6.2] If a class definitions produces an ADT can its implementation be changed in C++?

Yes, if the class properly separates the interface and the implementation, then the implementation can be changed without need to change any other code for any program that uses the class definition.

[Ch3.1] If a function returns a value or does not return a value is it still referred to as a function in C++?

Yes, in both cases the subpart of the program is still a function.

[Ch7.2] Can a nested class be used in a member function of the outer class in C++?

Yes, in either configuration of being public or private.

[Ch2.3] Can a for statement have multiple subexpressions in the Initialized Action or Update Action expression in C++?

Yes, it can (e.g. for (sum = 0, n = 1; n <= 10; n++) sum = sum + n; which is also equivalent to: for (sum = 0, n = 1; n <= 10; sum = sum + n, n++); This revised for statement took the loop body and added it to the Update Action expression )

[Ch1.5] Can a function have different definitions in two namespaces in C++?

Yes, it can and a program can then use one of these namespaces in one place and the other in another location.

[Ch5.1] Can an array have indexed variables of any type in C++?

Yes, it can and in order to declare an array with a specific type simply use the type desired before the array name.

[Ch7.2] Can a class definition be defined within a function definition in C++?

Yes, it can and with this configuration the class is referred to as a local class.

[Ch5.2] When an array argument is passed in a function call, can that function change the values stored in that array in C++?

Yes, it can as it has access to the memory location of the array being passed.

[Ch6.1] Can a structure type definition be used like predefined types when defined in C++?

Yes, it can be used like types for int, char, and etc.

[Ch2.2] Can a case of a switch statement be defined by variable with the const modifier in C++? (Eric)

Yes, it can because that variable is restricted from changing its current value.

[Ch5.2] Can the "const" modifier be used with any kind of parameter in C++?

Yes, it can but it is normally used only with array parameters and call-by-reference parameters for classes.

[Ch7.1] Can a constructor behave like a function that returns an object of its class type in C++?

Yes, it can but it still does not syntactically have a return type.

[Ch7.2] Can a nested class be either public or private in C++?

Yes, it can. If the nested class is private, then it cannot be used outside of the outer class. If the nested class is public, then it can be used as a type outside of the outer class.

[Ch3.2] Should the main function have a return statement in C++?

Yes, it is a requirement for the program to run.

[Ch7.2] Is a local class only defined within the scope of the function definition where the class is defined in C++?

Yes, it is and therefore a local class may not contain static members.

[Ch3.3] Is a variable that is declared inside a compound statement local to that pair of braces in C++?

Yes, it is but the name of the variable declared inside can be reused outside the compound statement for a different variable.

[Ch3.2] Can functions have no arguments in their declaration in C++?

Yes, it is perfectly legal for functions with no arguments. In this case there are no formal parameters listed in the function declaration and no arguments used when the function is called. the

[Ch5.2] When using the "const" modifier in a function definition is it required to have that modifier in the function declaration as well in C++?

Yes, it is required so that the function heading and the function declaration are consistent.

[Ch5.2] When the "const" modifier is used for one array parameter of a particular type, should it be used for every other array parameter of the same type that is not to be changed by that function in C++?

Yes, it should be because using the "const" parameter modifier is an all-or-nothing proposition. The reason why this is required is due to function calls within function calls that require protecting each array argument.

[Ch5.4] For a multidimensional array are each indexed variable of the base type for that array in C++?

Yes, just as a one-dimensional array.

[Ch6.2] Should classes be designed to be like an ADT in C++?

Yes, that is the details of how the "operations" are implemented should be hidden from, or at least irrelevant to, any programmer who uses the class. The operations of a class are the (public) member functions of the class. A programmer who uses a class should not need to even look at the definitions of the member functions. Only the member function declarations, given in the class definition, and a few comments should be all a programmer needs in order to use the class.

[Ch7.3] Can you initialize a vector of integers using a for loop and square brackets in C++?

Yes, the following (with declaring a vector of integers named v): for (unsigned int i = 0; i < 10; i++){ v[i] = i; } Assigns values to each position of the vector equal to 0 through 9. However, in order to set an element greater than i or equal to 10, then you would have to use the member function "push_back".

[Ch6.2] In classes are members that do not follow any access specifier defaulted to private in C++?

Yes, the members of that group will automatically be private.

[Ch3.2] When making nested function calls are functions that will be called required to have either a function declaration or definition before the call is executed in C++?

Yes, the same rules apply to nested function calls.

[Ch4.1] Can call-by-reference parameters be used in both void and return a value functions in C++?

Yes, they are not restricted.

[Ch3.2] Can both void functions and functions that return a value have return statements in C++?

Yes, they both can. In the case of a function that returns a value, the return statement specifies the value returned. In the case of the a void function, the return statement does not include any expression for a value returned it simply ends the function call. If a void function does not have a return statement then it will end after executing the code in the function body.

[Ch3.2] Can a function return a type "bool" and if they so, then how can readability of a function definition be implemented in C++?

Yes, they can and in a function definition you can return a Boolean expression. (e.g. bool appropriate(int rate) { return ((rate >= 10) && (rate < 20) || (rate == 0)); } )

[Ch7.2] Can any function be defined as an inline function in C++?

Yes, they can.

[Ch1.2] Do the operators && (and), || (or), the comma operator guarantee an order of evaluation in C++?

Yes, they do and it is always left to right.

[Ch6.1] Do the initializing values correspond to the order of member variables in the structure-type definition in C++?

Yes, they do so they must be in the corresponding order.

[Ch5.4] When accessing indexed variables of a multidimensional array, must each index be enclosed in its own set of square brackets in C++?

Yes, they must be enclosed in the square brackets, similar to how one-dimensional arrays access indexed variables.

[Ch1.3] Are numbers required to be separated by delimiting characters such as whitespace or line break in C++?

Yes, they must be separated by one or more spaces or by a line break. The computer will skip over any number of blanks or line breaks until it finds the next input value. This behavior holds for reading data into a string which means you cannot input string that contains spaces.

[Ch5.2] When an array argument is plugged in for its corresponding formal parameter does the base type have to match that of the formal parameter in C++?

Yes, this is a requirement for the array to be passed as an array argument.

[Ch7.1] Can a constructor of a class be overloaded in C++?

Yes, this is legal and this is done so that objects of that class type can be initialized in more than one way.

[Ch7.1] Can a class have a member variable whose type is that of another class in C++?

Yes, this is legal refer to the example in the image above.

[Ch6.2] Can member functions be overloaded in C++?

Yes, this is legal.

[Ch8.1] Can both unary and binary operators be overloaded in C++?

Yes, this is legal.

[Ch4.1] Can a function declaration have a mixed parameter list with call-by-value and call-by-reference parameters in C++?

Yes, this is legal. (e.g. void goodStuff(int& par1, int par2, double& par3); )

[Ch6.1] Can a structure have call-by-value or call-by-reference parameters of a structure type and return a structure in C++?

Yes, this is legal. (e.g. CDAccountV1 doubleInterest (CDAccountV1 oldAccount) { CDAccountV1 temp; temp = oldAccount; temp.interestRate = 2*oldAccount.interestRate; return temp; } )

[Ch7.1] Can a constructor declare multiple class type objects in the same line in C++?

Yes, this is legal. (e.g. DayOfYear date1(7, 4), date2(5, 5); )

[Ch7.2] Can the "const" parameter modifier be used with member functions of a class in C++?

Yes, this is legal. (e.g. bool isLarger(const BankAccount& account1, const BankAccount& account 2){ return(account1.getBalance() > account2getBalance()); } )

[Ch6.2] Can you use the names of all member of a class in the function definition for a member function without the dot operator in C++?

Yes, this is legal. (e.g. member var: month and day void DayOfYear::output(){ switch(month){ ...} cout << day; } )

[Ch6.1] Can structures have a hierarchy that includes members that are smaller structures in C++?

Yes, this is legal. (e.g. struct Date { int month; int day; int year; }; struct PersonInfo { double height; //in inches int weight; // in pounds Date birthday; }; )

[Ch6.2] Can a class have numerous occurrences of "public" and "private" access specifier in a class definition in C++?

Yes, this is legal. The same characteristics for both access specifiers apply for all items that follow them no matter the number of occurrences.

[Ch3.2] Do function declarations end with a semicolon in C++?

Yes, this is required for every function declaration.

[Ch6.1] Is there an error when there are more initializer values than struct members in C++?

Yes, this will cause an error.

[Ch1.3] Can you list multiple variables in a single cin statement in C++?

Yes, you can which is good separating variables to be stored respective based on their position in the cin statement. (e.g. cin >> dragons >> trolls; )

[Ch5.1] Can you declare arrays and regular variables together on the same line of code in C++?

Yes, you can. (e.g. int next, score[5], max; )

[Ch2.2] Can you have two case labels for the same section of code in a portion of a switch statement in C++?

Yes, you can. (e.g. case 'A': case 'a': cout << "Excellent. " << "You need not take the final. \n"; break; )

[Ch7.2] When using the "const" modifier for a member function of a class is it required to include it in both the declaration and definition in C++?

Yes. (e.g. class BankAccount{ public: ... void output() const; ... }; void BankAccount::output() const{ ... } )

[Ch1.3] What can be read by the cin object in C++?

You can read in integers, floating-point numbers, characters, or strings using cin.

[Ch1.2] What is the general rule for assignment compatibility in C++?

You cannot place a value of one type in a variable of another type. Placing data of one type into another can cause "automatic type conversion" (aka type coercion).

[Ch4.2] What happens when having more than one default arguments when a function is invoked in C++?

You must omit arguments starting from the right.

[Ch1.3] What is the difference between using \n and endl in console output in C++?

\n must always be inside quotes and endl should never be placed inside quotes.

[Ch6.1] a) What is a structure value of a structure type definition in C++? b) What is member value of a structure type definition in C++? c) What are member variables of a structure type definition in C++? d) What is a structure variable of a structure type definition in C++?

a) A collection of smaller values called member values in a structure definition. b) A member value is a data member of the structure definition. There is one member value for each member name declared in the structure definition. (e.g. from Project 3 - a value of the type Node is a collection of three member values, one of type int, another of type string, and lastly of type Node (pointer)) Member values that all together make up the structure value are stored in member variables. c) A smaller variable that is associated with member names that is a part of the larger structure variable. Member variables are specified by giving the name of the structure variable followed by a dot and then the member name. (e.g. from Project 3 - Node.m_int) d) A variable of the type of structure that can hold structure values. (e.g. on pages 243-244)

[Ch6.1] Based on the previous example given, how could an object of the PersonInfo structure output the year of the birthday member name?

cout << object_name.birthday.year << endl;

[Ch1.2] What is an example of a complicated expression for declaring and assigning variables in C++?

double rate = 0.07, time, balance = 0.00;

[Ch2.3] What is the structure of a for statement in C++?

for (Initialized_Action; Boolean_Expression; Update_Action)

[Ch7.3] How do you declare a vector in C++?

vector<int> v; Where the notation "vector<Base_Type>" is a template class, which means you can plug in any type for the Base_Type and that will produce a class for vectors with that base type.


Set pelajaran terkait

Processes, Media, and Channels Quiz

View Set

Chapter 2 - Network Infrastructure and Documentation

View Set

Infant and Toddler Midterm Practice

View Set

"Final Exam", Professor Gawn Econ 101 Multiple Choice

View Set

Chapter 1.1 and 1.2 Religion Test

View Set

Chapter 2 Monitoring and Diagnosing Networks

View Set