CS Week 3 - Classes I Flashcards

1
Q

what is a strut

A

struct name {
type item;
….
};
—- in main —
name object;
object.item;

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

data member

A

each struct sub item

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

member access

A

dot notation
.
for a declared variable, each struct data member can be accessed using .

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

how can use structs and functions

A

to return multiple values
function return type is struct name
pass in a regular argument
create another object in order to return it

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

how can you use structs and vectors

A

declaration of just one vector that stores items that each have a name and number data member

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

how to declare a constructor the professor way

A

name()
: item(iniValue), …. {
}

name (type item, …)
: item(iniValue),… {
}

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

how do you use a private data in main

A

in struct
type getName() const {return Name};
- usually all in one line

in main
cout &laquo_space;getName();

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

how do you set private data from main

A

in struct
void setName(type nameInput) {
name = nameInput;
}

in main
object.setName(input);
cout &laquo_space;getName;

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

difference between classes and structs

A

struct - default everything is public

class- default everything is private

struct is when you have no accessors or methods/functions needed

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

what is an object

A

a grouping of data - variables - and operations that can be performed on that data - functions

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

what is abstraction

A

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

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

what is abstractions data type (ADT)

A

a data type whose creation and update are constrained to specific well-defined operations - example - class

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

class

A

defines a new type that can group data and functions to form an object

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

public member functions

A

indicate all operations a class user can perform on the object

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

private data members

A

variables that member functions can access but class users cannot

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

function declaration

A

return type, function name, and parameter types;

17
Q

function definition

A

return type className :: functionName (parameters) {
statements ;}

18
Q

mutator

A

modify data
sets the value

19
Q

accessors

A

accesses, not to modify
gets the value
const after parameters
if it calls other functions, those must also be const

20
Q

private helper functions

A

to help public functions carry out tasks
any in the class can call these
private and public can call public and private

21
Q

how to initialize data members

A

in the class definition

private :
string name = something;
int num = something;
};

or constructors

22
Q

what is a constructor

A

called automatically when a variable of that class type is declared and which can initialize data members

23
Q

what is a default constructor

A

no arguments

className :: className () {
set the variables equal to something here;
}

24
Q

overload

A

by defining multiple constructors differing in parameter types

class name{
public:
//sets to default value
name ();

        //sets to input values when called
     name (parameters that will be set to the private varibales); ... };
25
Q

implicit parameter

A

object.Function();

object variable before the function name

compiler converts the call into a function call with a pointer to the object implicitly passed a parameter

26
Q

member access operator

A

->
this->
makes it clear that a class member is being accessed and is essential if data members and parameters have the same identifier

  • when an objects member function is called, objects memory address is passed via the implicit this parameter