Structures, Namespaces, and Classes Flashcards

1
Q

aggregate construct

A

allows to manipulate several data items as a single whole

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

struct Date{
int month;
int day;
int year;
};

A

structure definition

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

does a structure have to have a semicolon at the end of its definition

A

yes

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

elements of a structure

A

members or member variables

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

is a structure definition executable

A

no

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

can members of the same structure have the same name?

A

no

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

can members of different structures have the same name?

A

yes

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

assume myDataType is a struct. what is happening in the line below?
myDataType myVar;

A

declaration of the variable myVar of type myDataType

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

formal namespace definition

A

provide a scope for identifiers (variables, functions, etc.) within their declarative region.

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

namespaces are used to…

A

systematize code in logical groups, preventing naming conflict, especially if there are multiple libraries with single names in your code base.

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

how do we access structure variables outside of a structure?

A

StructureObjectName.VariableName

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

by default, the members in a structure are

A

public

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

can a structure variable be initialized at declaration?

A

yes

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

can you declare a structure object Date that has variables month, day, and year like this: Date object = {10, 31, 2035}?

A

yes, because you are assigning the variables when you declare the object

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

if you declare Date object = {10, 31}, and structure Date has three member variables, what will happen?

A

variable one and two will be set to 10 and 31, while variable three will be set to 0 because no number was passed in

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

if you declare Date object {10, 31, 2025, 20}, and structure Date has three member variables, what will happen?

A

an error will occur because there were more numbers passed in than variables that could be assigned

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

can structure objects be directly compared?

A

no

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

how do we see if two structure objects are the same?

A

compare each variable of one object to the same variable of the second object. If all of the variables are equal, then the objects are equal

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

what can a member be in a structure?

A

a basic type (double, int, bool, etc.), or a type of structure

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

what is the definition of namespace?

A

a tool that gives a structure identifiers

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

what is an identifier?

A

something that gives a variable its type (int, double, and bool are all identifiers)

22
Q

look at the code below. what is the output?

namespace n1{
int age = 30; }
namespace n2{
int age = 20;}
cout &laquo_space;age &laquo_space;endl;

A

there will be an error because the program does not know which age to print

23
Q

look at the code below. what is the output?

namespace n1{
int age = 30; }
namespace n2{
int age = 20;}
cout &laquo_space;n1::age &laquo_space;endl;

A

the output is 30 because the age variable is specified by namespace n1

24
Q

why do we use namespace std?

A

it has a library of many useful things, such as cout, cin, and string

25
Q

in a class, all members are

26
Q

when you declare an object of a class, do you have direct access to the variables?

A

no, because they are private

27
Q

how do we access private variables of a class?

A

using public return type functions

28
Q

what is a mutator function?

A

a function that modifies the state of an object

29
Q

what is an example of a mutator function?

A

a void type function

30
Q

what is an accessor function?

A

a function that does not modify the state of any object, it only returns objects

31
Q

what are some examples of accessor functions?

A

int functions, double functions, and bool functions because they all have a return type

32
Q

should you write a function that is both a mutator and accessor function?

A

no, because it is inconvenient to the end user

33
Q

what is a constructor?

A

a function with the same name as the class that does not have a return type

34
Q

what happens when you overload a constructor?

A

there is more than one constructor in a class, but they take a different number of parameters, different types of parameters, or both

35
Q

what happens to the default constructor when you create a constructor for a class?

A

it no longer exists

36
Q

what is a default constructor?

A

the constructor provided by VS Code when you create a class

37
Q

how many parameters does the default constructor take?

38
Q

is a constructor declared in the public or private section of a class?

39
Q

what is polymorphism?

A

when the name of the function is the same, but the two functions have different parameters or parameter types

40
Q

how do you initialize inheritence?

A

class NameofChildClass : (public, private, or protected) NameofParentClass

41
Q

what is simple inheritence?

A

only one level of inheritence

42
Q

what is multiple inheritence?

A

when a child class is derived from more than one parent class

43
Q

can you access a member function of a class without an object?

44
Q

can you access a friend function without an object?

45
Q

what does & mean in c++?

A

& is a reference to the object

46
Q

how many objects can a friend function access the private members of?

A

more than 1

47
Q

what member of a class can access private variable without the . operator?

A

a static member

48
Q

what is multilevel inheritence?

A

when the parent class you are deriving from is already derived from a class. The class you have just created has a grandparent class.

49
Q

if a member/member function is public in the parent class, can it be accessed in the child class?

50
Q

if a member/member function is protected in the parent class, can it be accessed in the child class?

51
Q

if a member/member function is private in the parent class, can it be accessed in the child class?