Week 10 - Inheritance and Enumerations, Sockets & Threads Flashcards

1
Q

What is the general form for class inheritance (C++)?

A

class derived-class-name : access-specifier base-class-name
{ /* body of class */ }

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

What are the three access specifiers?

A

Private, public and protected

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

What is the difference between protected members in a class and private members in a class?

A

Protected members can be accessed by derived classes, while private members cannot

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

What is good practice in inheritance access?

A

Use public inheritance unless there is a good reason to do otherwise

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

What are the two general rules in terms of inheritance constructors and destructors?

A

Constructors are execute in order of derivation

Destructors are executed in reverse order of derivation

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

What is simple inheritance?

A

Where a single class inherits from a single base class

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

What is chain inheritance?

A

Where a single class inherits from a single base class, and a second single class inherits from the first class, e.g. base -> single1 -> single2

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

What is multiple inheritance?

A

Where a single class inherits from more than one base class

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

What are two solutions to the ambiguity created by the diamond problem?

A

Apply the scope resolution operator

Prevent two copies of based being included in the 3rd derivation

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

What is an enumeration?

A

A set of user-defined integer constants

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

How do you define and use an enumeration?

A

enum boolean {False, True};
enum boolean isok;
iskok = True;

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

By default, how do enumeration values work?

A

Start at 0 and increment by 1 each time

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

What do sockets do?

A

Enable two nodes on a network to talk to each other

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

What happens on the server side when using sockets?

A

Create a socket (socket)

Set socket options (setsockopt)

Bind the listener process to a specific port number (bind)

Start listening (listen)

Whenever a client requests a connection:
- Accept a connection request from a client (accept)
- Exchange data with the client (send, read)
- Close connection (close)

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

What happens client side when using sockets?

A

Create a socket (socket)

Request a connection (connect)

Exchange data with server (send, read)

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

What are pipes?

A

Pairs of sockets

17
Q

What are threads?

A

Lightweight processes

18
Q

How is multi-threaded implemented in C/C++?

A

Provided by POSIX as pthreads using the POSIX Threads API

19
Q

What does POSIX stand for?

A

Portable Operating System Interface

20
Q

What header file does pthreads need?

A

pthread.h

21
Q

How do you link with the pthread library?

A

Include the link flag -lpthread

22
Q

What is mutex?

A

Mutual exclusion (lock and unlock) a locking mechanism for threads so there is single thread access at a time

23
Q

What is semaphore?

A

A signalling mechanism for threads (wait and signal) which allows multiple threads simultaneous access to the resource at any one time

24
Q

How do wait and signal work with semaphore?

A

Wait:
- if semaphore count is 0, then it waits until it isn’t
- decrements the semaphore count by 1

Signal:
- increments the semaphore count by 1 to sow that it has finished using the resource