PSY 361 FINAL

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

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? 10 all the numbers in the array 1 the correct answer is not listed

the correct answer is not listed

What is the name of the linux root directory? root ../ ./ /

/

Consider the following C++ code: char ch = 'B' + 5; What is the bit sequence for the variable ch? 01000111 01010101 01100110 You will get a compile error by adding a character and a number.

01000111

Consider the following program. What will is the output? #include <iostream> #include <vector> using namespace std; int main() { vector<int> v; for (auto i=0; i<10; i++) v.push_back(i * 5); vector<int>::iterator it = v.begin(); cout << *(it+3); return 0; } it will not compile 15 3 5

15

Suppose I have a file numbers.dat with the numbers 1 through 100 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 none of these answers is correct 21 20 1

20

What is the output of the following program: #include <iostream> using namespace std; void swap(int &x, int y) { int temp = x; x = y; y = temp; } int main() { int a = 10, b = 20; swap (a, b); cout << a << ',' << b<< endl; return 0; } 10,20 10,10 20,10 20,20

20,20

The following program will compile and run without errors. What is the output of the following program? #include <iostream> #include <thread> int mystery(int a, int b, int c, int *d) { *d = a + c; return *d / 2; } int main() { int sum = 0; int *ptr = &sum; std::thread t1(mystery,1,2,3,ptr); t1.join(); std::cout<< *ptr; return 0; } 6 0 4 3

4

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

4

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/30 40/35 35/40 30/40

40/35

Consider the following program. What is printed? #include <iostream> using namespace std; int x = 10; void print(int y) { cout << y << ":" << x << endl; int x = 20; } int main() { int x = 5; print(x); return 0; } 5:10 10:20 10:5 There is a compiler error because there are too many x variables.

5:10

What is printed to the screen when this program runs? #include <iostream> using namespace std; int x = 10; void print(int y) { cout << y << ":" << x << endl; } int main() { int x; x = 5; print(x); return 0; } 10:5 10:10 5:10 5:5

5:10

Assume the following C++ program segment. What is printed to the screen? char ch = 65; int x = ch; cout << x << ':' << ch << endl; A:65 A:A 65:A 65:65

65:A

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

<cstring>

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

False

Which of the following member functions is valid syntax for overloading the operator%( ) in C++? Example: BigInt X, Y(20), Z(3); X = Y % Z; // <--- using the % operator void BigInt::operator % (BigInt a) BigInt BigInt::operator % (BigInt a) BigInt BigInt::operator % (BigInt a, BigInt b) void BigInt::operator % (BigInt a, BigInt b)

BigInt BigInt::operator % (BigInt a)

Consider the following working program. What function is being called based on the yellow highlight? #include <iostream> #include "BigInt.h" using namespace std; int main() { BigInt X(10); BigInt Y = X++; // what function is called? cout << X; } BigInt operator++(int); BigInt BigInt::operator++(int); BigInt operator++( ); BigInt BigInt::operator++( );

BigInt BigInt::operator++(int);

Which of the following non-member functions is valid syntax for overloading the addition operator (+) in C++? Example: BigInt X, Y(20), Z(10); X = Y + Z; // <--- using the addition operator BigInt operator + (BigInt a) void operator + (BigInt a, BigInt b) BigInt operator + (BigInt a, BigInt b) void operator + (BigInt a)

BigInt operator + (BigInt a, BigInt b)

Which function prototype would satisfy the line highlighted below: BigInt X(12), Y(24), Z; Z = X + Y; cout << Z << endl; BigInt BigInt::operator+(BigInt, Bigint); int operator+(int, int, int); BigInt BigInt::operator+(int); BigInt operator+(BigInt, BigInt);

BigInt operator+(BigInt, BigInt);

What is the BEST programming language EVER? (Here's a hint) int main() { char p[] = {80,76,85,83}; char ch = 67; cout << ch; for (int i=0; i<2; i++) { cout << '-'; for (int i=0; i<sizeof(p); i++) { cout << p[i]; } } return 0; } C++ Python (yeah, right...) FORTRAN HammerHead

C++

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

C-string

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. True False

False

When using friend functions for operator overloading, which of the following statements is true? Friend functions can access any data member of a class. Friend functions can only access public members of a class Friend functions cannot be used for operator overloading Friend functions are member functions of a class

Friend functions can access any data member of a class.

What is true about the Collatz Conjecture - also known as the 3n+1 problem? It has been proven that it will converge to 1 for all positive integers. It has been proven that it will converge to 1 for all integers. The biggest number is INT_MAX It does not work with negative numbers.

It does not work with negative numbers.

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

Machine Code

What can be understood from the following Linux command and result: $ time sort numbers.dat > sorted.out & real 0m1.593s user 0m5.128s sys 0m0.184s The command took about 0.2 seconds to run The command took about 1.6 seconds to run The command took about 6.9 seconds to run (1.6 + 5.1 + 0.2) The command took about 5.1 seconds to run

The command took about 1.6 seconds to run

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? s1->grade = 'A'; MasterGold->grade = 'A'; The correct answer is not listed sptr.grade = 'A'

The correct answer is not listed

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

You can't assign "cowboy" to name

What is printed to the screen when this program is run: #include <iostream> using namespace std; void toss( ) { throw 42; cout << "hello-" << endl; } int main() { try { toss(); } catch ( const char * s) { cout << "world-"<< endl; } cout << "awesome-"; return 0; } world-awesome- awesome- hello-awesome- hello-world-awesome-

awesome-

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 that is printed by this function? 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];

Suppose there is a class called Card which is a playing card and suppose I have a vector of cards called deck. Consider the following code segment: vector<Card> deck; // create a vector of cards Card c1('A','S'); // create a card ????? // add the card to the deck What is the statement that will add the card to the deck? deck.push_back(c1); deck.put(c1); deck.add(c1); deck = c1;

deck.push_back(c1);

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

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

man wc

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

more

Consider the following program and the scope of the variables in the function scope. Where does the variable ptr[5] live? (line 5) #include <iostream> using namespace std; int x = 10; void scope(int z) { static int y = 20; int *ptr = new int[10]; cout << x << endl; // line 1 cout << y << endl; // line 2 cout << z << endl; // line 3 cout << ptr << endl; // line 4 cout << ptr[5] << endl; // line 5 } int main() { x = 5; scope(x); return 0; } on the stack on the move on the heap on the spot

on the heap

Consider the following program and the scope of the variables in the function scope. Where does the variable x live? (line 1) #include <iostream> using namespace std; int x = 10; void scope(int z) { static int y = 20; int *ptr = new int[10]; cout << x << endl; // line 1 cout << y << endl; // line 2 cout << z << endl; // line 3 cout << ptr << endl; // line 4 cout << ptr[5] << endl; // line 5 } int main() { x = 5; scope(x); return 0; } on the moon on the stack on the heap on the run

on the heap

Consider the following program and the scope of the variables in the function scope. Where does the variable y live? (line 2) #include <iostream> using namespace std; int x = 10; void scope(int z) { static int y = 20; int *ptr = new int[10]; cout << x << endl; // line 1 cout << y << endl; // line 2 cout << z << endl; // line 3 cout << ptr << endl; // line 4 cout << ptr[5] << endl; // line 5 } int main() { x = 5; scope(x); return 0; } on the road on the heap on the lam on the stack

on the heap

Consider the following program and the scope of the variables in the function scope. Where does the variable ptr live? (line 4) #include <iostream> using namespace std; int x = 10; void scope(int z) { static int y = 20; int *ptr = new int[10]; cout << x << endl; // line 1 cout << y << endl; // line 2 cout << z << endl; // line 3 cout << ptr << endl; // line 4 cout << ptr[5] << endl; // line 5 } int main() { x = 5; scope(x); return 0; } on the run on the heap on the stack on the contrary

on the stack

Consider the following program and the scope of the variables in the function scope. Where does the variable z live? (line 3) #include <iostream> using namespace std; int x = 10; void scope(int z) { static int y = 20; int *ptr = new int[10]; cout << x << endl; // line 1 cout << y << endl; // line 2 cout << z << endl; // line 3 cout << ptr << endl; // line 4 cout << ptr[5] << endl; // line 5 } int main() { x = 5; scope(x); return 0; } on the beach on the side on the heap on the stack

on the stack

Which one of the following operator cannot be overloaded in C++? The correct answer is not listed operator[ ] operator& operator+ operator?:

operator?:

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 touchdown pass by reference pass by linkage pass by value

pass by value

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? sptr->age = 49; student.age = 49; You're joking... right? sptr.age = 49;

sptr->age = 49;

What is printed to the screen when this program is run: #include <iostream> using namespace std; void toss( ) { throw 42; cout << "hello-" << endl; } int main() { try { toss(); } catch ( int ) { cout << "world-"<< endl; } cout << "awesome-"; return 0; } hello-awesome- world-awesome- hello-world-awesome- the correct answer is not listed

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 ptr the contents of a the number 10 the memory address of a

the memory address of a


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

Retirement Plans: Education and Health Savings Plans Review Questions

View Set

Ch 11: Shock, Sepsis, and Multiple Organ Dysfunction Syndrome

View Set

Chemistry Unit 6 TEST States of matter

View Set

APUSH Period 1 Critical Thinking Questions

View Set

RN Pharmacology Online Practice 2023B

View Set