classes Flashcards

(19 cards)

1
Q

what is a class

A

a way to group related data together in an easy to access method

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

what is an instance of a class

A

an object

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

encapsulation

A

group related data together in an easy to access method

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

abstraction

A

when we separate the interface (what the user can do) from the implementation (what actually happens “behind the scenes”)

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

what is a public member

A

something declared in a class that can be used outside of a class

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

what is a private member

A

functions that are only used inside of the class; must be accessed by members of the class (like setters and getters, which are always public for this reason)

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

what functions return the number of characters in a string

A

.length(), .size()

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

what function checks if the length of the string is 0

A

.empty()

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

what function clears the contents of the string

A

.empty()

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

what function adds a string/character to the end of a string

A

.append()

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

can a member function definition access private data members?

A

yes!

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

::

A

Scope resolution operator
Use when defining a member function of a class (like in cpp files)
Helps private class data become visible

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

by default, class members are…

A

private

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

how do you call a default constructor?

A

MyClass obj;
*no parenthesis!

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

what are constructors

A
  • has the same name as the class
  • usually starts with a capital letter
  • has no return type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what is special about the parameters of setters?

A

it should not be named the same thing as your member variable
ex: want parameter to be row_in if the variable is row, so that you have no confusion with trying to set row = row

17
Q

what should you include in a cpp file to reference a class

A

include “ClassName.h”

18
Q

what goes in source (cpp) files?

A

function implementations
*don’t forget scope resolution operator (::) to associate the function with the class!

19
Q

what goes in the header (.h) file?

A

where class definition and function declarations go