CECS 325 Final

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

If i is of the map iterator and p is of the type stored in the map values, then which of the following is a valid expression? (*i) = (*p).first *i = p (*i).second = p i = *p

(*i).second = p

Consider the following code snippet: vector<double> somedata; somedata.push_back(10); What is the size of the vector somedata after the given code snippet is executed? 2 10 1 0

1

What is the output of the following code, assuming proper libraries have been included? char trinity[20] = "C++ motorcycle"; cout << strlen(trinity); 3 Unpredictable runtime error 14 20

14

What is the output of the following code snippet? int num = 0; int* ptr = &num; num = 5; *ptr = *ptr + 10; cout << num << " " << *ptr << endl; 5 10 10 10 15 15 10 5

15 15

Consider the following code snippet: int numarray[ ] = { 1, 2, 3, 4, 5 }; cout << numarray[1]; cout << numarray[4]; What is the output of the code snippet? 15 25 04 14

25

Consider the code snippet below. int arr[5] = { 1, 2, 3, 4, 5 }; Which of the following is the value of *(arr + 3)? 4 3 1 2

4

The function pthread_create( ) has how many parameters? 3 4 1 2

4 thread Is the location where the ID of the newly created thread should be stored, or NULL if the thread ID is not required. attr Is the thread attribute object specifying the attributes for the thread that is being created. If attr is NULL, the thread is created with default attributes. start Is the main function for the thread; the thread begins executing user code at this address. arg Is the argument passed to start.

Consider this code segment: int x = 10; int y = 20; int z = mystery(x, y); cout << z << "/" << x + y; Also consider this function: int mystery(int a, int &b) { a += 5; b += 5; return a + b; } What prints to the screen? 40/35 35/40 40/30 30/40

40/35

What will print to the screen based on the following C++ code: char name[10] = "steve"; cout << strlen(name); steve 6 10 5

5

Consider the following C++ code segment: char word[10] = "matrix"; cout << strlen(word); What will be printed to the screen? 6 10 The correct answer is not listed matrix

6

What is the output of the following code, assuming proper libraries have been included? char state[] = "Idaho"; cout << sizeof(state); 5 6 No output, compiler error Idaho

6

What is the output of the following code snippet? int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int* ptr = arr; ptr = ptr + 6; cout << *ptr << endl; 5 There is no output due to a compilation error. 6 7

7

What is the output of the following code snippet? int num = 0; int* ptr = &num; *ptr = 90; num = 80; cout << *ptr << endl; 80 the address of num 0 The correct answer is not listed 90

80

Consider the following code snippet: int arrmarks[5]; for (int cnt = 0; cnt < 5; cnt++) { cout << "Enter the marks: "; cin >> arrmarks[cnt]; } Assume that a user enters 35, 56, 78, 90, and 45 as marks. What is stored in the element with the index number 3? 45 56 90 The correct answer is not listed 78

90

Suppose I have a file numbers.dat with the number 1 through 1000 sorted, one number per line. What will be printed on the screen if I type this command sequence: % more numbers.dat | tail -100 | head -20 | tail -1 920 none of these answers is correct 921 901

920

In which c++ library is strlen( ) found? <string> The correct answer is not listed. <cstring> <strlen>

<cstring>

What library must be included by your code to use functions that copy and concatenate character arrays? <string> <cstring.h> <cstring> <c-string>

<cstring>

What is the error in the following code snippet? const int WORDCOUNT = 100; string words[WORDCOUNT]; for (int i = 0; i <= WORDCOUNT; i++) { cout << words[i] << endl; } Array index out of bounds Cannot define an array of strings Infinite loop Skips elements in the array

Array index out of bounds

What is another name for "null terminated character array" container C-string word The correct answer is not listed

C-string

(15.20) What will be the output of the following complete program? #include <iostream> #include <string> using namespace std; int main() { set<string> cities; cities.insert("Los Angeles"); cities.insert("Anaheim"); cities.insert("Berkeley"); cities.insert("Anaheim"); for (auto it = cities.begin(); it != cities.end(); it++) { cout << " " << *it; } return 0; } Anaheim Anaheim Berkeley Los Angeles Anaheim Berkeley Los Angeles Los Angeles Anaheim Berkeley Compiler error, no output as set<> will be undefined.

Compiler error, no output as set<> will be undefined.

In C++, which statement about constructors is true? Constructors have the same name as the class. Constructors have no parameters. Constructors are declared with the keyword constructor. Constructors are declared with the keyword const.

Constructors have the same name as the class.

According to NUMA architecture, all memory in a computer can be accessed and the retrieval times are constant.

False

In the C++ language when building a class, header files (.h) must be separate from implementation files (.cpp)

False

This program will compile and run just fine: #include <iostream> int main() { cout << "Hello World\n"; }

False

When building a class in C++, it is good practice to make the data members public so that other classes can quickly access them. This is what makes C++ a fast language.

False

Which of the following is true about functions? Functions can have multiple parameters and can return multiple return values. Function can have multiple parameters and can return one return value. Functions can have only one parameter and can return only one return value. Functions can have one parameter and can return multiple return values.

Function can have multiple parameters and can return one return value.

What is the output of the following code snippet? char name[] = "Harry Houdini"; name[2] = 'v'; cout << name << endl; Havry Houdini Harry Houdini Harvy Houdini Harry Houdiniv

Havry Houdini

What is the output of the following code snippet if the input is "I hate summers I hate heat"? map<string, int> x; string str[] = {"I", "hate", "summers", "I", "hate", "heat"}; for (int i = 0; i < 6; i++) { x[str[i]] = x[str[i]] + 1; } map<string, int>::iterator iter; for (iter = x.begin(); iter != x.end(); ++iter) { cout << iter->first << " - " << iter->second << endl; } hate - 2 I - 2 hate - 1 heat - 1 I - 2 hate - 2 summers - 1 heat - 1 heat - 1 I - 2 hate - 2 summers - 1 I - 2 hate - 2 heat - 1 summers - 1

I - 2 hate - 2 heat - 1 summers - 1

What is the output of the following code snippet if the input is "I love maps I love programming"? map<string, int> x; string str; while (cin >> str) { x[str] = x[str] + 1; } map<string, int>::iterator iter; for (iter = x.begin(); iter != x.end(); iter++) { cout << iter->first << " - " << iter->second << endl; } I - 2 love - 2 maps - 1 programming - 1 I - 2 love - 2 programming - 1 maps - 1 love - 2 I - 2 maps - 1 programming - 1 programming - 1 I - 2 love - 2 maps - 1

I - 2 love - 2 maps - 1 programming - 1

What statement is true about he C++ language? it is interpreted It is compiled None of these answers are correct. It was invented in 1968

It is compiled

What is the output of the following code snippet? int* ptr; *ptr = *ptr + 5; cout << *ptr << endl; There is no output due to compilation errors. The address stored in ptr 5 It results in an unpredictable error when the code is run because it uses an uninitialized pointer

It results in an unpredictable error when the code is run because it uses an uninitialized pointer

What is the output of the following code snippet? double balance = 10000; const double* p; *p = *p - 1000; cout << *p; 9000 10000 It will yield a compiler error. The memory address of the variable balance will be printed.

It will yield a compiler error.

What kind of code do computers understand? Assembly Code Machine Code Source Code Bro Code

Machine Code

What is the output of the following code, assuming proper libraries have been included? char s[20] = "mystring1"; cout << strlen(s); 7 8 20 None of these

None of these

What happens when you define the data members in a class to be private? Only private member functions of the same class can access these data members. The member functions of every class can access the data members. Only the member functions of the same class can access the data members. Only private member functions of other classes can access the data members.

Only the member functions of the same class can access the data members.

Which of the following statements is true about pointers? Pointers contain values as well as addresses of variables. Pointers do not have any address location of their own. Pointers occupy permanent storage locations inside the hard disk. Pointers contain address locations of variables.

Pointers contain address locations of variables.

What are the names (in order) of the parts of this function definition? int my_fun (double a) Return type, function name, parameter variable type, parameter variable name Function name, function type, parameter variable name, parameter variable type Function name, function type, parameter variable type, parameter variable name Return type, function name, parameter variable name, parameter variable type

Return type, function name, parameter variable type, parameter variable name

What is the advantage of using sets over linked lists? Sets have data items arranged in FIFO order, so data items can easily be traversed. Sets can dynamically grow or shrink in size. Sets can have repeated data items, whereas linked lists cannot have repeated data items. Sets allow retrieval of data items faster than linked lists.

Sets allow retrieval of data items faster than linked lists.

What is the output of the following code snippet? class Cheetah { public: void set_speed(double new_speed); private: double speed; }; void Cheetah::set_speed(double new_speed) { speed = new_speed; } int main() { Cheetah ch1; ch1.set_speed(144); cout << "Cheetah speed: " << ch1.speed; return 0; } The code snippet does not compile. Cheetah speed: 0 Cheetah speed: 144 Cheetah speed:

The code snippet does not compile.

Consider this code segment: int nums[10]; nums[10] = 999; Which of the following statements is true? The code will compile but there is something wrong with this code There is nothing wrong with the code C++ is a dangerous motorcycle and you could be mortally wounded if you try to use it!!! The code will not compile.

The code will compile but there is something wrong with this code

Assume the following C++ code segment: struct student { string name; int age; char grade; }; student s1, *sptr; sptr = &s1; s1.name = "MasterGold"; What code would you use to set Master Gold's grade to A? The correct answer is not listed sptr.grade = 'A' s1->grade = 'A'; MasterGold->grade = 'A';

The correct answer is not listed

Consider the following code snippet: int somearray[6]; for (int i = 1; i < 6; i++) { somearray[i] = i + 1; } The correct answer is not listed The for loop initializes all the elements except the first element. The for loop initializes all the elements of the array. The for loop initializes all the elements except the first and last elements. The for loop initializes all the elements except the last element.

The for loop initializes all the elements except the first element.

What is the error in the following function definition? int doubler(int old_value) { double new_value = old_value * 2;} No error. The function does not return a value. The function returns a value of type double. The function attempts to modify its input parameter.

The function does not return a value.

What is the error in the following function definition? int tripler(int num_para) { double result = num_para * 3; } The function does not return a value. The function returns a value of type double. None of the listed items. The function does not modify its input parameter.

The function does not return a value.

What is the error in the following function definition? int find_max(int first, second) { int max = 0; if (first > second) { max = first; } else { max = second; } return max; } The function does not specify a type for the second parameter. The function returns the minimum instead of the maximum of the two parameters. The function does not return a value. The function returns 0 if the first and second parameters are equal.

The function does not specify a type for the second parameter.

What is the problem with the code snippet below? string val() { string result = "candy"; return; } int main(){ cout << val() << endl; return 0; } The function val does not have any parameter variables. The correct answer is not listed The use of val in the cout statement of main is illegal. The string data type cannot be returned from a function. The function val does not have a return value.

The function val does not have a return value.

What is displayed when you execute the following code snippet? int ch = 100; cout <<&ch << endl; The value at the memory location of 100 The memory location of ch The value of ch None of the listed items

The memory location of ch

What does Amdahl's law describe? The computing power will double every 18 months Programs can run faster if you use parallel processing Moore was an optimist The sequential work will limit the speedup due to parallelism!

The sequential work will limit the speedup due to parallelism!

What is the syntax error in the following function definition? string parameter(double r) { double result; result = 2 * 3.14 * r; return result; } The variable result is set but never used. The function does not return the value result. The function does not specify result return type. The value that is returned does not match the specified return type.

The value that is returned does not match the specified return type.

What is the linux command to show the contents of a file? show more There are 2 correct answers listed cat

There are 2 correct answers listed

The function pthread_create( ) allows a program to have multiple threads running concurrently. True False

True

A programmer working on an auto rental application realizes that she needs to create many Car objects in this application. What does she need to do in order to define a Car class? Write a Car class that defines the data members and functions that Car objects will have. Define both global data and functions to represent car data and behavior. Define a set of global variables to store data for Car objects. Write a set of functions that accepts a car as a parameter.

Write a Car class that defines the data members and functions that Car objects will have.

Consider the following C++ code segment: char name[15] = "PonyExpress"; char * cptr = name; name = "cowboy"; cout << name; Which of the following is true: You can't assign "cowboy" to name Cowboys can't be in the Pony Express You can't assign an array to a pointer There is overflow on the first line

You can't assign "cowboy" to name

What will be the value inside the variables a and b after the given set of assignments? int a = 20; int b = 10; a = (a + b) / 2; b = a++; a = 15, b = 16 a = 16, b = 16 a = 15, b = 15 a = 16, b = 15

a = 16, b = 15

If an element is already in a set, attempts to add it again are ignored insert another copy crash the program create a warning message

are ignored

Which location of the array arr does ptr point to right after you assign an array to a pointer variable, as shown in the following code snippet? int arr[10]; int* ptr = arr; arr[10] You cannot assign an array to a pointer. arr[0] arr[1]

arr[0]

Which of the following is true about the chars variable? char chars[] = "Hello World"; chars is an array of size 11, and the last value in the array is null. chars is an array of size 12, and the last value in the array is "d". chars is an array of size 11, and the last value in the array is "d". chars is an array of size 12, and the last value in the array is null.

chars is an array of size 12, and the last value in the array is null.

The following C++ function receives an array of integers and a particular index in that array. Index is within the bounds of the passed array. The cout statement will correctly print the desired element. Which of the answers will print the same correct output? int showElement(int A[ ], int index) { cout << A[index]; } cout << *(A + index); cout << &A + index; cout << *A + index; cout << &A[index];

cout << *(A + index);

Consider the following code segment in C++:: int A[ ] = {0, 1, 2, 3, 4, 5}; int *ptr = A; How would I print 5 to the screen? cout << ptr[5]; cout << ptr + 5; cout << *ptr[5]; cout << ptr * 5;

cout << ptr[5];

Consider a function named avg, which accepts four numbers as integers and returns their average as a double. Which of the following is the correct statement to call the function avg? avg(2, 3.14, 3, 5); double average = avg(2, 3, 4, 5); double average = avg("2", "3", "4", "5"); avg();

double average = avg(2, 3, 4, 5);

Which of the following is the correct first line of a function definition named calc_average that accepts three int parameters and returns a double? double calc_average() calc_average(int a, int b, int c) double calc_average(int a, int b, int c) int calc_average(double a, double b, double c)

double calc_average(int a, int b, int c)

In the following class definition, which of the data members or member functions are hidden from the class users? class Car { public: Car(); void start(); void stop(); private: double speed; void set_speed(double new_speed); }; void start(), void stop(), double speed, and void set_speed(double new_speed) void start() and void stop() Car(), void start(), and void stop() double speed and void set_speed(double new_speed)

double speed and void set_speed(double new_speed)

What is the output of the following code snippet? int main() { int i = 4; char* name = "Steven Black"; cout << name[i] << endl; return 0; } Black n The program does not compile due to a syntax error. e

e

What linux command is used to print "Hello World" on the terminal echo Hello World print Hello World type Hello World push Hello World

echo Hello World

When a C++ program runs, and dynamic memory is needed, where does the allocated dynamic memory live in memory? register heap ram stack

heap

If i is of the map iterator and p is of the type stored in the map values, then which of the following is a valid expression? i = *p i->first = p i->second = p *i = p

i->second = p

Which of the following is a legally correct way of declaring a variable that is a pointer to an integer? pointer<int> ptr int& ptr int ptr* int* ptr The correct answer is not listed

int *ptr;

Which one of the following statements is an invalid initialization of an array named myarray? int myarray[5] = { 0, 1, 2, 3 }; int myarray[5] = { 0, 1, 2, 3, 4, 5 }; int myarray[ ] = { 0, 1, 2, 3, 4 }; int myarray[4] = { 0, 1, 2, 3 };

int myarray[5] = { 0, 1, 2, 3, 4, 5 };

How do you create an array of 20 integers called nums in C++? integer nums[20]; int nums = new int[20]; int nums[20]; nums[20] <int>

int nums[20];

Which one of the following statements is an invalid initialization of an array named somearray? int somearray[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int somearray[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; int somearray[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; int somearray[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; The correct answer is not listed

int somearray[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

Consider a function named calc, which accepts two numbers as integers and returns their sum as an integer. Which of the following is the correct statement to call the function calc? int sum = calc(2, 3); calc(2, 3.14); calc(); int sum = calc("2", "3");

int sum = calc(2, 3);

If itr is a map iterator and q is of the type stored in the map values, then which of the following is a valid expression? itr->second = q (*itr) = q->first itr = *q itr = q

itr->second = q

Using linux commands, how would I find out more about the wc command? man wc list wc help wc more wc

man wc

What is the output of the following code snippet? int main() { int i = 5; const char* name = "Philip Roger"; cout << name[i] << endl; return 0; } p Roger The program does not compile due to a syntax error. R

p

Consider the following valid C++ function: void func(char * ptr) { cout << ptr; } What is the passing mode used in the function to pass the parameter ptr? pass by value pass by touchdown pass by linkage pass by reference

pass by value

Consider the code snippet below. int ch = 100; int* ptr = &ch; Which of the following observations are true based on the code snippet? ptr stores the address of ch &ptr gives the address of ch The correct answer is not listed ptr stores the value of ch &ptr gives the value of ch

ptr stores the address of ch

Given the following code snippet, what is true about the statement ptr_num++? int num[5] = { 1, 2, 3, 4, 5 }; int* ptr_num = num; ptr_num++; ptr_num++ results in a compilation error. ptr_num now points to num[0]; ptr_num++ results in a run-time error. ptr_num now points to num[1];

ptr_num now points to num[1];

Consider the code snippet below. int num = 500; int* ptr_num = &num; Which of the following observations are true based on the code snippet? &ptr_num gives the value of num &ptr_num gives the address of num ptr_num stores the address of num ptr_num stores the value of num

ptr_num stores the address of num

Assume the following C++ code segment: struct student { string name; int age; char grade; }; student s1, *sptr; sptr = &s1; s1.name = "MasterGold"; What code would you use to set Master Gold's age to 49? The correct answer is not listed. student.age = 49; sptr->age = 49; sptr.age = 49;

sptr->age = 49;

The fibonacci function is a recursive function. Each time the function gets called in a recursive loop, what type of memory is used to store the contents and state of the program? register heap ram stack

stack

Suppose that you declare an array int arr_num[10]. Assuming the function declaration statement given below, what would you use to pass the array to the given function? int sum_arr(int arr_num[]) sum_arr(arr_num[0]) sum_arr(*arr_num) sum_arr(&arr_num) sum_arr(arr_num)

sum_arr(arr_num)

Consider the following segment of code in C++: int nums[10] = {1,2,3,4,5,6,7,8,9,10}; printArray(nums); Also consider the this function: void printArray(int n[ ]) { for(int i=0, i<n.size; i++) cout << n[i]; } How many numbers will the printArray( ) function actually print out? 1 the correct answer is not listed 10 all the numbers in the array

the correct answer is not listed

Consider the following C++ code: int a = 10; int *ptr = &a; cout << ptr; What is printed out? the memory address of a the number 10 the contents of a the memory address of ptr

the memory address of a

Which one of the following is a correct declaration for a function named passvect with the vector parameter mynum of size 10, so that the function modifies the contents of the actual parameter mynum? void passvect(vector<int>& mynum) void passvect(vector<int> mynum) void passvect(vector<int>& mynum(10)) void passvect(mynum)

void passvect(vector<int>& mynum)

Suppose I have a vector that I want to pass to a sort( ) function. vector<int> v; // the potion of the code that fills the // vector is not shown sort( v ); // I expect the vector to be sorted here What does the signature of the sort function look like to make sure the vector will be sorted when it returns from the sort function? void sort (vector<int> * vec) the correct answer is not shown void sort ( vector<int> & vec) void sort (vector<int> vec)

void sort ( vector<int> & vec)

Suppose I have a vector that I want to pass to a sort( ) function. vector<int> v; // the potion of the code that fills the // vector is not shown sort( v ); // I expect the vector to be sorted here What does the signature of the sort function look like to make sure the vector will be sorted when it returns from the sort function? void sort (vector<int> * vec) the correct answer is not shown void sort (vector<int> vec) void sort ( vector<int> & vec)

void sort (vector<int> vec)

Which is the appropriate time to initialize a variable? before the main function at the end of the program when you use it when you define it

when you define it


Set pelajaran terkait

Patho Unit 3 PrepU with Explanation Chapter 26

View Set

Chapter 21: Teacher and Counselor

View Set