comp sci midterm review

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

How many elements does the following array have?int values[1000];

1000

How many objects of type Car are created? Car mustang; Car prius; int miles; Truck tundra;

2

what is the output after the code executes? int num = 5; int denom = 25; int temp = 0; ...

25/5 = 5

An array can easily be stepped through by using a

A FOR LOOP

Which of the following is true if a programmer has to create a class Clinic with the following data members and functions?

Data members should be private items and function declarations should be public items

(T/F)Although two-dimensional arrays are a novel idea, there is no known way to pass one to a function.

False

The ampersand (&) is used to dereference a pointer variable in C++.

False

The weak_ptr can share ownership of a piece of dynamically allocated memory.

False

Given the following input, what is the output? 4 1 1990

Month 5 Day 1 Year 1990

What is the output? #include <iostream> #include <vector> using namespace std; int main() { unsigned int i; vector<int> Xvector; Xvector.push_back(1); Xvector.push_back(2); Xvector.clear(); for (i = 0; i < Xvector.size(); ++i) cout << ' ' << Xvector.at(i); return 0; }

No output

What is the output? #include <iostream> using namespace std; class Line { public: Line () { cout << "No such line"; } }; int main() { Line L1, *L2; return 0;

No such line

A programmer is overloading the equality operator (==) and has created a function named operator==. What are the return type and arguments of this function?

Return type: bool, Arguments: 2 const class type references

Which of the following is true for overloading a class constructor?

The parameter types of the constructors should be different.

Which of the following is TRUE about this statement?sum += *array++;

This statement assigns the dereferenced pointer's value, then increments the pointer's address.

(T/F)In C++11 you cannot use a range-based for loop to modify the contents of an array unless you declare the range variable as a reference variable.

True

(t/f)A pointer can be used as a function argument, giving the function access to the original argument.

True

Given the following input, what is output? English 50 50.0 Math 120 75.5

You have: English book. You have: Math book.

To assign the contents of one array to another, you must use

a loop to assign the elements of one array to the other array

If you leave out the size declarator in an array definition

all array elements default to zero values

When writing functions that accept multi-dimensional arrays as arguments, ________ must be explicitly stated in the parameter list.

all but the first dimension

Unlike regular variables ___ can hold multiple values.

arrays

A(n) _____ can be used to implement an abstract data type (ADT).

class

An array's size declarator must be a ________ with a value greater than ________.

constant integer expression, zero

Use the delete operator only on pointers that were

created with the new operator

Which of the following statements deletes memory that has been dynamically allocated for an array?

delete [] array;

This vector function returns true if the vector has no elements.

empty

(T/F)In C++11 the range-based for loop is best used in situations where you need the element subscript for some purpose.

false

(t/f)Before you can perform a bubble sort, the data must be stored in descending order.

false

(t/f)The following statement is a valid C++ definition:double money[25.00];

false

With pointer variables you can ________ manipulate data stored in other variables.

indirectly

A(n) ________ can be used to specify the starting values of an array.

initialization list

Select all that apply. Of the following, which statements have the same meaning?

int *ptr = nullptr; int* ptr = nullptr;

Assume you have two integer variables, num1 and num2. Which of the following is the correct way to swap the values in these two variables?

int temp = num2; num2 = num1; num1 = temp;

What does the following statement do? vector<int>v(10);

it creates a vector object with a starting size of 10.

The following is the pseudocode for which type of algorithm? set found to false...

linear search

A binary search begins with the ________ element of an array.

middle

Not all arithmetic operations can be performed on pointers. For example, you cannot ________ or ________ pointers.

multiply, divide

The ________ is automatically appended to a character array when it is initialized with a string constant.

null terminator

In C++11, the ________ keyword was introduced to represent address 0.

nullptr

A two-dimensional array can have elements of ________ data type(s).

one

The process of redefining the functionality of a built-in operator, such as +, -, and *, to operate on programmer-defined objects is called operator _____.

overloading

This vector function removes an item from a vector.

pop_back

In the following statement, what does int mean?int *ptr = nullptr;

ptr is a pointer variable and will store the address of an integer variable.

After the code shown executes, which of the following statements is TRUE?int numbers[] = {0, 1, 2, 3, 4};int *ptr = numbers;ptr++;

ptr will hold the address of numbers[1]

This vector function is used to insert an item into a vector.

push_back

In the following code, what is the correct return statement for an overloaded + operator?

return myGame;

A two-dimensional array can be viewed as

rows and columns

Given the following declaration, where is the value 77 stored in the scores array?int scores[] = {83, 62, 77, 97, 86}

scores[2]

The following is the pseudocode for which type of algorithm? For start = each array subscript from the first to the next to the last ......

selection sort

The range-based for loop in C++11 is designed to work with a built-in variable known as

size, expressed as an integer

To pass an array as an argument to a function, pass the ________ of the array.

size, expressed as an integer

Algorithms used to arrange random data in some order are ________ algorithms.

sorting

A function may return a pointer but the programmer must ensure that the pointer

still points to a valid object after the function ends

Which of the following is an accessor declaration?

string GetName() const;

Identify the correct struct definition

struct Sample { int a; int b; }

To access an array element, use the array name and the element's ________.

subscript

When you work with a dereferenced pointer, you are actually working with

the actual value of the variable whose address is stored in the pointer variable

if you are using an older computer that does NOT support the C++11 standard, you should initialize pointers with

the integer 0 or the value NULL

(T/F)each individual element of an array can be accessed by the array name and the element subscript

true

(t/f)A selection sort and a binary search can be applied to STL vectors as well as arrays.

true

(t/f)On average, an item is just as likely to be found near the beginning of an array as near the end.

true

Which of the following defines a unique_ptr named uniq that points to a dynamically allocated int?

unique_ptr uniq( new int );

Dynamic memory allocation occurs

when a new variable is created at runtime

Which of the following statements describes an abstraction?

Hiding the implementation and showing the important features

(t/f)The number of comparisons made by a binary search is expressed in powers of two.

true

What will the following code display? int numbers[4] = {99,87}; cout << numbers[3] << endl;

0

What is the last legal subscript that can be used with the following array?int values[5];

4

Which of the following statements is NOT valid C++ code?

All of these are invalid

What does the following code do? const int SIZE =5; double x[SIZE]; for(int i = 2; i < SIZE; i++) { x[i] =0.0; }

An error will occur when the code runs.

Convert the following constructor to a constructor initialization list. House::House() { houseNum = 1; price = 1.00; }

House:: House() : houseNum(1), price(1.00) { }

Identify the type of function definition used in the code. class AgeCalculator { public: int CalcAge(int age) { ageMonths = age * 12; return ageMonths; } private: int ageMonths; }; int main() { AgeCalculator newAge; newAge.CalcAge(5); return 0; }

Inline function definition

What is the output? #include <iostream> using namespace std; class Shape { public: Shape(int l = 5, int b = 5); void Print(); Shape operator-(Shape shape2); private: int length; int width; }; Shape Shape::operator-(Shape shape2) { Shape newShape; newShape.length = length - shape2.length; newShape.width = width - shape2.width; return newShape; } Shape::Shape(int l, int b) { length = l; width = b; } void Shape::Print() { cout << "Length = " << length << " and " << "Width = " << width << endl; } int main() { Shape s1(20, 20); Shape s2; Shape s3; s3 = s1 - s2; s3.Print(); return 0;

Length = 15 and Width = 15

What has access to a class's private data members?

Member functions but not class users

Given a struct Point with data members x and y, identify the correct function definition for a function Distance() that takes in two struct type parameters point1 and point2, and returns the distance between them. double Distance(Point point1, Point point2){...};

Point point1, Point point2

An array name is a pointer constant because the address stored in it cannot be changed at runtime.

True

It is legal to subtract a pointer variable from another pointer variable.

True


Set pelajaran terkait

Module 62: What Is Aggregate Demand? What Is Aggregate Supply?

View Set

NRN171 Quiz 2 Clinical Decision making and judgement

View Set

Psych Test study guide 11 - 31 - 17

View Set