Day 6 Flashcards
What is a class?
A blueprint written by a programmer to define what actions an object can perform
What is an object?
an instance of the class when the program is running
Constructor
called to initialize class data same name as class no parameters
Destructor
- if you see a banana peel ~ you know its a destructor
- uses free memory when the object leaves scope or with the delete keyword
Private
- keyword describes section of info only used by class itself.
- by default, all classes are private
- (private means private! - no one else can see it!!)
Public
- keyword that describes info that can be accessed from outside of class
- like free wifi at starbucks ;P
behavior
- function declared inside class body.
- manipulate private class variables
- *it’s a behavior to manipulate private parts **
this
- if you see –> , the answer is THIS.
- indicates the object itself and cannot be accessed outside of the class code definition.
- commonly used with characteristics and methods
Getters
Setters
-keyword is retrieve for getters and assign for setters
they retrieve/assign values to private characteristics
What file contains the 2 classes to perform input and output?
include
Input file stream
std::ifstream
its a class
question will likely ask for a “stream”
this is used when READING data from the file
be careful not to confuse this with fstream, read slowly on test
Output file stream
std::ofstream
it’s a class
used when WRITING or appending data
file mode : write mode
std::ios::out
truncates contents of existing file
DEFAULT ofstream
file mode: Append
std::ios::app
append to the end of the file if it already exists
file mode: Read mode
std::ios::in
cannot change contents of the file
DEFAULT for ifstream