Comp Sci Ch 5 Ch 6 Flashcards

1
Q

What does equality mean with string comparisons

A

same number of characters and each corresponding character is identical

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

what does relational mean with string comparisons

A

begins at index 0 and compares each character until the evaluation results in false, or end of string is reached

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

What do you have to include when you want to use character operations

A

include <cctype></cctype>

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

What are the 5 functions when working with characters and what do they do

A

isalpha(c) - true if c is a letter
isdigit(c)- true if c is a number 0-9
isspace(c)- true if whitespace or endl;
toupper(c)- returns the uppercase version of c
tolower(c)- returns the lowercase version of c

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

How to access an input string

A

getline(cin, name);

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

How do you access a string character

A

name.at(x)

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

if you know length, how do you find index

A

length - 1w

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

what do you use to find the string size

A

name.size()

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

how can you append one string to another one

A

string1.append(string2)

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

what are test cases you can use when testing your code involving a string

A

0 indexes or the start or end

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

when to use while loop vs for loop in string code

A

while loop for when user to providing sentinel value
for loop when we know end/stop

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

how do you find an item and how in a specific index range

A

string.find(item)
string.find(item, index)

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

what is returned when an item is not found

A

string::npos

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

how to get a substring starting at an index and with having length characters

A

string.substr(index, length)
-if no length goes to end

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

how to add a character to the end of a string

A

string.push_back(c)

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

how to insert a sub string to a string at a specific index

A

string.insert(index, substr)

17
Q

how to replace characters at some indexes with a substr

A

string.replace(index, num, substr)
index to num-1

18
Q

how to return a copy of string 1 with string 2 appended

A

str1 + str2

19
Q

The 3 parts of a for loop expression

A

loop initialization
loop expression
loop variable update

20
Q

++i vs i++

A

pre increment and post increment
pre- increment then output
post- output then increment

-in for loops it does not matter but use ++i instead :)

21
Q

When doing a loop that involves some kind of false statement or true, what should you do

A

when its false, make the loop stop

22
Q

How do you iterate through a string with a FOR loop

A

starting at 0 to name.size()

23
Q

how do you iterate until done with a string with a WHILE looo

A

while ( name.find(item) != string::npos)

24
Q

What is a nested for loop

A

a for loop that appears in the body of another for loop

25
Q

how should you walk through a for loop

A

check, body run, increment

26
Q

What is a nested for loop for

A

used to generate all combinations of some items

27
Q

how do you walk through a nested for loop

A

check 1st loop, 2 run inside loop as you would normally walk through, increment outer loop

28
Q

What types of comments should you add for developing a program incrementally and how should you check a loop works

A

FIXME, output each i

29
Q

what must you declare to use ifstream and ofstream

A

include <fstream></fstream>

30
Q

How to read from a file

A

–declare ifstream
–open the file using name.open(name of file)
–check if an if branch if it opened using !name.is_open() as expression–inside if cout the error and return 1;
–read each one using while loop with expression name» a variable you declared to store each new value
–close file using name.close()

31
Q

How to write to a file

A

–declare of ofstream
–open the file using name.open(name of file)
–check if an if branch if it opened using !name.is_open() as expression–inside cout an error message and return 1
–write to the string using name &laquo_space;“stuff”
–close file using name.close()