ECE 1310 FINAL

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

A variable's scope has to do with what? a) Where in the program it is visible and able to be used. b) How long ago (in computer time) it was declared and initialized. c) How large a number it is able to hold. d) How much precision and accuracy it is capable of.

Where in the program it is visible and able to be used.

How can you print out the contents of a pointer? (i.e. the address it contains) a) With Console : : ReadLine () b) Use cin c) Use cout d) none of the above

Use cout

Some valid scopes for an identifier are: a) function scope b) file scope c) block scope d) operating system scope e) all of the above f) a, b, c

a, b, c

How should a programmer normally terminate an infinite series like exponential or factorial? a) Keep calculating until the answer matches your calculator's value. b) Loop a fixed number of times and take the resulting answer. c) Check the size of the last term against some threshold, and if it's smaller, quit the loop. d) Use calculus to see when the answer converges.

c) Check the size of the last term against some threshold, and if it's smaller, quit the loop.

Local variables are: a) of type int b) are made before the program runs c) automatic storage class, by default. d) always global

c) automatic storage class, by default.

(T IF) exp () , main () , cout, and pow () are all examples of functions.

false

(T/F) A default argument is typically specified in the function's body in the * .h file.

false

(T/F) Declaring a variable name in an inner scope to cover up a variable with the same name in an outer scope is considered good style.

false

(T/F) It is considered a clever programming strategy to use the same name for variables in inner scopes as in outer scopes, so that the outer scope variable is hidden.

false

(T/F) Once a reference is declared and bound to a variable, it can be changed.

false

(T/F) The C++ standard library function, rand () generates/returns random numbers with a Rayleigh Distribution.

false

(T/F) The C++ statement: int randNum = 500+rand () % 50000; generates random numbers between, and including 500 and 50000.

false

(T/F) The main reason for functions: to organize the code in a way makes it less difficult for the computer to manage the complexity of large programs.

false

(T/F) When a function argument is "passed by value", it is passed as the real variable (not a copy).

false

(T/F) continue statements return to the top of while, for, do-while and switch statements.

false

Using the unnamed enum: enum {bitl=0xl}; ,write the line of code that will unset (set to 'O') a register's 15th bit without affecting the other 31 bits in the register. Assume the register is already declared and exists with the name myReg.

myReg &= ~(bit1 << 15)

In the C++ statement: double *p1, p2; a) p1 is a pointer to double and p2 is a double b) p1 and p2 are both pointers to double c) p1 and p2 are both reference types d) p1 and p2 are both value types

p1 is a pointer to double and p2 is a double

The C++ statement: int randNum = 1 + rand() % 100; will generate and assign (to randNum) _ _ _ a) random whole numbers in the range 1 to 100, inclusive b) random floating point numbers in the range 1 to 100, inclusive c) random whole numbers in the range 2 to 99, inclusive d) random whole numbers in the range O to 99, inclusive e) none of the above

random whole numbers in the range 1 to 100, inclusive

Declaring a parameter as a constant reference (i.e. const) __ . a) simulates the appearance and security of pass-by-value. b) allows for easy differential calculus throughout the program. c) will not ensure the your data will be safe from overwrite. d) none of the above.

simulates the appearance and security of pass-by-value.

The keyword void in a C++ function parameter list: a) shows that anything can be passed to the function. b) shows that a function does nothing when called. c) is a hint to the programmer that the function is a system call. d) specifies that a function takes no arguments.

specifies that a function takes no arguments.

Given the following lines of C➔+ code: int i1 = 10000; int* iPtr = &i1; what construct would you use to access the variable i1 through the pointer iPtr a) &iPtr b) *iPtr c) .iPtr* d) iPtr .il

*iPtr

Assuming that iArray is an array of integers 4 elements long, the following C++ code results in what values stored in the array elements? for (inti= O; i < 4 ; i++) { iArray[i] = i+i; } a) 0, 1, 2, 3 . b)0,1,4,9 C) 1, 2, 3, 4 d) 0, 2, 4, 6

0,2,4,6

What value will be stored into i1? (Express your answer in shorthand hex notation): unsigned int i1 = ~0xDEADBEEF;

0xFEEBDAED

In a 32-bit register, what mask (written in hex-shorthand) would be used for the field consisting of bits 12- 19?

0xFFC00

Assuming that the array iArray contains the values 0, 1, 2, 3. Also assume that the array i2Array is an array containing 4 elements all set to zero. What four values will i2Array contain after the code executes? for (inti= O; i < 4; i++) { i2Array[ iArray[i] ] = iArray[i] + 1; }

1,2,3,4

Explain (1) what bit number is being manipulated by this bit-bashing code. Also explain (2) what is being done to the bit: unsigned int HWReg; HWReg I= (Oxl << 30);

1. it shifs to the right 30 positions 2. 30th bit is turned on

In the following code, what is the value assigned to down by the compiler? enum {up=lOO, down}; a) 0 b) 1 c) 2 d) 100 e) 101 f) 102

101

After the following C++ code executes: int il = 6; int i2 = 30; int* intPtrl = &il; *intPtrl = i2; what is the value of il? a) 5 b) 6 c) 22 d) 30

30

In a 32-bit register, what mask (written in hex-shorthand) would be used for the field consisting of 10-20 bits?

CtrlReg |= 0x1ffcoo

Why would a progrrunmer choose a recursive solution over an iterative solution? a) If one desires to be as efficient as possible. b) If one has to program problems that involve Bessel functions. c) If the recursive solution more accurately mirrors the problem, or is easier to understand and debug. d) If pointers or references are used.

If the recursive solution more accurately mirrors the problem, or is easier to understand

What is about the only reason to use a do-while structure over a while structure? a) It can execute much faster. b) It has proven to be the best formatting available. c) It is guaranteed to execute its contained statements once, even if its test is false. d) It is unique in its ability to execute infinite loops, like in operating system coding.

It is guaranteed to execute its contained statements once, even if its test is false.

(T/F) break statements exit while, for, do-while and switch statements.

True

Reasons for using reference-types (pointers and references): a) to allow low-level communication with hardware. b) to allow for much better performance and efficiency in moving data around. c) for purely decorative reasons. d) to allow easy C++ communication with other programming languages. e) a& b f) none of the abov

a & b

What is true of a variable declared as const? a) It is not allowed to be changed from its originally assigned value. b) It is a compiler error if it's changed. c) It can only be used in mathematical equations. d) No fractional value can ever initialize it. e) a& b f)c&d

a & b

A data structure is: a) a function that can operate on large amounts of data b) a collection of related data items c) a looping structure that loops over data collections d) none of the above

a collection of related data items

Code like this: is: double myFunction(int il) { double dl = cos(2*twoPI*il); return dl; } a) a function body b) a function prototype c) all of the above d) none of the above

a function body

Code like this: int myFunction(int il, double dl); is:

a function prototype

The type double * is a) a reference to type fl.oat b) a pointer to type cin c) a reference to type double d) a pointer to type double

a pointer to type double

Declare and initialize a double variable, d1, and then declare a pointer to a double. (1) Initialize the pointer with the address of d1. (2) Print out the value of d1, indirectly. (3) Set d1 to the value of 100, indirectly. (4) Write a line of code to make the pointer point to d2 instead of d1. (5) Print out the address of d2 using only the pointer.

code fragment

Write a [unction prototype (i.e. function interface, or function declaration) as you would put in the *. h file for a function that takes two doubles and returns an int. Then (2) write the function definition (i.e. function implementation) as you would put in the * .cpp file. It must divide the two doubles that are passed in and return the roundedup answer.

code fragment

Write a code fragment using a switch-statement to choose between 3 cases. Assume that an int variable named choice already exists and is "switched off of' in the switch-statement (i.e. you don't need to write the code that gets user input.) Furthermore, assume that choice can take on values 'O' - '2'. Add a default-case to "catch" any number not in the range 'O' - '2'. Print out a unique statement for each case, including default .

code fragment

Given a 32-bit register: unsigned int ControlReg; , using bitwise operators, how would you set the 0th bit (set it to '1 ') while leaving the other 31 bits as they are?

ctrlreg |= 0x1

Given the following :function prototype: int aFunc(doub1e * dl, const. d oubl e & d2, int il); what input arguments can the function, aFunc, change permanently? a) d1 b) d2 c) i1 d)a&b e) none of them

d1

The very first 'slot' of an array named, d, is accessed by what syntax? a) d[first] b) d[a] c) d[O] d) d[l]

d[0]

Write a program fragment that dynamically allocates an array of 100 integers, and uses a loop to (2) generate and (3) store in the array: 100 random products, where the products are x(i) * y(i), and the x(i) are random numbers such that 75 <= x(i) <= 750, and the y(i) are random numbers such that 20000 <= y(i) <= 33000.

int * p; cout << "How many numbers would you like to type? "; cin >> i; p= new int[i];

Of the available choices, which one legally "calls" a function whose prototype is: int myFunc(doub1e, int); a) int i1 = myFunc (double 3 .14, int 100) ; b)int i1 = myFunc(3.14, 100); c)int i1 myFunc(double, int); d)int i1 = myFunc(double, int); e) all of the above f) none of the above

int i1 = myFunc(3.14, 100);

One way to declare and a locate an array of five ints named iArray is: a) int *iArray[4]; b) int iArray[4]; c) int iArray [5] ; d)int *iArray[S]= new int;

int iArray [5] ;

The function declared as: int aFunction(double); a) takes a double and an int b) takes an int, and returns a double c) takes a double, and returns an int d) returns a double and an int

takes a double, and returns an int

Overloaded functions are distinguished by: a) the number of statements they contain. b) the amount of memory they consume during execution. c) their "signature". d) the number of times their called in a program.

their "signature"

(T/F) A pointer is a variable that contains addresses.

true

(T/F) An identifier's storage class determines the period during which that identifier exists in memory.

true

(T/F) Once a pointer is declared and loaded with an address, it can be changed.

true

(T/F) Overloaded functions that perform closely related tasks can make programs more readable and understandable.

true

(T/F) Pass-by-reference weakens security.

true

(T/F) Recursion occurs when a function calls itself, either directly, or indirectly through another function

true

(T/F) The "position-number" of an array is called an index.

true

(T/F) The following line of code is correct syntax: int aFunction(int size, double weight= 12);

true

(T/F) Variables of static storage class, exist in memory from the very beginning of the program.

true

(T/F) You should give your personal functions descriptive names that suggest what the function does.

true


Set pelajaran terkait

NUR 221 PrepU Psychiatric and Mental Health Nursing.

View Set

XCEL FINAL EXAM MISSED QUESTIONS

View Set

CMN 571 -- NP Questions from NPC Exam and Practice

View Set

Personal Finance (Midterm Exam Review)

View Set

Chapter 11 C++ Class Inheritance

View Set

PSYCH CHAPTER 5 PRE AND POST TEST QUESTIONS AND NCLEX

View Set