CS1B Midterm 1

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

A binary search can always be used in place of a sequential search

False

A sequential search can be used on any array but works much faster if the array is sorted

False

Elements of a two-dimensional array are accessed by the array name followed by the column address followed by the row address

False

Enum creates an alias for a datatype

False

Functions should be defined above int main()

False

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

False

Given the declaration int beta[20]; the statement cout << beta[3]; outputs the third element in the array

False

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

False

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

False

If name1 and name2 are of type C-STRING and they both contain the value "Sally" the expression name1 == name2 would evaluate to true

False

In C++ the entire array or an individual element in array cannot be returned through a return statement

False

In C++, corresponding arguments from a calling function and parameters from a called function must have the same name

False

In a C++ expression, all addition and subtraction are performed before multiplication or division

False

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

False

In a while loop, we are NOT required to initialize the LCV prior to entering in the loop

False

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

False

Once the program compiles it is guaranteed to execute correctly

False

Structs can only be passed by reference

False

Structs cannot be returned through a return statement, but an individual member can

False

The C++ directive #include <myheader.h> would include the user-defined header file myheader.h

False

The expression num3 *= num1 + num2 * 10 could be written as num3 = num3*num1 + num2 *10

False

The following statements will declare a 10 element array of integers: int AR_SIZE = 10; int intAR[AR_SIZE];

False

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

False

The order in which directives and declarations appear in a header file does not matter

False

The statement return 3*alpha + 5; is valid in a void function

False

The value of the C++ expression 7 - 3 * 5 is 20

False

The value of the expression 15 > x > 5 in C++ will always be false

False

Using globally declared constants is as dangerous as using globally declared variables

False

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

False

We should always pass parameters by reference because it takes less overhead

False

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

False

When the result of a floating point expression is assigned to an integer variable, the fractional part is rounded

False

White box testing tests the over functionality of the code

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);

The following is a valid use for a typedef: typedef float FloatArrayType[100];

True

The name of an array is the address in memory of the first element

True

The scope of a local identifier extends from the point of declaration to the end of the block in which it was declared

True

The size of an array is established at compile time rather than at run time

True

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

True

This is a valid operation for strings. str3 = str1 + str2;

True

Two different enumerated types in the same program can have the same values

True

Typedef creates an alias for a datatype

True

Used properly, the typedef declarations add readability to a program

True

User-defined header files must have the .h extension

True

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

True

When passing parameters by reference, the address of the calling function's argument is sent to the function

True

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

True

Without the struct datatype, storing information of different types as a set of data would require the use of parallel arrays

True

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

Given the following code segment: struct Brandinfo { char brand; string mondel; }; Brandinfo myDisk[20]; which of the following assignment statements is valid?

myDisk[3].brand = 'X';

Consider the following function definition void Demo(int& intVal, float floatVal) { intVal = intVal * 2; floatVal = float(intVal) + 3; } suppose the calling function has variables myInt and myFloat whose values are 20 and 4.8 respectively. What are the values of myInt and myFloat after return from the following call? Demo(myInt, myFloat);

myInt = 40 and myFloat = 43.5

We can avoid side effects by... (Choose all that apply) -passing parameters by reference -passing parameters by constant reference -passing parameters by value -none of the above

passing parameters by constant reference passing parameters be value

Which category of datatypes includes enums?

simple

Which of the following is not a simple datatype?

struct

Which category of datatypes includes arrays?

structured

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;

Which of the following expressions is logically equivalent to !(a == b || b < d)

- (a != b) || (b >= d)

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; i >= 1; --i) { larger = intArray[o]; 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; }

- Selection Sort

When should we use a void function over a value returning function? - When we are returning one value - When we are not returning any values - When we are returning more than one value - None of the above

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

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

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

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

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 + 15; }

30

Given the declaration char alpha[25][3]; How many char elements does alpha have?

75

Given: int val, val1; //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:

Before line 5 and before line 6

The following code segment is an implementation of: int bottom; int top; int middle; bool found; int index; bottom = 0; top = size - 1; found = false; while (!found && bottom <= top) { middle = (bottom + top) / 2; if (intAr[middle] == key) { found = true; index = middle; } else if (intAr[middle] < key) { bottom = middle + 1; } else { top - middle - 1; } }

Binary Search

The following line of code is an example of: ifstream inFile;

How to declare the file stream variable inFile

In general, which of the following sorts is the most efficient?

Insertion sort

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

One way, into the function

A c-string is an array of characters

True

An individual component of an array cannot be passed as an argument to a function. The entire array must be sent

True

Array subscripts always begin at 0

True

Arrays are always passed by reference to functions

True

Both value and reference parameters can be declared in the same function heading

True

C++ allows some aggregate operations on structs, but never on arrays

True

Char is an integral datatype

True

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

True

Elements in an array all must be the same datatype

True

Enumerated types simplify coding and makes code self-documenting

True

For loops are pre-test loops

True

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

True

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

True

If a function contains a statement that changes a value parameter, only the copy of the argument is changed, not the original

True

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

True

If name1 and name2 are of type STRING and they both contain the value "Sally", the expression name1 == name2 would evaluate to true

True

If there are several items in a parameter list, the compiler matches the parameters and the arguments by their relative positions in the list

True

In C++, the exprsesion 2.5 + 8.0 5 6 would produce a compile time error

True

In C++, we use structs to define records

True

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

True

It is considered bad practice to have function definitions in a Header file

True

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

True

String size is dynamically allocated

True

Test stubs test whether the calling function is passed the proper value for the parameters

True

The declaration of ifstream inFile; requires the fstream directive to be included in the program

True

The elements in an array are accessed by an index and the members of a struct are accessed by using the dot operator

True

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

True

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

a compile time error

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

a constant, a variable name and an expression

The declaration int anArray[15] = {1,3}

declares anArray to be a 15 element array of integer values and places the value 1 in anArray[0], 3 in anArray[1], and 0 in all other locations

The following line of code is an example of: open("InputFile.txt");

how to associate the file stream variable inFile with the filename InputFile.txt

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)


संबंधित स्टडी सेट्स

Biblical foundations of social justice

View Set