Spararama

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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

.length() or length()

What will the output be of the follwing code snippet: int x{3}; int y{4}; float z; z = x/y; std::cout << z; Anwer: 7500000001 0 .7499999999 .75

0

assembler high level languages compiler interpreter

Translates assembly language into machine code 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 a program that reads source code and produces a stand-alone executable program that can then be run a program that directly executes the instructions in the source code without requiring them to be compiled into an executable first

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

True

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

True

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

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

faster- lower level portable- higher leverl more readable- higher leverl require a lot of instructions to do a simple task- lower level

A _________ _____________ is an array where the length is known at compile time.

fixed array / fixed length array / fixed size array

A __________ ___________ type variable is a variable that can hold a real number

floating point

________________ have a special meaning within the C++ language

keywords / key words

a collection of sequential characters called a __________

string

A(n) __________ indicates which "slot" in the array you are trying to access

subscript or index

The set of rules that govern how sentences are contsructed in a language (spoken/written/programming/etc) is called ____________.

syntax

You should ALWAYS use unsigned integer for loop counters.

False - This can lead to unexpected behavior if the counter goes negative.

an enum class places all its items in the global namespace

False - an enum class puts its items in a namespace that is the same as the enum's name.

Defining an enumeration allocates memory for it..

False - memory is allocated when you defining a variable of the enumerated type.

std::endl is more efficient than using \n

False - std::endl also flushes the buffer.

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. _value Answers: Legal Good for variable name Good for function name Good for type name for user-defined type not Legal

Legal

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 Answers: Legal Good for variable name Good for function name Good for type name for user-defined type not legal

Legal Good for type name for user-defined type

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. twoPosition Answers: Legal Good for variable name Good for function name Good for type name for user-defined type not Legal

Legal Good for variable 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. Bank Answers: Legal Good for variable name Good for function name Good for type name for user-defined type not Legal

Legal Good for type name for user-defined type

You can start a std::vector with available slots by initializing it with some values, or use a number in () Answers: True False

True

You should not use floats for comparisons because of rounding errors. Answers: True False

True

a function always has () after it's name, though there may be things between the ( and the ) Answers: True False

True

curly braces {} are often used to indicate a block of code which groups multiple statements such as for function bodies.

True

for purposefully intentional loops, you should use "while(true)"

True

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

True

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

True

unsigned integers should be avoided because of wrap around effects. Answers: True False

True

while loops are prefered over do/while loops. Answers: True False

True

you should avoid == operator when comparing floats. Answers: True False

True

It is possible to grab multiple words of input on a single line using std::cin

True - std::cin >> x >> y;

You should favor list (uniform) initialization over copy and direct initialization. Answers: True False

True- It can sometimes be a bit slower than direct initialization, but it has a lot of benefits such as not allowing narrowing conversions and a unifrom method for all initialization.

What does the following code snippet print to the monitor: int x = 4; if(x <= 3 || x > 5){ cout << "You win" } else{ cout << "You lose" } cout << " the prize!"; Answers: You win You lose You win the prize! You lose the prize!

You lose the prize!

Code implementing undefined behavior may exhibit any of the following symptoms: Answers: Your program seems like its working but produces incorrect results later in the program. Your program works on some compilers but not others. Your program produces different results every time it is run. Your program works until you change some other seemingly unrelated code. Your computer may spontaneously combust Your program crashes, either immediately or later. Your program consistently produces the same incorrect result. Your program behaves inconsistently (sometimes produces the correct result, sometimes not).

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

Which loop is correct? (condition)Answers: do {//code}while (condition);do {//code}while (condition)do {//code}while (condition):

do {//code}while (condition);

How is an array declared? Answers: int myArray [5] int myArray(5) int myArray {5}

int myArray [5]

______________ _________________are values inserted directly into the code

literal constants

Match the terms with their definitions (0.5) object file linker portable library file C++ Standard Library

machine language file typically named name.o or name.obj, where name is the same name as the .cpp file it was produced a program that takes all the object files generated by the compiler and combine them into a single executable program, links library files, resolves cross-file dependencies. usable without major rework for different types of system a collection of precompiled code that has been "packaged up" for reuse in other programs an extensive library, core to C++, that provides additional functionality that you can use in your programs

When defining an enum, the name should be capitalized Answers: True False

True

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

-128 127

When creating multiple variables on the same line, in one command, it is possible to create variables of differing types.

False

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

False

switch statements MUST have a "default label"

False

C++ excels in situations where the following is needed. Answers: High Performance easy to read writing code quickly and getting it up and running. Precis control over memory

High Performance Precis control over memory

The following code snippet: int x{3};std::cout << x; Will output x or 3

It will output 3

consider the following code fragment:int i = 0;while (i < 0){cout << "hi ";}What does the code output? Answers: It won't ouput anything. hi It will ouput an error It will output an infinite number of "hi"

It won't ouput anything.

Match the terms with their definition. operation operands operator precedence associativity

a mathematical calculation involving zero or more input values input values for a mathematical calculation. The specific operation to be performed, denoted by a construct (typically a symbol or pair of symbols) The order in which operators are evaluated in a compound expression 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

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] Answers: 23 4 4 2 4 4 2 23 23 4 23 23 23 8 8 2 8 8

23 4 4

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

9

__________ is the output stream operator indicating data that will be displayed on the console when used in collaboration with std::cout

<<

Unlike regular, c-style arrays, the size of a std::array does not need to be known at compile time. Answers: True False

False

Check ALL that are true about types in C++ - Any type can be changed (cast) to another type - 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 - There are fundamental and user-defined variations

Answers - 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 - There are fundamental and user-defined variations

Match the type of initialization with the example: Question - Copy initialization Direct Initialization List (uniform) initialization Answer Choices - A. int x{3}; B. int x(3); C. int x=3;

Answers Copy initialization - C. int = 3; Direct Initialization - B. int x(3); List (uniform) initialization - A. int x{3};

Math the terms with their definitions (0.2) Terms Machine Code Binary Digit/Bit Portable Definitions A. usable without major rework for different types of system B. Each individual 0 or 1 C. The limited set of instructions that a CPU can understand directly

Answers Machine Code - C. The limited set of instructions that a CPU can understand directly Binary Digit/Bit - B. Each individual 0 or 1 Portable - A. usable without major rework for different types of system

Match the term with it's definition Terms Naming Collision Namespace Global Namespace Scope Resolution Operator Answer Choices A. The identifier to the left of the :: symbol identifies the namespace that the name to the right of the :: symbol is contained within. If no identifier to the left of the :: symbol is provided, the global namespace is assumed. B. In C++, any name that is not defined inside a class, function, or a namespace is considered to be part of an implicitly defined namespace C. two identical identifiers introduced into the same program in a way that the compiler or linker can't tell them apart, D. a region that allows you to declare names inside of it for the purpose of disambiguation.

Answers Naming Collision - C. two identical identifiers introduced into the same program in a way that the compiler or linker can't tell them apart, Namespace - D. a region that allows you to declare names inside of it for the purpose of disambiguation. Global Namespace - B. In C++, any name that is not defined inside a class, function, or a namespace is considered to be part of an implicitly defined namespace Scope Resolution Operator - A. The identifier to the left of the :: symbol identifies the namespace that the name to the right of the :: symbol is contained within. If no identifier to the left of the :: symbol is provided, the global namespace is assumed.

Match the compilation stage with what it does. Preprocessor - Compiler - Assembler - Linker/Loader - Answer Choices A. Translates code into assembly instructions for a specific architecture. B. Generates machine code. C. Strips comments from the code and deals with any # commands D. - Organizes Machine Code - Links External Libraries - Creates Final executable files

Answers Preprocessor - C. Strips comments from the code and deals with any # commands Compiler - A. Translates code into assembly instructions for a specific architecture. Assembler - B. Generates machine code. Linker/Loader - D. - Organizes Machine Code - Links External Libraries - Creates Final executable files

differentiate between characteristics of lower level languages and higher level languages. Answer Choices - Faster Portable More Readable Require a lot of instructions to do a simple task

Answers - Faster - lower level Portable - higher level More Readable - higher level Require a lot of instructions to do a simple task - lower level

Which are true about identifiers in C++ Answers: C++ is case sensitive, and thus distinguishes between lower and upper case letters. nvalue is different than nValue is different than NVALUE. The identifier must begin with a letter (lower or upper case) or an underscore. It can not start with a number. The identifier can only be composed of letters (lower or upper case), numbers, and the underscore character. That means the name can not contain symbols (except the underscore) nor whitespace (spaces or tabs). The identifier can not be a keyword. Keywords are reserved

C++ is case sensitive, and thus distinguishes between lower and upper case letters. nvalue is different than nValue is different than NVALUE. The identifier must begin with a letter (lower or upper case) or an underscore. It can not start with a number. The identifier can only be composed of letters (lower or upper case), numbers, and the underscore character. That means the name can not contain symbols (except the underscore) nor whitespace (spaces or tabs). The identifier can not be a keyword. Keywords are reserved

Preprocessor macro directives are still commonly used in modern program. Answers: True False

False

This is an appropriate use of the auto keyword: auto x = 4; True False

False

ALL lines are ignored by the compiler that are between the /* symbol and the */ symbol, as these denote a multi-line comment.

True

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

True

Floating point data types are always signed Answers: True False

True

If you want to cout the names of the items in an enum, you should switch on a variable of the enum type and std::cout the name in the corresponding case.. Answers: True False

True

It is good to treat compiler warnings as if they were errors and fix them right away. Answers: True False

True

It is possible to write any for loop as a while loop and vice-versa Answers: True False

True

Objects of fundamental data types are generally extremely fast. Answers: True False

True

The ! operator flips the Boolean value. Answers: True False

True

Computer Program/Application Programming source code (or just code) hardware running/executing a program

a set of instructions that the computer can perform in order to perform some task The process of creating a program a list of commands typed into one or more text files The collection of physical computer parts that make up a computer and execute programs When a computer program is loaded into memory and the hardware sequentially executes each instruction

object file linker portable library file C++ Standard Library

machine language file typically named name.o or name.obj, where name is the same name as the .cpp file it was produced a program that takes all the object files generated by the compiler and combine them into a single executable program, links library files, resolves cross-file dependencies. usable without major rework for different types of system a collection of precompiled code that has been "packaged up" for reuse in other programs an extensive library, core to C++, that provides additional functionality that you can use in your programs

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

modulus

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. 2dArray Answers: Legal Good for variable name Good for function name Good for type name for user-defined type not Legal

not Legal

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 Answers: Legal Good for variable name Good for function name Good for type name for user-defined type not Legal

not Legal

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. isDone? Answers: Legal Good for variable name Good for function name Good for type name for user-defined type not Legal

not Legal

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. return Answers: Legal Good for variable name Good for function name Good for type name for user-defined type not Legal

not Legal

We call the set of specific values that a data type can hold its _____________

range

program state debugger Stepping step into step over Step out breakpoint

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 a computer program that allows the programmer to control how another program executes and examine the program state while that program is running. the name for a set of related debugger features that let us execute (step through) our code statement by statement. 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. ill execute an entire function without stopping and return control to you after the function has been executed. executes all remaining code in the function currently being executed, and then returns control to you when the function has returned. a special marker that tells the debugger to stop execution of the program at the breakpoint when running in debug mode.

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

true

Mark all that are true about a programming statement type of instruction that causes the program to perform some action most common type of instruction in a C++ program smallest independent unit of computation in the C++ language act much like sentences do in natural language Most (but not all) statements in C++ end in a semicolon a single statement may compile into many machine language instructions statements are limited to about 60 characters. must be written as a single line of code

type of instruction that causes the program to perform some action most common type of instruction in a C++ program smallest independent unit of computation in the C++ language act much like sentences do in natural language Most (but not all) statements in C++ end in a semicolon a single statement may compile into many machine language instructions

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

uninitialized


Kaugnay na mga set ng pag-aaral

Chapter 17. Activity - Based costing and analysis

View Set

Major Nerve Plexuses and Select Nerves

View Set

Almost, Maine - Daniel (Man) and Hope

View Set

Communities Develop and Montana Becomes a Territory

View Set