Midterm #2 Flashcards

1
Q

types of input

A

arguments, cin&raquo_space;, and getline

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

types of output

A

cout«

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

argc

A

argument counts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

argv

A

argument variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how to compile a program

A

g++ -o example.out example.cpp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

how to run a program

A

./example.out (inline arguments)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

(./example.out 3 10 abc) agrc

A

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

(./example.out 3 10 abc) argv

A

argv[0], argv[1], agrv[2], argv[3]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

(./example.out A B C 1 2)
argc?

A

6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

(./example.out A B C 1 2) argv[3]

A

c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

(./example.out A B C 1 2) argv[5]

A

2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

(./example.out A B C 1 2) argv[4] + argv[5]

A

we cannot have sum of two strings “1” + “2” is an invalid type of addition operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

atoi (str)

A

convert str to an int value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

atof (str)

A

convert str to a double value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

cout«

A

displays a prompt to whoever is running the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

std::

A

formal syntax (don’t need if “using namespace std”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

cin»

A

whatever the user puts into the program (becomes a variable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

getline()

A

if the variable you want contains a space

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

getline() (written out)

A

getline (cin, variable with space)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

\

A

the back-slash

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

"

A

double quote marks

22
Q

\t

A

a horizontal tab

23
Q

\n

24
Q

std::endl

25
Q

branching (tree)

A

if, switch

26
Q

if (tree)

A

if (){
}
if(){
}else{
}

27
Q

bool type

A

Range: True (1) or false(0)
&& - and
|| - or
! - not

28
Q

a==b==c

A

a==b && b==c

29
Q

a != b != c

A

a != b && a != c && b != c

30
Q

a > b > c

A

a > b && b > c

31
Q

a < b < c

A

a < b && b < c

32
Q

a in [b, c]

A

a >= b && a <= c

33
Q

a ∈ [b, c]

A

a >= b && a <= c

34
Q

a not in [b, c]

A

a < b || a > c

35
Q

a !∈ [b, c]

A

a < b || a > c

36
Q

one way if statement

A

if ( <Boolean-Expression> ){
<statement(s)>
}</Boolean-Expression>

37
Q

two ways if statement

A

if ( <Boolean-Expression> ){
statement(s) of "true" case
}else{
statement(s) of "false" case
}</Boolean-Expression>

38
Q

what can you use “if … else” for

A

to make multiple branches

39
Q

if … else multiple branches example

A

if(condition1){
// statement_block1

} else if(condition2){
// statement_block2

} else if(condition3){
// statement_block3

} else{// statement_block4

}

40
Q

common mistake of if statements

A

putting a semicolon after if expression, not using ==

41
Q

what can you use “switch … case” for

A

when there is more options than just true and false

42
Q

switch … case example

A

switch (integer-expression){
case Value 1:
// statement(s) for Case 1

break;
}
case Value2:
// statement(s) for case 2

break;


default:
// statement for default case

}

43
Q

what does (char) represent

A

a character data type that represents a single character

44
Q

what does (string) represent

A

a string data type that represents a sequence of characters

45
Q

what is a literal character

A

represented by single quotation marks (‘a’ ‘5’)

46
Q

message.length/message.size

A

shows the number of characters in a string

47
Q

what is a literal string

A

represented by double quotation marks (“5” “csc117”)

48
Q

stringname[index]

A

what a variable is a a certain position

49
Q

stringname[index] example

A

string s = “ABCD”;
s[0] = ‘P’;
cout &laquo_space;s[0] &laquo_space;endl;
// the output is “PBCD”

50
Q

while loop

A

writes out what ever is looped as many times as you tell it to

51
Q

while loop general example

A

while (condition){
// statement(s);
// loop body
}

52
Q

what are the beginning parts of every program

A

include <iostream></iostream>

#include <cmath>
#include <cctype>
using namespace std;</cctype></cmath>

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