COSC102 Midterm 1

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/87

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.

88 Terms

1
New cards

Which mode in Vim allows you to write new code?

insert

2
New cards

What is the relationship between Unix and Linux?

Linux is based on Unix.

3
New cards

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.

4
New cards

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

mkdir

5
New cards

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.

6
New cards

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.

7
New cards

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

rmdir

8
New cards

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.

9
New cards

What is an operating system?

The underlying program controlling the basic functionality of the computer.

10
New cards

What command is used to copy a line in Vim?

yy

11
New cards

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).

12
New cards

What is Unix?

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

13
New cards

What is the command line interface in Linux?

A way to navigate the operating system using commands.

14
New cards

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

ls

15
New cards

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.

16
New cards

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

linux

17
New cards

How do you write and quit Vim?

In normal mode, type :wq

18
New cards

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.

19
New cards

How can you revive cin from a fail state?

Use cin.clear().

20
New cards

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

Use cin.fail().

21
New cards

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.

22
New cards

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

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

23
New cards

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

setw()

24
New cards

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')

25
New cards

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

showpos

26
New cards

What does the setprecision(x) manipulator do?

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

27
New cards

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

setw()

28
New cards

How do you paste copied lines in vim?

p

29
New cards

How do you delete a line in vim?

dd

30
New cards

How do you remove a file in the command line?

rm

31
New cards

How do you remove a directory in the command line?

rmdir (directory must be empty)

32
New cards

How do you copy a file in the command line?

cp (file) (new destination)

33
New cards

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

ssh (secure shell)

34
New cards

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)

35
New cards

What does whoami do?

It displays your user name

36
New cards

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

clear

37
New cards

How do you move a file in the command line?

mv (path of file) (path of destination)

38
New cards

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

cd ..

39
New cards

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

<iostream>

40
New cards

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.)

41
New cards

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

<iomanip>

42
New cards

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

right for right justify, left for left justify.

43
New cards

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

fixed

44
New cards

What does the showpoint manipulator do?

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

45
New cards

How do you use manipulators to notate scientific notation?

scientific

46
New cards

What does the hex manipulator do?

converts the output to hex format.

47
New cards

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

arrayLists

48
New cards

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

<vector>

49
New cards

How do you declare a vector in c++?

vector<(data type)> vectorName;

50
New cards

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

vectorName[i] or vectorName.at(i)

51
New cards

What index do vectors start at?

ZERO!!!!

52
New cards

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

vectorName.push_back()

53
New cards

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

vectorName.size()

54
New cards

How do you clear a vector?

vectorName.clear()

55
New cards

How do you resize a vector?

vectorName.resize()

56
New cards

How can you declare a 2D vector?

vector<vector<(data type)>> vectorName

57
New cards

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

vectorName [row][column]

58
New cards

What are file streams?

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

59
New cards

What do you need to #include to use filestreams?

<fstream>

60
New cards

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");

61
New cards

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

fin.close();

62
New cards

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");

63
New cards

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

64
New cards

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

fout.close()

65
New cards

Can you use IO manipulators for fout?

yes

66
New cards

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

.is_open() or .fail()

67
New cards

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))

68
New cards

What do you need to #include to use getline?

<string>

69
New cards

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

stoi()

70
New cards

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

It goes through each line in the input stream.

71
New cards

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[]){}

72
New cards

What does argc return?

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

73
New cards

What will argc return in this scenario?

./calculate 5 4 3 10

5

74
New cards

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).

75
New cards

What will argv[0] always return?

The name of the program.

76
New cards

What will argv[2] return in this scenario?

./calculate 17 23 4

23

77
New cards

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.

78
New cards

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

<sstream>

79
New cards

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

istringstream sin;

sin.str(variable);

OR

istringstreamsin(input);

80
New cards

How do you declare an output string stream object?

ostringstream sout;

81
New cards

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

sout << var1;

string myString = sout.str();

82
New cards

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.

83
New cards

What does sin/sout .clear() do?

Clears the string stream

84
New cards

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

YEA!!!

85
New cards

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

A C-style string

86
New cards

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

right

87
New cards

What does this line of code do?

vector a (5,0);

Creates a vector of 5 integers all initialized to zero.

88
New cards

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

vector myVector {10, 20, 30};