CS1B Final

Ace your homework & exams now with Quizwiz!

(T/F) Given the declaration int beta[20]; the statement cout << beta[3]; outputs the third element in the array

F

(T/F) Given the declaration float *p; The statement cout << p; will output a floating point value.

F

(T/F) Given two variables of type int, scoreSum and numScores, and a variable of type float, scoreAvg, the following expression scoreAvg = scoreSum / numScores; would place the correct average into scoreAvg.

F

(T/F) If name1 and name2 are of type c-string and they both contain the value "Sally", the expression name1 == name2 would evaluate to true

F

(T/F) If value is a variable, then &value is the physical address of that variable in memory.

F

(T/F) In C++, "A" and 'A' are equivalent.

F

(T/F) In C++, corresponding arguments from a calling function and parameters from a called function must have the same name

F

(T/F) In C++, corresponding arguments from a calling function and parameters from a called function must have the same name.

F

(T/F) In C++, the entire array or an individual element in array cannot be returned through a return statement

F

(T/F) In a C++ expression, all addition and subtraction are performed before multiplication or division

F

(T/F) In a black box testing, we are required to understand the internal structure of the code to correctly create the test cases

F

(T/F) In a while loop, we are not required to initialize the LCV prior to entering in the loop

F

(T/F) In physical memory, the nodes in a linked list are contiguous.

F

(T/F) In the statement cout << val the symbol << is called the extraction operator because it extracts a value from memory and displays it on the screen

F

(T/F) Once the program compiles it is guaranteed to execute correctly

F

(T/F) Once you assign a pointer to NULL it is a good practice to delete it.

F

(T/F) Pointers can be passed into a function, but they can't be returned.

F

(T/F) Pointers cannot be compared using relational operators.

F

(T/F) Queues can only be represented using a linked list.

F

(T/F) Stacks can only be represented using a linked list.

F

(T/F) Stacks can only be represented using linked-lists

F

(T/F) Structs can only be passed by reference

F

(T/F) Structs cannot be returned through a return statement, but an individual member can

F

(T/F) The & operator is called the indirection operator.

F

(T/F) The C++ directive #include <myheader.h> would include the user-defined header file myheader.h

F

(T/F) The expression num3 * = num1 + num2 * 10; could be written as num3 = num3 * num1 + num2 * 10;

F

(T/F) The following code segment will find the last node in a link-list (assume the list has been created and has at least one node). ptr = head; while (ptr != NULL) { ptr = ptr -> next; }

F

(T/F) The following code segment will output 9. int *pInt; *pInt = 9; cout << "The value at pInt: " << *pInt;

F

(T/F) The following statements will declare a 10 element array of integers: int AR_SIZE = 10; int intAR[AR_SIZE];

F

(T/F) The function heading void SomeFunc(float myFloatAr[ ]) causes a compile time error because the size of the array is missing

F

(T/F) The only arithmetic operations allowed when using enumeration type variables are increment and decrement.

F

(T/F) The order in which directives and declarations appear in a header file does not matter

F

(T/F) The programmer must know in advance how many nodes will be needed in a linked list.

F

(T/F) The statement cout << "Help\n\n\nme!"; would leave three blank lines between Help and me.

F

(T/F) The statement return 3 * alpha + 5; is valid in a void function

F

(T/F) The value of the C++ expression 7 - 3 * 5 is 20

F

(T/F) Two different enumerated types can have the same value.

F

(T/F) Two different enumerated types in the same program can have the same values

F

(T/F) Using globally declared constants is as dangerous as using globally declared variables

F

(T/F) We don't have to define the datatype for each member in a struct as long as they are all of the same datatype

F

(T/F) We don't have to define the datatype for each member in a struct as long as they are all of the same datatype.

F

(T/F) We should always pass parameters by reference because it takes less overhead

F

(T/F) We should always pass parameters by reference because it takes less overhead.

F

(T/F) When a floating point value is assigned to an integer variable, the fractional part is rounded.

F

(T/F) When a two-dimensional array is passed as a parameter, the C++ compiler ignores the size of both dimensions

F

(T/F) When the indirection operator is used with a pointer variable, you are actually working with the address the pointer is pointing to.

F

(T/F) When the result of a floating point expression is assigned to an integer variable, the fractional part is rounded

F

(T/F) When using arrays, the compiler will give you an out of bounds error if your index is not within a valid range

F

(T/F) When using cin.getline before cin >> it is essential to include a cin.get or cin.ignore for the program to properly accept input.

F

(T/F) When using numeric limits, it is necessary to have #include <ios> in your program.

F

(T/F) White box testing tests the overall functionality of the code

F

(T/F) You need to #include <fstream> when using streamsize.

F

(T/F) Which scenario(s) does a Queue represent? (Choose all that apply)

FIFO, LILO

(T/F) Which scenario(s) does a Stack represent? (Choose all that apply)

FILO, LIFO

(T/F) Queues can only be represented using linked lists

False

Given: void Func(int arr[ ], int size) and the following declaration in the main: int theArray[15]; which of the following is an appropriate call to Func

Func(theArray, 15);

What is recursion?

Process in which the result of each repetition is dependent upon the result of the next repetition

A data type tells the compiler

What type of data will be stored in memory and how much memory needs to be allocated

When should we use a void function over a value returning function?

When we are not returning any values, When we are returning more than one value

What is the difference between static and dynamic binding

Static binding happens at compile time - overloading Dynamic binding happens at run time - overriding

(T/F) Given int in1,in2; float fn3; The value of in1 is 4 after the following expression is evaluated: in1 = (fn3 = (in2 = 5) * 4 / 8) * 2

T

(T/F) Given the declaration int alpha[20]; int beta[20]; statements such as beta = alpha, cin >> beta, beta = = alpha are invalid because aggregate operations are not allowed on arrays

T

(T/F) The statement if(score[id] >= 90) { letterGrade[id] = 'A'; } is an example of the use of parallel arrays

T

(T/F) A c-string is an array of characters

T

(T/F) A singly linked-list can be traversed in one direction.

T

(T/F) An escape sequence can be used for formatting character strings.

T

(T/F) Array subscripts always begin at 0

T

(T/F) Both value and reference parameters can be declared in the same function heading

T

(T/F) C++ allows some aggregate operations on structs, but never on arrays

T

(T/F) C++ allows the members of a struct to be an array.

T

(T/F) Char is an integral datatype

T

(T/F) Different struct types can have the same member(field) names

T

(T/F) Elements in an array all must be the same datatype

T

(T/F) Entering a character value when a float or an int is expected will result in an infinite loop.

T

(T/F) Enumerated types simplify coding and makes code self-documenting.

T

(T/F) Every loop can be implemented recursively

T

(T/F) For Loops are pre-test loops.

T

(T/F) Given int in1,in2; float fn3; The value of in1 is 4 after the following expression is evaluated: in1 = (fn3 = (in2 = 5) * 4 / 8) *2;

T

(T/F) If a function contains a statement that changes a value parameter, only the copy of the argument is changed, not the original

T

(T/F) If a function contains a statement that changes a value parameter, only the copy of the argument is changed, not the original.

T

(T/F) If a search algorithm used to search an array is implemented as a value returning function, the return value should be the index that represents the location of the element found

T

(T/F) If name1 and name2 are of type string and they both contain the value "Sally", the expression name1 == name2 would evaluate to true

T

(T/F) If p is a pointer variable, the statement p = NULL; is used to ensure that pointer p is not pointing to anything.

T

(T/F) If there are several items in a parameter list, the compiler matches the parameters and the arguments by their relative positions in the lists

T

(T/F) In C++, dynamic variables are created and released during execution (run) time using the new and delete operations.

T

(T/F) In C++, the expression 2.5 + 8.0 % 6 would produce a compile time error

T

(T/F) In C++, we use structs to define records

T

(T/F) In the declaration char userName[25]; userName stores the base address where the beginning byte of 25 contiguous bytes are located (the base address)

T

(T/F) It is considered bad practice to have function definitions in a Header file.

T

(T/F) It is considered bad practice to initialize variables in the declaration section.

T

(T/F) It is necessary to use an .ignore() when using cin with an extraction operator followed by a cin.getline()

T

(T/F) LILO and FIFO are the synonymous.

T

(T/F) Pointers can be passed by value or by reference when using the & operator.

T

(T/F) String size is dynamically allocated

T

(T/F) Structs and individual members can be returned through a return statement.

T

(T/F) Suppose a function has a defined struct called PersonNode that has name as a member. Assume the pointer personPtr has been declared as type PersonNode and a new instance of that struct has been created. The following statement would be valid return personPtr->name;

T

(T/F) Test Stubs test whether the calling function is passing the proper values for the parameters

T

(T/F) The amount of memory AND the values to be stored in that memory for constants is determined at compile time.

T

(T/F) The declaration ifstream inFile; requires the fstream directive to be included in the program

T

(T/F) The elements in an array are accessed by an index and the members of a struct are accessed by using the dot operator

T

(T/F) The following code fragment if ( code > 10) cout << "high security"; else cout << "low security"; could be rewritten as cout << (code <=10 ? "low security": "high security");

T

(T/F) The following code segment would result in an inaccessible object (memory leak). int* p; int* q; p = new int; *p = 5; q = new int; *q = 10; p = q;

T

(T/F) The following is a valid use for a typedef: typedef float FloatArrayType[100];

T

(T/F) The name of an array is the address in memory of the first element

T

(T/F) The new operator allocates memory for a variable of the specified type and returns the address location of that memory location.

T

(T/F) The scope of a local identifier extends from the point of declaration to the end of the block in which it was declared

T

(T/F) The scope of a local identifier extends from the point of declaration to the end of the block in which it was declared.

T

(T/F) The size of an array is established at compile time rather than at run time

T

(T/F) The use of the C++ manipulators fixed and setprecision( ) require the header file iomanip to be included.

T

(T/F) The value of the expression 15 > x > 5 in C++ will always be false

T

(T/F) This is a valid operation for strings. str3 = str1 + str2;

T

(T/F) Typedef creates an alias for a datatype

T

(T/F) Used properly, the typedef declarations add readability to a program

T

(T/F) User-defined header files must have the .h extension

T

(T/F) Using the float value 10.0 in the statement avg = sum / 10.0; is an example of the use of a literal constant

T

(T/F) When passing parameters by reference, the address of the calling function's argument is sent to the function

T

(T/F) When the head pointer is pointing to NULL it signifies that the list is empty.

T

(T/F) When using a do while loop to validate an input we should continue executing the loop based on the range of inputs that are invalid.

T

(T/F) Without the struct datatype, storing information of different types as a set of data would require the use of parallel arrays

T

(T/F) You cannot input the value of an enumeration type directly from a standard input device.

T

(T/F) numeric_limits determines the size of an implementation specific type.

T

What should your loop check for?

That you havent reached the end of the linked-list, and that the search has not been found

What is a base case?

The simpler-to-solve problem is known as the base case Recursive calls stop when the base case is reached

What is a constructor

a special method that is called upon when an instance of an object is declared that instantiates the object

If a function is supposed to compute and return the average of five variables of datatype int, which is most appropriate function type?

a value returning function using value parameters

Which of the following may appear after an extraction operator ( >> )

a variable

Which of the following describes the execution of statements while certain conditions are met.

an if-then statement

What does it mean to say a class is composed of another class

attributes in one class are class types

Which data type(s) would be most appropriate to store names such as "Joe".

char

How do you access a member of a struct?

dot operator

What is the advantage of using structs?

easier to organize related data items

What is FIFO?

first in first out

What is the difference between a mutator and an accessor

mutator - modifies attributes accessor - uses attributes, but does not modify them

The following code would cause if (x > 5); { cout << "greater than five"; } cout << "\ncontinue";

no error

Given: int val, val2; // line 1 char name1[20]; // line 2 char name2[20]; // line 3 cin .getline(name1, 20); // line 4 cin.getline(name2,20); // line 5 cin >> val2; // line 6 To make the code fragment execute properly, cin.ignore (1000, '\n'); should be placed:

nowhere, it's not necessary

Parameter passage by reference is used if a parameter's data flow is

one-way, out of the function and two-way, into and out of the function

Are aggregate operations allowed on structs?

only assignments

We can avoid side effects by...

passing parameters by constant reference, passing parameters by value

How do you access members of a struct using pointers?

ptr->member

What if you want to access what the pointer member is pointing to?

ptr->next->member

Which of the following describes the execution of two or more alternative statements:

selection

Which category of datatypes includes enums?

simple

Define a struct called DvdRec that contains the title, genre, and running time.

struct DvdRec { string title; string genre; int time; };

Which category of datatypes includes arrays?

structured

What is the difference between structured and unstructured programming?

structured - Data is passed to functions, some data is managed by main, some by functions unstructured - everything is in main

If the two variables student1 and student2 were declared as struct type which had name and id as a member, then which of the following would be valid C++ statements:

student1 = student2;

The mathematical expression 1 <= x < 100 could be written in C++ as

x >=1 && x < 100 and 1 <= x && x < 100

Can structs be a return type?

yes

Can you pass structs by value or reference?

yes

(T/F) Given int nums[25]; only the subscripts less than 0 or greater than 25 would be said to be out of bounds

F

Among the C++ arithmetic operators, which ones have the highest precedence

*, / , and %

What is overloading

- Defining two methods of the same name in the same class differentiating them by their signatures - Functions and operators can also be overloaded - Static-Binding (resolved at compile time)

What is overriding?

- Redefining a method that has already been defined in the parent class (using the same signature) - Dynamic-Binding (resolved at run time)

What is the difference between structured and OOP?

- Structured: Focus is on functionality and data is passed through functions - OOP: Focus is on data and methods are used to access data

When we write functions we should...

- Write them such that they handle one specific task - Make them generic so that they can be reused - Pass by value or by constant reference if we are not returning a value through the parameter list

How do you access a member of a struct using pointers?

->

Given the function definition: int Mystery(float someVal) { int retVal; if(someVal > 2.0) retVal = 3 * int(someVal); else retVal = 0; return retVal; } What is the value of the integer variable anInt after the following anInt = Mystery(4.5); ?

12

Which of the following is not a valid identifier in C++?

2ndVal

What is the value of angle after execution of the following code fragment? Assume the value 5 is input for angle cin >> angle; if (angle >= 5) { angle = angle + 15; } if (angle > 2) { angle = angle + 10; }

30

what is a destructor

A special method that allows an instance of the class to be terminated

What is an ADT?

Abstract Data Type

What are the advantages and disadvantages of recursion?

Advantages: Models certain algorithms most accurately; results in shorter, simpler functions Disadvantages: May not execute very efficiently

The following code segment is an implementation of: const int AR_SIZE = 5; int intArray[AR_SIZE] = { 7, 12, 6, 4, 2}; for (int i = AR_SIZE-1; i >= 1; --i) { larger = intArray[0]; index = 0; for (int j = 1 ; j <= i; ++j) { if (intArray[j] > larger) { larger = intArray[j]; index=j; } } intArray[index] = intArray[i]; intArray[i] = larger; }

Bubble Sort

(T/F) Functions should be defined above the int main()

F

C++ source files should be arranged from top to bottom as indicated here. Select the correct one. A.Preprocessor directives Declaration section int main() { executable statements return 0; } B.Preprocessor directives int main() Declaration section { executable statements return 0; } C.Declaration section Preprocessor directives int main() { executable statements return 0; } D.Preprocessor directives int main() { Declaration section executable statements return 0; } E. none of the above

D

Declare an array 100 elements of that struct called movies

DvdRec movies[100];

(T/F) Given the following declarations: int firstArray[20]; int secondArray[20] = {1,2,3,4,5}; firstArray = secondArray; will assign the values {1, 2, 3, 4, 5} to the corresponding elements in firstArray

F

(T/F) A C++ identifier may start with a digit.

F

(T/F) A binary search can always be used in place of a sequential search

F

(T/F) A compiler translates code written in machine language into C++.

F

(T/F) A variable is the name of a location in memory that contains an unchangeable value.

F

(T/F) An individual component of an array cannot be passed as an argument to a function. The entire array must be sent

F

(T/F) Arrays are always passed by reference to functions

F

(T/F) Assuming a pointer variable ptr declared within a function, once the statement delete ptr; is executed, the pointer ptr can no longer be re-used within this function.

F

(T/F) C++ does not allow any aggregate operations on structs.

F

(T/F) During program execution, only one pointer can point to any single dynamic variable.

F

(T/F) Elements of a two-dimensional array are accessed by the array name followed by the column address followed by the row address

F

(T/F) Enum creates an alias for a datatype

F

(T/F) Enumerated types simplify coding and makes code self-documenting

F

What is a stack?

Items are added to and removed from the front

If an ampersand (&) is not attached to the data type of a function parameter, the corresponding argument can be:

a constant, a variable name and an expression

What is a member?

a field within the struct

What is a virtual function

a function that can be used before it is defined

How would you output the title of the 10th element in the array?

cout << movies[9].title;

If a function is supposed to search an integer array for one instance of a search item which of the following is the most appropriate function heading?

int searchIntAr(const int intAr[ ], const int AR_SIZE, int searchItem)

What is information hiding?

keeping the data private and how methods are implemented hidden so that changes won't effect the code using the objects

What is LIFO?

last in first out

What is polymorphism?

the ability to associate many meanings to one function name by means of using virtual functions or late binding (dynamic binding)

What is inher

when a new class (the derived class) is created from another class (base class)

What type of loop should you use to search a linked list?

while loop


Related study sets

MGT CLEP TEST 3013, Management Clep Test Focus Questions

View Set

(Complete) Ch. 17: Pricing objectives and Policies

View Set

FCE #1 Make adjectives by using the suffixes : -OUS , -AL , -Y , -IVE , -ABLE , -FUL , -LESS

View Set

Abnormal Psychology Chapter 10: Eating Disorders

View Set

Ch. 20 - Diabetes Mellitus & Nutrition

View Set

Organizational Behavior Chapters 6-8

View Set

Cognitive Development (Early and Middle Childhood): Psych 241: Exam 3

View Set