13.1 User-defined data types Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Why are user-defined data types necessary?

A

Necessary as it allows the user to create data types that are custom to their required needs.

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

Difference between a composite data type vs non-composite?

A

non-composite data type = defined without reference to another data type. Not iterable, no functions, immutable.

composite data type = built from other data types. e.g. List.

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

Define an enumerated data type

A

nc
TYPE Rating = (1 .. 10)
DECLARE Happiness : Rating
Happiness ← 9

from enum import Enum, auto
class Lunch(Enum):
    noodles = auto()
    rice = auto ()

today = Lunch(1)

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

Define a pointer

A
nc
TYPE MyPointer = ^INTEGER
DECLARE variable1 : MyPointer
variable^ ← variable2
variable1 ← @variable3
variable1 ← variable2^   (@ memory location var2)
variable ← variable3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define a set

A

c
DECLARE MyThings : SET OF STRING
MyThings ← {“phone”, “laptop”, “camera”}

my_things = {“phone”, “laptop”, “camera”}
my_things.intersection(your_things) is A AND B
my_things.union(your_things) is A OR B

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

Define a record

A
c
TYPE ThingOfWonder
  DECLARE Thought : STRING
  DECLARE Prize : INTEGER
ENDTYPE

class ThingOfWonder:

def __init__(self):

self. Thought = ""
self. Prize = 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Define a class for a person with a property name

A
class Person:           
  def \_\_init\_\_(self, name):
    self.\_\_name = name
  def set_name(self, new_name):
    self.\_\_name = new_name
  def get_name(self);
    return self.\_\_name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Define a child class for person called ReallyImportantPerson

A
class ReallyImportantPerson(Person):
  def \_\_init\_\_(self, name, title):
    super().\_\_init\_\_(name)
    self.\_\_title = title
  def get_name(self):
    return super().get_name() + "IS MY NAME!"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly