2nd Test Flashcards
(22 cards)
To have input and output files:
include LTfstreamGT
```
Use:
Ifstream (filename
Name things in the file;
Name another thing in the file;
String name;)
(Int score;)
~~~
How to open a file:
FakeFileName.open(“RomeoJuliet.txt”);
How to close a file:
FakeFileName.close();
.eof()
Returns what?
End of file character.
What does fin.get() do?
It gets a single character from a file.
How to make an output file?
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 to make an input file?
name the file:
ifstream nameOfFileThatYouWant2;
How to create a constant variable
before “using namespace std;”
write: const (data type) (VariableName) = (whatever you choose)
Why are constant variables (named constants) useful?
You can quickly enter your program and change these key values quickly.
Example of a switch statement:
Switch(variabe){ case 'w': statements; break; case 'd': statements; break; case 'a': statements; break; default: statements; break; }
How to use reference variables?
Put a “&” sign in front of the parameters in a function!
This will pass the address of the “shoebox”, not just the value.
What does the struct look like and do?
struct nameUChoose{
Int var1
Int var2
};
NameUChoose = localName; localName.var1 = blah LocalName.var2 = glop
This allows us to have multiple values in one place!
What is a ppm?
Portable pixmap file
It allows us to make a graphics using text!
How to do PPM:
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)
What does a struct always end with?
;
How to do a condition (turnary) operator?
(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.
How to use a switch statement:
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
What happens if you use a break statement in a for loop?
It will break out of the loop
What happens is you use a continue statement in a for loop?
It will skip the rest of the code in that iteration and test the condition for the loop again.
How to make a function an operator
Instead of a function name put: operator@
Where @ is the symbol you choose to be your operator.
How to do absolute value?
Unsigned (data type);
Unsigned makes it always positive
How to have a variable be remembered:
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.