CECS 325 - Final
What is the name of the linux root directory? • ./ • ../ • / • root
/
How do you search forward for a specific word in Vim? • #word • ?word • /word • &word
/word
How can you move the cursor to the beginning of the current line? • 0 • G • H • $
0
Consider the following program. What will be the output? #include <iostream? #include <vector> using namespace std; int main() { vector<int> v; for(auto i = 0l i < 10; i++) v.push_back(i*5); vector<int>::interator it = v.begin(); cout << *(it+3); return 0; } • it will not compile • 5 • 3 • 15
15
The function pthread-create() has how many parameters? • 3 • 2 • 1 • 4
4 parameters
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 • 30/40 • 40/30 • 35/40
40/35
Consider the following C++ code segment: char world[10] = "matrix"; cout << strlen(word); • matrix • 6 • The correct answer is not listed • 10
6
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 typed this command sequence: $ more numbers.dat | tail - 100 | head - 20 | tail -1 • 920 • none of these answers are correct • 901 • 921
920
How can you save changes to a file and exit Vim? • :exit • :wq • :write&exit • :save&quit
:wq
In which c++ library is strlen( ) found? <cstring> The correct answer is not listed. <strlen> <string>
<cstring>
What is another name for "null terminated character array" • word • container • c-string • the correct answer is not listed
C-string
What is wrong with the following C++ program: #include using namespace std; int main() { int x=3, y=5 // line 1 int * ptr; // line 2 int *ptr2 = &y ; // line 3 y = x; // line 4 ptr = & x; // line 5 cout << x << y << ptr; return 0; } • Line 2 is wrong • Line 3 is wrong • Line 5 is wrong • nothing is wrong
Correct - answer nothing is wrong, but line 1 is missing ";"
What does the :help command do? • Displays a help message • Creates a new Vim session • Opens a file for editing • Opens a new empty buffer
Displays a help message
What does the command :q! do? • Exits without saving changes • Saves changes and exits • Quit Vim with confirmation • The correct answer is not listed
Exits without saving changes
In the C++ language when building a class, the function prototypes must be in a header file (.h) and the implementation must be separate in the .cpp file • True • False
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. • True • False
False
This program will compile and run just fine: #include <iostream> int main() { cout << "Hello World\n"; return 0; } • True • False
False - missing namespace std;
What statement is true about the C++ language? • It is interpreted • It is compiled • None of these answers are correct • It was invented in 1968
It is compiled
What kind of code do computers understand? • Assembly code • Source code • Machine code • Bro code
Machine code
What does the u key do in normal mode? • Moves the cursor to the end of line • Undoes the last change • Deletes the current line • Copies the current line
Undoes the last change
Which mode allows you to navigate and manipulate highlighted text? • Insert mode • Command mode • Replace mode • Visual mode
Visual mode
Consider this code segment: int nums[10]; nums[10] = 999; Which of the following statements is true? • There is nothing wrong with the code • C++ is dangerous motorcycle and you could be mortally wounded if you try to use it! • The code will compile but there is something wrong with this code • The code will not compile
The code will compile but there is something wrong with this 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 5.1 seconds to run • The command took about 1.6 seconds to run • The command took about 0.2 seconds to run • The command took about 6.9 seconds to run(1.6 + 5.1 + 0.2)
The command took about 1.6 seconds to run
Assume the following 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 segment of code in C++: int nums[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; printArray(nums); Also consider this function: void printArray(int n[]) { for(int i = 0, int < n.size(), i++) cout << n[i]; } How many numbers will the printArray() function actually print out? • all the numbers in the array • 10 • 1 • the correct answer is not listed
The correct answer is not listed
What is the error int the following function definition? int doubler(int old_value) { double new_value = old_value * 2; } • No error • The function returns a value of type double • The function attempts to modify its input parameter • The function does not return a value
The function does not return a value
What is the linux command to show the contents of a file? • There are 2 correct answers listed • cat • more • show
There are 2 correct answers listed
The function pthread_create() allows a program to have multiple threads running concurrently. • True • False
True
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 an array to a pointer • Cowboys can't be in the Pony Express • You can't assign "cowboy" to name • There is overflow on the first line
You can't assign "cowboy" to name
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.put(c1); • deck.push_back(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 • type Hello World • print Hello World • push Hello World
echo Hello World
What key is used to enter insert mode in Vim? • i • m • r • t
i
How do you create an array of 20 integers called nums in C++? • int nums = new int[20]; • nums[20] <int> • int nums[20]; • integer nums[20];
int nums[20];
Consider a function name calc, which accepts two numbers as integers and returns their sum as an integer. Which of the following is correct statement to call the function calc? • int sum = calc(2, 3); • calc (2, 3.14); • int sum = calc ("2", "3"); • calc ();
int sum = calc (2, 3);
Using linux commands, how would find out more about the wc command? • more wc • list wc • help wc • man wc
man wc
Consider the following valid C++ function: void func (char * ptr) { cout << ptr; } What is the passing mode is used in the function to pass the parameter ptr? • pass by linkage • pass by value • pass by touchdown • pass by reference
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? • The correct answer is not listed. • student.age = 49; • sptr.age = 49; • sptr->age = 49;
sptr->age = 49;
Consider the following C++ code: int a = 10; int *ptr = &a; cout << ptr; What is printed out? • the memory address of ptr • the number 10 • the memory address of a • the contents of a
the memory address of a
Which command is used to copy the current line in normal mode? • pp • cc • yy • dd
yy