cecs 325 midterm

5.0(1)
studied byStudied by 225 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/39

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

40 Terms

1
New cards

What statement is true about the C++ language?
a) None of these answers are correct.

b) it is interpreted

c) It was invented in 1968

d) It is compiled

d) It is compiled

2
New cards

How do you create an array of 20 integers called nums in C++?
a) nums[20] <int>

b) int nums[20];

c) integer nums[20];

d) int nums = new int[20];

b) int nums[20];

3
New cards

If I am in Linux, how can I determine which directory I am currently in?

a) cd

b) where

c) pwd

d) show

c) pwd

4
New cards

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

5
New cards

This program will compile and run just fine:

#include <iostream>
 
int main()
{
     cout << "Hello World\n";
     return 0;
}

True

False

False

6
New cards

What kind of code do computers understand?

a) Machine Code

b) Bro Code

c) Assembly Code

 d) Source Code

a) Machine Code

7
New cards

What is the linux command to show the contents of a file? 
a) show

b) more

c) dir

d) There are 2 correct answers listed

b) more

8
New cards

What linux command is used to print "Hello World" on the terminal?

a) print Hello World

b) echo Hello World

c) push Hello World

d) type Hello World

b) echo Hello World

9
New cards

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?

a) deck.push_back(c1);

b) deck = c1;

c) deck.put(c1);

d) deck.add(c1);

a) deck.push_back(c1);

10
New cards

What is the name of the linux root directory?

a) ./

b) ../

c) root

d) /

d) /

11
New cards

What key is used to enter insert mode in Vim?

a) m

b) r

c) t

d) i

d) i

12
New cards

How can you save changes to a file and exit Vim?

a) :save&quit

b) :write&exit

c) :wq

d) :exit

c) :wq

13
New cards

Which command is used to delete the character under the cursor?

a) z

b) d

c) x

d) r

c) x

14
New cards

What does the u key do in normal mode?

a) Moves the cursor to the end of the line

b) Copies the current line

c) Undoes the last change

d) Deletes the current line

c) Undoes the last change

15
New cards

How do you search forward for a specific word in Vim?

a) &word

b) /word

c) #word

d) ?word

b) /word

16
New cards

Which command is used to copy the current line in normal mode?

a) cc

b) yy

c) pp

d) dd

b) yy

17
New cards

How can you move the cursor to the beginning of the current line?

a) H

b) 0

c) $

d) G

b) 0

18
New cards

What does the command :q! do?

a) Exits without saving changes

b) Saves changes and exits

c) Quits Vim with confirmation

d) The correct answer is not listed

a) Exits without saving changes

19
New cards

Which mode allows you to navigate and manipulate highlighted  text?

a) Replace mode

b) Command mode

c) Insert mode

d) Visual mode

d) Visual mode

20
New cards

What does the :help command do?

a) Opens a new empty buffer

b) Opens a file for editing

c) Displays a help message

d) Creates a new Vim session

c) Displays a help message

21
New cards

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?

a) 11

b) the correct answer is not listed

c) 1

d) all the numbers in the array

b) the correct answer is not listed

22
New cards

Consider the following program. how many numbers are printed to the output screen?

#include <iostream>
#include <vector>
using namespace std;

int main()
{
  vector<int> v;
  for (int i=0; i<10; i++)
        v.push_back(i * 5);


    while (v.size() > 0)
    {
      cout << v.back()<<endl;
    }

  return 0;
}

a) it will not compile

b) 0

c) more than 10

d) 10

c) more than 10

23
New cards

Consider this code segment:

int nums[10]= {10,20,30};
nums[10] = 999;

a) There is nothing wrong with the code

b) The results are unpredictable.

c) The code will not compile.

d) C++ is a dangerous motorcycle and you could be mortally wounded if you try to use it!!!

b) The results are unpredictable.

OR

c) The code will not compile.

(regraded question)

24
New cards

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

a) more wc

b) list wc

c) help wc

d) man wc

d) man wc

25
New cards

I have a safe at my house that is filled with chocolate and I don't want my grandkids to steal any so I have converted the safe combination from decimal numbers to septenary numbers and then I wrote the septenary combination on the front of the safe in large digits so I wouldn't forget - and also to torment the grandkids...

This is the combination of the safe:

36 - 25 - 16

What is written on the safe?

a) The correct answer is not listed.

b) 62 - 17 - 22

c) 49 - 43 - 23

d) 51 - 34 - 22

e) 16 - 25 - 36

d) 51 - 34 - 22

26
New cards

Consider the following C++ variable declaration:

short x = ?????;    // x is initialized to some number which you cannot see

Suppose this is the binary representation of x:

1011001011010011

Which of the following is true?
a) The value is less than zero

b) There are too many binary digits listed

c) The value is greater than 200

d) There are not enough binary digits listed

a) The value is less than zero

27
New cards

Consider the following code segment:

int nums[10] = {7, 8, 9};

    cout << sizeof(nums);

What is printed on the output screen?
a) 40

b) 3

c) 30

d) 10

a) 40

28
New cards

What is printed to the screen when this program is run:

#include <iostream>
using namespace std;

void toss( )
{
    cout << "hello-";
    throw 42;
}
int main()  
{
    try { toss(); }
    catch ( const char * s)
        { cout << "world-"; }
    
    cout << "awesome-";
    return 0;
}

a) hello-awesome-

b) world-awesome-

c) hello-world-awesome-

d) hello-

a) hello-awesome-
OR
c) hello-world-awesome-

(regraded question)

29
New cards

What is printed to the screen when this program is run:

#include <iostream>
using namespace std;

void toss( )
{
     throw 42;
    cout << "hello-";
}

int main()  
{
    try { toss(); }
    catch (...)
        { cout << "world-"; }
    
    cout << "awesome-";
    return 0;
}

a) hello-world-

b) -awesome-

c) world-awesome-

d) hello-awesome-

c) world-awesome-

30
New cards

When you create and use classes in C++ , the classes must be separated into header file and implementation file.

True

False

False

31
New cards

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 -10 | head -5 | tail -1

a) 10

b) 1

c) none of these answers is correct

d) 5

c) none of these answers is correct

32
New cards

Consider the following code segment in C++:

int a = 5;

int b = 10;

int *ptr = &a;

*ptr = b;

cout << a;

What will be printed on the screen?

a) 5

b) the address of b

c) the address of a

d) 10

d) 10

33
New cards

Consider this complete program:

#include <iostream>
using namespace std;

int mystery(int a, int & b)
{
    a += 5;
    b += 5;
    return a + b;
}


int main()
{
  int x = 10;
  int y = 20;
  int z = mystery(x, y);
  cout << x << "/" <<  y;
}

What prints to the screen?
a) 35/40

b) 10/25

c) 40/30

d) 30/40

b) 10/25

34
New cards

What is wrong with the following C++ program:

#include <iostream>
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;
}

a) nothing is wrong

b) Line 2 is wrong

c) line 5 is wrong

d) line 3 is wrong

a) nothing is wrong

35
New cards

What is wrong with the following C++ program:

#include <iostream>
using namespace std;

int main()
{
    int x, y=5 ;               // line 1
    int * ptr;                     // line 2
    int *ptr2 = &y ;          // line 3
    int & ref;                    // line 4
    ptr = & x;                  // line 5
    cout << x << y << *ptr;
    
    return 0;
}

a) Line 3 is wrong

b) line 4 is wrong

c) line 1 is wrong

d) Line 2 is wrong

b) line 4 is wrong

36
New cards

Consider the following segment of code in C++:

int nums[10] = {1,2,3,4,5,6,7,8,9,10};
printArray(nums, 5);

Also consider the this function:

void printArray(int n[ ], int size)
{
for(int i=0, i < size, i++)
cout << n[i];
}

How many numbers will the printArray( ) function actually print out?

a) 1

b) all the numbers in the array

c) 5

d) 10

c) 5

37
New cards

Suppose I run the bubble sort function on 10,000 numbers and it takes 2 seconds.

About how long will it take the same function to sort 20,000 numbers?

a) 4 seconds

b) 24 seconds

c) 12 seconds

d) 8 seconds

d) 8 seconds

38
New cards

What is the expected growth rate of the bubble sort algorithm?

a) O (n)

b) Oh No!!!!!!!

c) O (n * log(n))

d) O (n^2)

d) O (n^2)

39
New cards

Suppose I type this at the Linux prompt:

$ ls -l numbers.dat

Here is the result of the above command:

-rw-r--r-- 1 steve steve 5000 Mar  8 02:19 numbers.dat

Which of the following is true?
a) There are 5000 numbers in numbers.dat

b) The size of numbers.dat is 5000 bytes

c) I'm hungry for a byte of Snickers bar

d) The largest number is 5000 in numbers.dat

b) The size of numbers.dat is 5000 bytes

40
New cards

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

a) The command took about 1.6 seconds to run

b) The command took about 5.1 seconds to run

c) The command took about 6.9 seconds to run (1.6 + 5.1 + 0.2)

d) The command took about 0.2 seconds to run

a) The command took about 1.6 seconds to run