"Mini Boss Fight" study set for CPSC 1375

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

How many values can be held in the following arry: int myArray[8];

8

What is the greatest index for the following array: int myArray[10]

9

Where should you put function declarations used in int main()?

Before int main()

__________ scope means local variables are in scope from their point of definition to the end of the block they are defined with

Block

If your code does not follow the proper syntax of C++ the compiler will give you a ________ ________.

Syntax Error

Which loop will not work?

for (i=-; i<5; i++) ~or for (i=5; i<=10; i++) ~or for (i=5; i=10; i++)

Which for loop is correct?

for (i=0; i<10; i++)

Global variables have [fs], which means they are visible from the [pd] until the end of the [f] in which they are declared.

fs - File Scope pd - Point of Declaration f - file

What is the return type of a function with the following declaration: int foo(char x, float v, double t);

int

When we have a variable inside a nested block that has the same name as a variable in an outer block it is called

name hiding ~or~ shadowing

double num [9]; what is the name of this array?

num

Decide if this identifier is Legal, good to use as a variable name, good to use as a function name, good to use as a type name for a user-defined type, or not legal. More than one answer is possible. Select all that apply. CURRENT.VALUE

Not legal

_____________ ____________occur when the loop iterates one too many or one too few times to produce the desired result.

Off by one errors ~or~ Off-by-one errors

It's good practice to use parentheses to make it clear how an expression should evaluate, even if they are technically unnecessary.

True

Objects of fundamental data types are generally extremely fast

True

Objects or fundamental data types are generally extremely fast

True

Shadowing of local variables should generally be avoided, as it can lead to inadvertent errors where the wrong variable is used or modified.

True

Some operators can be unary or binary, depending on how they are being used

True

The ! operator flips the Boolean value

True

The modulus operator can be used to see if one number is divisible by another number.

True

The unary plus operator is redundant. It was added largely to provide symmetry with the unary minus operator

True

To increase the number of items on a std::vector, use the .push_back() method

True

When mixing logical AND and logical OR in a single expression, explicitly parenthesize each operation to ensure they evaluate how you intend.

True

While loops are preferred over do/while loops

True

std::cin only accepts 1 or 0 for boolen variables.

True

__________ ______________ is the result of executing code whose behavior is not well defined by the C++ language

Undefined Behavior

A variable that has not been given a known value (usually through initialization or assignment) is called

Uninitialized variable ~or~ uninitialized

Namespace cannot be nested

False

The C++ standard ALWAYS and EXPLICITLY defines the order in which anything in your code is evaluated.

False

The smallest index for an array is 1

False

The while loop will continue looping as long as the conditional evaluates to false!

False

This is a legal use of the auto keyword: auto x;

False

Variable will keep their updated values between loops if they are declared inside the loop

False

Variables declared inside a function are available for use outside the function

False

When a global variable is shadowed you can not access the global variable until the local variable goes out of scope

False

What is the best way to print out every value in an array

For loop

To use the iostream library, what command is needed at the top of your program?

#include <iostream> ~or~ #include<iostream>

Consider the following code fragment int i=0; while (i<0) {cout<< "hi";}

It won't output anything

When the postfix variation of ++ or -- are used, a copy of the value is made before the expression is evaluated

True

You have to use ::, the scope resolution operator, to access items in an enum class.

True

You should favor list (uniform) initialization over copy and direct initialization

True

You should not use floats for comparisons because of rounding errors

True

a do/while loop does not check the conditional until the loop has been run once

True

std::cin will grab input until it reaches any whitespace (space or newline)

True

when storing integer values in a bool, 0 is false, and any other value is considered true!

True

Which statement is better for the variable bool x;

if(x == true) ~or~ if(x)

the 'io' part of iostream stands for

input/output

Should you use a std::vector or std::array in this situation: You need a container to store the intensity of the pixels on a 1024x768 display

std::array

Which commands can be used to move the cursor to the next line:

std::cout<<'\n'; ~or~ std::cout<<std::endl;

Should you use a std::vector or std::array in this situation: You need a container to store information about students in a school district

std::vector

A collection of Sequential characters called a _________

string

Assume this code is inside the main function of a properly formatted C++ program and the vector library and the iostream library have been included at the top of the file. Write three lines of a program that: 1. Creates a vector of ints named vInt 2. adds the value 2 to the vector 3. Outputs the size of the vector to the console

(there are a ton of different possible answers, pay attention to the answer number you're looking for) 1. vector<int> vInt; 1. vector<int>vInt; 1. vector <int> vInt; 1. std::vector<int>vInt; 1. std::vector<int>vInt; 1. std::vector <int> vInt; 2. vInt.push_back(2); 3. cout<<vInt.size(); 3. cout<< vInt.size(); 3. std::cout<<vInt.size(); 3. std::cout << vInt.size();

You should ALWAYS use unsigned integer for loop counters.

False

using directives, such as "using namespace std;" are preprocessor directives

False

Which of these are conditional statements available in C++

Switch ~and~ if/else

By definition, an 8-bit signed integer has a range of [neg] to [pos]

-128 to 127

What are some debugging tools built into Visual Studio that allow you to "watch" the values stored in a variable when a program is running in debug mode and execution is paused:

-Hover your mouse over the variable -Use QuickWatch -The "Watch" window

Decide if this identifier is Legal, good to use as a variable name, good to use as a function name, good to use as a type name for a user-defined type, or not legal. More than one answer is possible. Select all that apply totalPointsScored

-Legal -Good for variable name

Check ALL that are true about types in C++

-There are fundamental and user-defined variations -What data can be stored in a variable depends upon its type -Is associated with how much memory is allocated for the variable -C++ is a strongly typed language

What are some good reasons to comment out your code?

-You're working on a new piece of code that won't compile yet, and you need to run the program -To find the source of an error -You've written new code that compiles but doesn't work correctly, and you don't have time to fix it until later. -You want to replace one piece of code with another piece of code

Code implementing undefined behavior may exhibit any of the following

-Your program seems like its working but produces incorrect results later in the program. -Your program works until you change some other seemingly unrelated code. -Your program behaves inconsistently (sometimes produces the correct result, sometimes not). -Your program consistently produces the same incorrect result. -Your program produces different results every time it is run. -Your program works on some compilers but not others. -Your program crashes, either immediately or later.

What is the output of the following code snipped: std::cout << 1/2;

0

What is the output of the following code snipped: std::cout<<1/2;

0

What will the output of the following code snippet: int x{3}; int y{4}; float z; std::cout << z;

0

Which of these are GOOD examples of using comments

1. //set pointed variable to true pointed = true; //increase player's health health = health + (level * 1.75); 2. //player just got hit by a pointed dart. poisned = true; 3. //player just leveled up, so we need to increase their health by a factor relative to their level! health = health + (level * 1.75); 4. //This solution may seem counter-intuitive, but has found to drastically increase performance on production.

Match the terms with their definition 1. Operation 2. Operands 3. Operator 4. Precedence 5. Associativity

1. A mathematical calculation involving zero or more input values 2. Input values for a mathematical calculation 3. The specific operation to be performed, denoted by a construct (typically a symbol or pair of symbols) 4. The order in which operators are evaluated in a compound expression 5. determines whether to evaluate the operators from left to right or from right to left when two operators with the same precedence level are adjacent to each other in an expression

Match the fundamental type with the data it can store 1. Float 2. Bool 3. Char 4. Int 5. Void

1. A member with a fractional part 2. True or False 3. A single character of text 4. Positive and negative whole numbers, including 0 5. No type

Match the term with its definition 1. Translation 2. Translation Unit 3. Preprocessor 4. Preprocessor Directives 5. #include directive 6. #define directive 7. Conditional Compilation Preprocessor Directives

1. A phase that happens before code is compiled 2. A code file with translations applied to it 3. A phase of translation. 4. instructions that start with a # symbol and end with a newline (NOT a semicolon). 5. the preprocessor replaces the this directive with the contents of the included file. The included contents are then preprocessed (along with the rest of the file), and then compiled. 6. can be used to create a macro. In C++, a macro is a rule that defines how input text is converted into replacement output text. 7. allow you to specify under what conditions something will or won't compile. There are quite a few different conditional compilation directives, the three that are used by far the most are: #ifdef, #ifndef, and #endif.

Match the configuration characteristic with the type of configuration it is describing 1. Designed to help you debug a program 2. Designed for when you are releasing a program to the public 3. Used for writing a program 4. Optimized for size and performance 5. Turns off optimizations and makes your program slower and larger 6. Does not contain extra debugging information 7. Normally the fault configuration in an IDE 8. Good for testing code performance

1. Debug Configuration 2. Release Configuration 3. Debug Configuration 4. Release Configuration 5. Debug Configuration 6. Release Configuration 7. Debug Configuration 8. Release Configuration

Correctly match the programming language to be either high-level or low-level 1. C++ 2. Java 3. Assembly 4. Machine Code

1. High Level 2. High Level 3. Low Level 4. Low Level

Match whether the phrase is describing a rule, best practice, or warning. (0.2) 1. Instruction you MUST do 2. things you SHOULD do 3. Thing you should NOT do 4. If you don't do this, your program won't work 5. Considered standard or highly recommended 6. Superior to other alternatives when there is one 7. Tend to lead to unexpected results

1. Rule 2. Best Practice 3. Warning 4. Rule 5. Best Practice 6. Best Practice 7. Warning

What are the characteristics of a Console Project?

1. Runs on a Linux, Mac, or Windows Console 2. Reads input from the keyboard 3. Only prints text to the screen 4. Compiles to a stand-alone executable

Match the compilation stage with what it does 1. Preprocessor 2. Compiler 3. Assembler 4. Linker/Loader

1. Strips comments from the code and deals with and # commands 2. Translates code into assembly instructions for a specific architecture 3. Generates Machine Code 4. Organizes Machine Code/Links external libraries/Creates final executable files

What are some advantages of C++

1. Strongly typed language 2. More control over memory 3. Object Oriented Language 4. Abstraction without cost

Match the terms with their definitions 1. Machine Code 2. Binary Digit/bit 3. Portable

1. The limited set of instructions that a CPU can understand directly 2. Each individual 0 or 1 3. Usable without major rework for different types of system

Match the term with its definition 1. Bit 2. Memory Addresses 3. Byte 4. Data Type 5. Fundamental Data Types

1. The smallest unit of memory, can hold a value of 0 or 1 2. Allows us to find and access the contents of memory at a particular location 3. A group of bits that are operated on as a unit. The modern standard is that a byte is comprised of 8 sequential bits 4. Tells the compiler how to interpret the content of memory in some meaningful way 5. Data types that are "built-in" to C++

Match the Visual Studio debugging window with the variables you would expect to see there 1. Autos 2. Locals 3. Watch

1. The variables currently being "acted upon" 2. The variables that exist within the current code block. That is, within the current set of {} 3. Variables the programmer manually added to the window

Match the terms with their definitions (0.2) 1. Assembler 2. High Level Languages 3. Compiler 4. Interpreter

1. Translates Assembly language into machine code 2. Programming languages designed to allow the programmer to write programs without having to be as concerned about what kind of computer the program will be run on 3. A program that read source code and produces a stand-alone executable program that can then be run 4. A program that directly executes the instructions in the source code without requiring them to be compiled into an executable first

Match the floating point type with its information 1. Float 2. Double 3. Long Double

1. Uses at least 4 bytes of memory ±1.18 x 10-38 to ±3.4 x 1038 6-9 significant digits, typically 7 2. Uses at least 8 bytes of memory ±2.23 x 10-308 to ±1.80 x 10308 15-18 significant digits, typically 16 3. Uses at least 16 bytes of memory ±3.36 x 10-4932 to ±1.18 x 104932 33-36 significant digits

What is best practice for naming an identifier?

1. Variable names should begin with a lowercase letter 2. Your identifiers should make clear what the value they are holding means (particularly if the units aren't obvious) 3. Avoid naming your identifiers starting with an underscore, as these names are typically reserved for OS, library, and/or compiler use. 4. If the variable or function name is multi-word, there are two common conventions: words separated by underscores, called snake_case, or intercapped (sometimes called camelCase, since the capital letters stick up like the humps on a camel). 5. Identifier names that start with a capital letter are typically used for user-defined types 6. if you're working in someone else's code, it's generally considered better to match the style of the code you are working in than to rigidly follow the naming conventions 7. An identifier with a trivial use can have a short name (e.g. such as i). An identifier that is used more broadly (e.g. a function that is called from many different places in a program) should have a longer and more descriptive name (e.g. instead of open, try openFileOnDisk).

Match the term with its corresponding definition: 1. Data 2. Program 3. RAM 4. Value 5. Object 6. Variable 7. Identifier 8. Runtime 9. Instantiation 10. Instance 11. Data type (or just type) 12. Integer 13. Compile-time

1. any information that can be moved, processed, or stored by a computer. 2. collections of instructions that manipulate data to produce a desired result 3. (short for random access memory), memory that is available for your programs to use 4. A single piece of data, stored in memory somewhere 5. a region of storage (usually memory) that has a value and other associated properties 6. A named object 7. the name of the object 8. When a program is run 9. The act of creating an object and assigning a memory address 10. An instantiated object 11. tells the compiler what type of value (e.g. a number, a letter, text, etc...) the variable will store. 12. a number that can be written without a fractional component, such as 4, 27, 0, -2, or -12 13. when the program is compiled

Typically comments should be used for the following three things:

1. at the statement level, comments should be used to describe why the code is doing something 2. within a library, program, or function described above, comments can be used to describe how the code is going to accomplish its goal. 3. for a given library, program, or function, comments are best used to describe what the library, program, or function, does. These are typically placed at the top of the file or library, or immediately preceding the function. comments can also be used to describe what the code is doing, at the statement level.

Math the type of initialization with the example 1. Copy initialization 2. Direct initialization 3. List (uniform) initialization

1. int x = 3 2. int x(3) 3. int x{3}

Match the terms with their definitions 1. Program State 2. Debugger 3. Stepping 4. Step into 5. Step over 6. Step out 7. Breakpoint

1. the value of the variables you're using, which functions have been called (so that when those functions return, the program will know where to go back to), and the current point of execution within the program (so it knows which statement to execute next). All of this tracked information is called 2. a computer program that allows the programmer to control how another program executes and examine the program state while that program is running. 3. the name for a set of related debugger features that let us execute (step through) our code statement by statement. 4. command executes the next statement in the normal execution path of the program, and then pauses execution of the program so we can examine the program's state using the debugger. 5. ill execute an entire function without stopping and return control to you after the function has been executed. 6. executes all remaining code in the function currently being executed, and then returns control to you when the function has returned. 7. a special marker that tells the debugger to stop execution of the program at the breakpoint when running in debug mode.

What is the output of the following code fragment: int myArray[5] = {2, 4, 6, 8, 10} myArray[0] =23; myArray[3] = myArray[1] cout << myArray[0] << " " << myArray[1] << " " << myArray[3]

23 4 4

Each of the variables in an array is called an __________

Element

An ________ ________ (also called an enumeration or enum) is a data type where every possible value is defined as a symbolic constant

Enumerated Type

The specific sequence of statements that the CPU executes is called the program's _________ __________

Execution Path

A blank line in code can indicate to the compiler how to group related instructions when creating the machine code

False

A for loop's init statement is run at the beginning of every loops

False

A name declared in a namespace may still be mistaken for an identical name declared in another scope

False

An enum class will implicitly convert enumerated values to integers

False

Based on the C++ Core Guidelines, this is good code: //x is the player's x position float x;

False

Comments remain in the code, unchanged, after compilation

False

Defining an enumeration allocates memory for it..

False

In C++ the objects refer to a variable, data structure in memory, or function

False

Integer overflow (often called overflow for short) occurs when we try to store a value that is outside the range of the type. Essentially, the number we are trying to store requires more bits to represent than the object has available. In such a case, more memory is allocated when the object doesn't have enough memory to store everything

False

When dividing by 0, the computer will ignore the expression and continue on with the program

False

You should ALWAYS use unsigned integer for loop counters

False

std::vectors have their sizes set at compile time, just like arrays

False

using directives, such as "using namespace std;" are preprocessor directives.

False

A ___________ ___________ is an array where the length is known at compile time

Fixed array ~or~ fixed length array ~or~ fixed size array

What do arrays do?

Store multiple values under a single identifier

________________ have a special meaning within the C++ language

Keywords ~or~ key words

decide if this identifier is legal, good to use as a variable name, good to use as a function name, god to use as a type name for a user-defined type, or not legal. More than one answer is possible. Select all that apply delete Object

Legal Good for function name

Decide if this identifier is Legal, good to use as a variable name, good to use as a function name, good to use as a type name for a user-defined type, or not legal. More than one answer is possible. Select all that apply. Account

Legal Good for type name for user-defined type

_______________ _________________are values inserted directly into the code

Literal constants

The variables that are part of a struct are called ___________

Member ~or~ Members

In order to access the individual members, we use the ________________ _____________ operator (which is a period)

Member Selection

The ____________ ______________ (also informally known as the remainder operator) is an operator that returns the remainder after doing an integer division

Modulus Operator

Decide if this identifier is Legal, good to use as a variable name, good to use as a funciton name, good to use as a type name for a user-defined type, or not legal. More than one answer is possible. Select all that apply 2dArray

Not legal

#include <iostream> Is a special instruction called a:

Preprocessor directive

A collection of sequential characters called a __________

String

A function is a named collection of statements that executes sequentially

True

An array's size must be known before a program will compile

True

An empty initializer list {} will initialize every value in an int array to 0

True

Avoid using directives (such as using namespace std;) at the top of your program. They violate the reason why namespaces were added in the first place.

True

Blank lines are ignored by the compiler

True

Both the ++ and -- operators can be prefix or postfix.

True

By convention, global variables are declared at the top of a file, below the include, but above any code

True

Char variables use a single byte of memory

True

Character literals are put in single quotes 'a'

True

Each item in an enum is seperated by a comma

True

For an enum, you need a semi-colon after the closing }

True

It is possible to never enter a while loop because the conditional is evaluated BEFORE the loop is entered

True

It's a good idea to give members of a struct a default value in the struct definition

True

Objects of fundamental data types are generally extremely fast.

True

Passing a variable "by reference" will cause changes to the corresponding parameter variable in the function to affect the value stored in the variable passed into the function.

True

Prefer a for loop over a while loop when there is an obvious "loop variable"

True

Shadowing of local variables should generally be avoided, as it can lead to inadvertent errors where the wrong variable is used or modified

True

The amount of memory reserved for a fundamental type is pre-defined, whereas memory needed for user-defined types can vary.

True

The continue keyword allows an early advancement into the next iteration of a loop

True

The end-expression is evaluated at the end of each loop and BEFORE the conditional statement

True

The name of a struct should begin with a capital letter

True

The statement: Return 0; in the int main() function indicated the end of a program execution and that the program exited normally

True

Unless you have an explicit reason to do otherwise, you should always initialize your variables upon creation

True

Unless you have an explicit reason to do otherwise, you should always initialize your variables upon creation.

True

Unsigned integers should be avoided because of wrap around effects

True

The following code snippet is from a working program. int x; cin >> x; switch (x) { case 0: cout << "Left "; case 1: cout << "Right "; break; case 2: case 3: cout << "Forward "; case 4: cout << "Back"; break; default: cout << "I'm lost! "; } Based on the code, what will be outputted if the user 0: [a] 1: [b] 2: [c] 6: [d]

[a] - Left Right [b] - Right [c] - Forward Back [d] - I'm Lost

The following code snippet is from a working program. int x; cin >> x; switch (x) { case 0: cout << "tango "; case 1: cout << "foxtrot "; case 2: case 3: cout << "delta ";break; case 4:default: cout << "Say again please! "; } Based on the code, what will be outputted if the user 0: [a] 1: [b] 2: [c] 4: [d]

[a] - tango foxtrot delta [b] - foxtrot delta [c] - delta [d] - Say again please!

Decide whether these statements apply to arrays, vectors, or both: Size set at compile time: [array1] Stores data in an array structure: [both1] Has a method for figuring out its size: [vector1] Can randomly access data (i.e. can jump directly to any spot): [both2] Use .push_back() to add new data: [vector2] Has little to no overhead: [array2]

[array1] - Array [both1] - Both [vector1] - Vector [both2] - Both [vector2] - Vector [array2] - Array

Decide whether the following types are fundamental or user-defined: Class [class] Int [int] Float [float] Struct [struct] Function [function] Char [char]

[class] - User-defined [int] - Fundamental [float] - Fundamental [struct] - User-defined [function] - User-defined [char] - Fundamental

When an identifier can be accessed, we say it is [is]. When an identifier can not be accessed, we say it is [os]

[is] - in scope [os] - out of scope

deferintiate between characeristics of a lower level languages and higher level languages -faster [l1] -portable[h1] -more readable[h2] -require a lot of instructions to do a simple task [l2]

[l1]-lower level [h1]-higher level [h2]-higher level [l2]-lower level

std::cout uses the [o] insertion operator to send text to the console to be printed while std::sin uses the [i] extraction operator to read input from the keyboard

[o] - << [i] - >>

Fill in the blanks for the following code to ensure the expected output #include <iostream>using namespace std; int manipulateTwoNumbers([param1] num1, [param2] num2, [param3] num3){ num1 = num1 + num3;num2 = num2 * num3; return num2-num1; } int main(){ int num1{4};int num2{3};int num3{-2}; cout << num1 << " " << num2 << " " << num3 << " " << manipulateTwoNumbers(num1, num2, num3) << endl; }

[param1] - int [param2] - int &? [param3] - int

the iostream library allows us to [r] and [w] from/to the console

[r] - Read [w] - Write

The scope resolution operator tells the compiler that the identifier specified by the [rh] operand should be looked for in the scope of the [lh] operand.

[rh] - right-hand [lh] - left-hand

A variable's [sd] determines what rules govern when and how a variable will be created and destroyed. In most cases, a variable's storage duration directly determines its [l]. Local variables have [a], which means they are created at the [pd] and destroyed at the [end] they are defined in

[sd] - Storage Duration [l] - Lifetime [a] - Automatic Storage Duration [pd] - Point of Definition [end] - End of the Block

Decide if a switch or an if/else statement should be used in the following situations: 1. You want to run a chunk of code depending on how many leaves are on a plant (numLeaves variable stored in a Plant class) [switch1] 2. You want to run a chunk of code depending on whether the health of a player is above 0. [ifelse1] 3. You want to run a chunk of code depending on whether the user ID entered matches the user ID stored in an account class [ifelse2] 4. You want to run a chunk of code depending on the number of sides on the dice in an instance of a Dice class [switch2] 5. You want to run a chunk of code depending on the value stored in a boolean variable [ifelse3]

[switch1] - Switch [ifelse1] - If/else [ifelse2] - If/else [switch2] - Switch [ifelse3] - If/else

Write a line of code that creates a reference variable named y that is a reference to the following int x=3;

int & y = x; int&y=x; int& y = x; int &y = x; int & y {x}; int& y {x}; int &y {x}; int&y {x}; auto & y = x; auto& y = x; auto &y = x; auto&y = x; auto & y {x}; auto& y {x}; auto &y {x}; auto&y {x}; auto & y{x}; auto& y{x}; auto &y{x}; auto&y{x}; int & y{x}; int& y{x}; int &y{x}; int&y{x};

How is an array declared

int myArray [5]

Fill in the blank in the code fragment so that it outputs: 0 2 4 6 8 10 Do not put any spaces in your answer!!!! for (int j = 0; j <= 10; [a] ) {cout << j << " ";}

j+=2 ~or~ j=j+2 ~or~ j += 2

How would I get the number of characters in the following code snippet: std::string myString myString.________

length() ~or~ .length()

Fill in the blank in the following code fragment so that each element of the array is assigned twice the value of its index: int myArray[10]; for(int i = 0; i < 10; i ++) {___________________}

myArray[i] = 2*i

The keyword used to transfer control from a function back to the calling function is:

return

In the following declaration, what is the name of the function? double stringTest (int x, float y);

stringTest

Say we have a function, double subtract (double x, double y), what is the correct way to call this function in the main program?

subtract (x, y)

Which of the following Boolean expressions will NOT cause an error if the x variable contains a value of 0

x ==0 || 1/x ~or~ x !=0 && 1/x


Ensembles d'études connexes

soc chapter 9: social stratification in the US

View Set

ch 1, 2, 4, 12, 13 quiz mult. choice/true or false

View Set

BIOL 2170 Chapter 7 Learning Curve

View Set