COSC102 Midterm 1

studied byStudied by 0 people
0.0(0)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

1 / 87

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

88 Terms

1

Which mode in Vim allows you to write new code?

insert

New cards
2

What is the relationship between Unix and Linux?

Linux is based on Unix.

New cards
3

Explain the significance of Vim in the context of coding in a command line interface.

To write any code, you need a code editor, such as VSCode, but editors such as VSCode cannot be used in a command line interface. So, Vim is significant because it's what allows the user to be able to write code in a command line interface.

New cards
4

To make a new directory using the command line, you would use which command?

mkdir

New cards
5

What are normal mode and insert mode in Vim and how do you switch between them?

Normal mode allows you to navigate code files and execute certain commands, whereas insert mode only allows you to edit and add new code. Use i to access insert mode and esc to go back to normal mode.

New cards
6

Explain every part of both the command and the command line prompt below. (samsmith, the @ symbol, etc)

samsmith@workstation2:~$ cd Music

samsmith is the user, @ separates the user and the computer, workstation2 is the computer samsmith is connected to, : separates the computer and the current directory, ~ is the home directory, $ serves as a separator between the directory and the area for the user to execute commands, and cd Music is used to move the user into the Music folder.

New cards
7

To remove a directory using the command line, you would use which command?

rmdir

New cards
8

What is the difference between a graphical user interface (GUI) and a command line interface (CLI)?

A GUI allows for users to access and run commands simply by clicking buttons or pictures, for instance, on windows you can access your documents folder by clicking on the file explorer icon and clicking on the documents folder. On a CLI, there are no images or buttons to click and you must manually type in commands to access certain files or programs, for instance, you would have to type cd Documents to access your documents folder.

New cards
9

What is an operating system?

The underlying program controlling the basic functionality of the computer.

New cards
10

What command is used to copy a line in Vim?

yy

New cards
11

How do you use a command such as copy or delete across multiple lines in vim?

You put the number first, then the command (Ex. 4yy for copy four lines).

New cards
12

What is Unix?

Unix is an operating system that linux is based off of.

New cards
13

What is the command line interface in Linux?

A way to navigate the operating system using commands.

New cards
14

How do you list the contents of a directory using the command line?

ls

New cards
15

What is the difference between an absolute path and a relative path?

An absolute path starts from the root directory, while a relative path starts from the current directory.

New cards
16

Which operating system is the Macintosh operating system (MacOS) based on?

linux

New cards
17

How do you write and quit Vim?

In normal mode, type :wq

New cards
18

What happens if cin is used to read an integer, but the user types a double?

The cin call fails and goes into a fail state.

New cards
19

How can you revive cin from a fail state?

Use cin.clear().

New cards
20

How can you check if cin failed to read the correct data type?

Use cin.fail().

New cards
21

What does cin.ignore() do?

Skip one or more character in the key buffer

cin.ignore(n, c);

cin.ignore(20, '\n'); //Skip next 20 characters or until \n

cin.ignore(); //Skip only next character

Also allows you to move past bad input when you use cin.clear() and cin.ignore(numeric_limits::max(), '\n') //Must #include when using this.

New cards
22

What does cin.get() allow you to do?

Read and save a single character from input, including whitespace.

New cards
23

Which manipulator is used to set the width of the NEXT FIELD ONLY??!?!?

setw()

New cards
24

What manipulator is used to change the character used to fill extra spaces in a field?

setfill() - must be a char in single quotes (ex. '0')

New cards
25

Which manipulator is used to determine whether the plus sign (+) is shown with positive numbers?

showpos

New cards
26

What does the setprecision(x) manipulator do?

Changes the float point precision. (Rounds to x decimal places)

New cards
27

WHICH MANIPULATOR IS NOT PERSISTENT????!?!?!?!?

setw()

New cards
28

How do you paste copied lines in vim?

p

New cards
29

How do you delete a line in vim?

dd

New cards
30

How do you remove a file in the command line?

rm

New cards
31

How do you remove a directory in the command line?

rmdir (directory must be empty)

New cards
32

How do you copy a file in the command line?

cp (file) (new destination)

New cards
33

What command do you use to remote connect to a hydra/tesla machine?

ssh (secure shell)

New cards
34

How do you copy a file from a hydra/tesla machine to your personal computer using the command line?

scp (netid@computername.eecs.utk.edu):(directory of file on hydra/tesla) (where you want to copy the file to)

New cards
35

What does whoami do?

It displays your user name

New cards
36

How do you clear the console logs in the command line?

clear

New cards
37

How do you move a file in the command line?

mv (path of file) (path of destination)

New cards
38

How do you move to the parent directory in the command line?

cd ..

New cards
39

What do you need to #include for cin and cout?

<iostream>

New cards
40

What does wrapping cin in an if statement do?

It checks to make sure that the value types are the same (ex. if x is an int and you have if(cin>>x), cin>>x will return true if x is an int and false if it is not.)

New cards
41

If you use I/O manipulators, what must you #include?

<iomanip>

New cards
42

How do you right or left justify using I/O manipulators?

right for right justify, left for left justify.

New cards
43

If you want to use setprecision, what must also be included so the number is not printed in scientific notation?

fixed

New cards
44

What does the showpoint manipulator do?

writes a decimal point for a double output, even if the point is unnecessary.

New cards
45

How do you use manipulators to notate scientific notation?

scientific

New cards
46

What does the hex manipulator do?

converts the output to hex format.

New cards
47

What are vectors in c++ similar to in java?

arrayLists

New cards
48

What do you need to #include if you want to use vectors?

<vector>

New cards
49

How do you declare a vector in c++?

vector<(data type)> vectorName;

New cards
50

How can you access a vector element at a selected index in c++?

vectorName[i] or vectorName.at(i)

New cards
51

What index do vectors start at?

ZERO!!!!

New cards
52

How can you add a new element to the end of a vector in c++?

vectorName.push_back()

New cards
53

How can you get the size of a vector in c++?

vectorName.size()

New cards
54

How do you clear a vector?

vectorName.clear()

New cards
55

How do you resize a vector?

vectorName.resize()

New cards
56

How can you declare a 2D vector?

vector<vector<(data type)>> vectorName

New cards
57

How can you access a single element in a 2D vector?

vectorName [row][column]

New cards
58

What are file streams?

They allow you to read input and print output in external files.

New cards
59

What do you need to #include to use filestreams?

<fstream>

New cards
60

How do you declare a file stream input name and open a file?

ifstream fin;

fin.open("input.txt"); // THIS MUST BE IN DOUBLE QUOTES OR BE A STRING VARIABLE

OR

ifstream fin("input.txt");

New cards
61

What do you need to put after you are done collecting input with fin?

fin.close();

New cards
62

How do you declare a file stream output name and open a file?

ofstream fout;

fout.open("output.txt"); // THIS MUST BE IN DOUBLE QUOTES OR BE A STRING VARIABLE

OR

ofstream fout("output.txt");

New cards
63

What is stored in var1 when this line of code is excecuted if input.txt contains "John Doe"

ifstream fin("input.txt");

string var1;

fin >> var1;

fin.close();

John

New cards
64

Once you are done using fout, what line do you have to put?

fout.close()

New cards
65

Can you use IO manipulators for fout?

yes

New cards
66

What are the two ways you can check if an fin or fout file was successfully opened?

.is_open() or .fail()

New cards
67

How can you get an entire line in c++?

getline(input stream you want to use (ex. cin, fin, sin), string to store in, OPTIONAL; delimiter(char to stop at, \n by default))

New cards
68

What do you need to #include to use getline?

<string>

New cards
69

If you get an number from getline(), what must you use to store it as an int?

stoi()

New cards
70

What does it mean if you wrap fin or getline inside of a while loop?

It goes through each line in the input stream.

New cards
71

If you want to use argv and argc, what do you write instead of int main?

int main(int argc, char **argv){}

OR

int main(int argc, char *argv[]){}

New cards
72

What does argc return?

The number of arguments used when the program is run using ./

New cards
73

What will argc return in this scenario?

./calculate 5 4 3 10

5

New cards
74

What is argv and what does it return?

argv means argument values, and argv[i] will return the argument at that index (arguments are separated by whitespace).

New cards
75

What will argv[0] always return?

The name of the program.

New cards
76

What will argv[2] return in this scenario?

./calculate 17 23 4

23

New cards
77

How can you error check with argc?

If you know the number of arguments needed, you can use an if statement to check if argc is not equal to your specified number of arguments.

New cards
78

What must you #include if you want to use string streams?

<sstream>

New cards
79

How do you declare an input string stream object and an input string?

istringstream sin;

sin.str(variable);

OR

istringstreamsin(input);

New cards
80

How do you declare an output string stream object?

ostringstream sout;

New cards
81

How would you add an existing variable var1 to a string named myString using string streams?

sout << var1;

string myString = sout.str();

New cards
82

What does .str() contain when using stringstreams in c++?

With sin.str(), it sets the input string.

With sout.str(), it contains everything that has been added to the stringstream using sout.

New cards
83

What does sin/sout .clear() do?

Clears the string stream

New cards
84

If there is a vector v, do v.clear() and v.resize(0) both set the size of the vector to zero?

YEA!!!

New cards
85

When you use command line arguments, what data type is a single argument stored as?

A C-style string

New cards
86

Which justification (left/right) is default when using IO manipulators?

right

New cards
87

What does this line of code do?

vector a (5,0);

Creates a vector of 5 integers all initialized to zero.

New cards
88

How would you create a vector named myVector with three ints, 10, 20 and 30, in that order?

vector myVector {10, 20, 30};

New cards
robot