CS Week 3 - Classes I Flashcards
what is a strut
struct name {
type item;
….
};
—- in main —
name object;
object.item;
data member
each struct sub item
member access
dot notation
.
for a declared variable, each struct data member can be accessed using .
how can use structs and functions
to return multiple values
function return type is struct name
pass in a regular argument
create another object in order to return it
how can you use structs and vectors
declaration of just one vector that stores items that each have a name and number data member
how to declare a constructor the professor way
name()
: item(iniValue), …. {
}
name (type item, …)
: item(iniValue),… {
}
how do you use a private data in main
in struct
type getName() const {return Name};
- usually all in one line
in main
cout «_space;getName();
how do you set private data from main
in struct
void setName(type nameInput) {
name = nameInput;
}
in main
object.setName(input);
cout «_space;getName;
difference between classes and structs
struct - default everything is public
class- default everything is private
struct is when you have no accessors or methods/functions needed
what is an object
a grouping of data - variables - and operations that can be performed on that data - functions
what is abstraction
to have a user interact with an item at a high level, with lower level internal details hidden from the user
-information hiding, or encapsulation
what is abstractions data type (ADT)
a data type whose creation and update are constrained to specific well-defined operations - example - class
class
defines a new type that can group data and functions to form an object
public member functions
indicate all operations a class user can perform on the object
private data members
variables that member functions can access but class users cannot