cpsc1430 midterm 2 (Classes, OOP, Linked Lists)

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/14

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

15 Terms

1
New cards

Which method is the default constructor of the class?

Resources are allocated without prior deletion, and no OUTSIDE information is used to set the members

2
New cards

Which method is the copy constructor of the class?

Resources are allocated without prior deletion, and another instance is used to set the members

3
New cards

Which method is a non copy, non default constructor of a class?

Resources are allocated without prior deletion, and an input different from the associated class is used to set the members

4
New cards

Which method is the assignment operator of the class?

Allocations and deallocations are balances, and another instance is used to set the members

5
New cards

Which method is the destructor of the class

Resources are freed without a matching allocation

6
New cards

From a programmer's perspective, the way methods work with their parameters is different compared to the "normal" functions declared outside of classes. Explain this difference.

Methods take a pointer to an instance of their class as an

implicit parameter. Every member of the instance pointed by

the implicit parameter can be accessed as though it was a

local variable in the method body

7
New cards

What is the purpose of an access specifier, and where are they used? Provide one example of an access specifier.

used to control whether or not a

method / member in a class definition is externally

accessible. An example of an access specifier is "public",

which marks methods / members as externally accessible.

8
New cards

What is the purpose of a default constructor?

A default constructor is used to initialize the state of a class instance when no external information is supplied for that initialization.

9
New cards

When are default constructors called?

When a class instance is declared without any parameters and without assignment, the instance is implicitly initialized through its class's default constructor.

10
New cards

What is the purpose of an overloaded assignment operator?

An overloaded assignment operator is used to copy the state

of one instance of a class into another pre-existing instance

of the class (providing additional logic compared to default

assignment behavior). This is particularly important for

classes which have invariants based around exclusive

ownership of a resource.

11
New cards

When are overloaded assignment operators called?

Overloaded assignment operators are called when an instance

of the corresponding class is assigned into another instance of

the same class outside of the assignee's declaration

12
New cards

what are the differences between .cpp and .h files?

.cpp is where you define the methods and functions and you initialize methods, classes, constructors, etc in .h

13
New cards

What defines the ordering of elements in a linked list?

The ordering of the elements in a linked list is defined by

the pointer values stored at each node. The node identified

by this pointer (or a null address) indicates how the ordering

progresses directly after the associated element

14
New cards

Compare and contrast linked list

ordering relative to how arrays order their values.

Arrays store all elements contiguously, and the position of

an element in an array's ordering is determined by the

element's position in memory relative to adjacent elements.

In essence, linked lists represent their order explicitly with

pointer values, whereas arrays represent their order

implicitly through their element's addresses

15
New cards

Can a linked list simultaneously store elements in different types of storage

(static/stack/dynamic)? Why or why not?

Yes, as long as mixing storage types does not violate any of

the invariants imposed upon the linked list implementation.

The structure/ordering of a linked list is defined through the

pointer values at each of the nodes. Pointers can be held in

any type of storage and can point into any type of storage,

so nothing inherently disallows joining nodes from different

types of storage