2nd Test Flashcards

(22 cards)

1
Q

To have input and output files:

A

include LTfstreamGT

```
Use:
Ifstream (filename
Name things in the file;
Name another thing in the file;
String name;)
(Int score;)
~~~

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

How to open a file:

A

FakeFileName.open(“RomeoJuliet.txt”);

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

How to close a file:

A

FakeFileName.close();

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

.eof()

Returns what?

A

End of file character.

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

What does fin.get() do?

A

It gets a single character from a file.

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

How to make an output file?

A

name the file:
ofstream nameOfFileThatYouWant;

Later…
open the file!
nameOfFileThatYouWant.open(“YeOldeRomeoJuliet.txt”)

Output to the file!
if (!fin.eof())nameOfFileThatYouWant LTLT c;

close the file!
nameOfFileThatYouWant.close(“YeOldeRomeoJuliet.txt”)

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

How to make an input file?

A

name the file:

ifstream nameOfFileThatYouWant2;

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

How to create a constant variable

A

before “using namespace std;”

write: const (data type) (VariableName) = (whatever you choose)

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

Why are constant variables (named constants) useful?

A

You can quickly enter your program and change these key values quickly.

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

Example of a switch statement:

A
Switch(variabe){
case 'w':
    statements;
    break;
case 'd':
    statements;
    break;
case 'a':
    statements;
    break;
default:
    statements;
    break;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to use reference variables?

A

Put a “&” sign in front of the parameters in a function!

This will pass the address of the “shoebox”, not just the value.

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

What does the struct look like and do?

A

struct nameUChoose{
Int var1
Int var2
};

NameUChoose = localName;
localName.var1 = blah
LocalName.var2 = glop

This allows us to have multiple values in one place!

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

What is a ppm?

A

Portable pixmap file

It allows us to make a graphics using text!

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

How to do PPM:

A

P3 (this says it’s a ppm)
1 4 (this says 1 columns, 3 rows)
255 ((red, green, blue: RGB) 0 means no color, 255 is all color)
(then below you will denote the level of brightness for each element in the array:)
255 0 0 (this means the r= 255, g=0, b=0 - makes red!)
0 255 0 (makes green!)
0 0 255 (makes blue)
255 255 0 (make yellow)

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

What does a struct always end with?

A

;

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

How to do a condition (turnary) operator?

A

(condition) ? statement : statement

If the condition is true, the first statement will be read.
If the condition is false, the second statement will be read.

17
Q

How to use a switch statement:

A

Put:
switch(variable)
depending on what that variable is, put cases.
Each case will run unless you place “break;” in each cases followed by :’s

18
Q

What happens if you use a break statement in a for loop?

A

It will break out of the loop

19
Q

What happens is you use a continue statement in a for loop?

A

It will skip the rest of the code in that iteration and test the condition for the loop again.

20
Q

How to make a function an operator

A

Instead of a function name put: operator@

Where @ is the symbol you choose to be your operator.

21
Q

How to do absolute value?

A

Unsigned (data type);

Unsigned makes it always positive

22
Q

How to have a variable be remembered:

A

Make it static!

Ex: static int j = 42
j++;

If this is in a function, j will become 43, then if called again, j will become 44, etc.