Composing Programs has introduced us to a way to implement an OOP system in programming languages that don't have it. Together with the current lesson, the OOP system can do the following: • Make a...


Python OOP (Check pictures for instructions)
Code Template below:






Composing Programs has introduced us to a way to implement an OOP system in programming languages<br>that don't have it. Together with the current lesson, the OOP system can do the following:<br>• Make a class<br>• Bind the self object to a class method<br>• Instantiate objects of a class<br>• Run an --init_() routine during instantiation of an object<br>• Make a class inherit from a base class<br>• Get its superclass from a class method<br>Now, we are interested in augmenting our system to be able to compare two objects. Recognizing that (at<br>least initially) no two objects from the same class are created, we can assign an ID to each object instantiated.<br>This hashcode is used by some languages, such as Java, to implement the equality operator between objects.<br>In this challenge, we will be emulating this in Python.<br>We will be assigning each object with a hash based on a pseudorandom universally unique identifier (UUID).<br>This hash can be retrieved using the hash function. To check whether two objects are the same, we will be<br>implementing an is_same function to check whether their hashes are the same. Finally, we will be<br>implementing a clone function to duplicate an object. There are several ways to

Extracted text: Composing Programs has introduced us to a way to implement an OOP system in programming languages that don't have it. Together with the current lesson, the OOP system can do the following: • Make a class • Bind the self object to a class method • Instantiate objects of a class • Run an --init_() routine during instantiation of an object • Make a class inherit from a base class • Get its superclass from a class method Now, we are interested in augmenting our system to be able to compare two objects. Recognizing that (at least initially) no two objects from the same class are created, we can assign an ID to each object instantiated. This hashcode is used by some languages, such as Java, to implement the equality operator between objects. In this challenge, we will be emulating this in Python. We will be assigning each object with a hash based on a pseudorandom universally unique identifier (UUID). This hash can be retrieved using the hash function. To check whether two objects are the same, we will be implementing an is_same function to check whether their hashes are the same. Finally, we will be implementing a clone function to duplicate an object. There are several ways to "clone" an object, but we will only implement a very simple one that makes a new object with the same hash as itself. Input Format The first line of the input is an integer T denoting the number of classes (or testcases) that will follow. Each testcase starts with a line containing a single number denoting the number of commands ne to execute for this testcase. The next line contains the name of the class class_name to create. The next ne lines denote the commands to execute. Each line consists of an operation op followed by some operands. op can only be from this set: create, hash, is_equal, clone. The format of a line with each keyword is shown below, with a and b as snake-case variable names. create a - create an object a of class class_name hash a - get hash of object a • is_equal a b - compare two objects a and b • clone a b - copy object a into a new object c Note that each line in a set of commands is executed in order. For example, the code below shows means that object a is created first, then its hash is printed, and then the object b is then created. create a hash a create b hash b
Constraints<br>Input Constraints<br>1<T< 5<br>0 < ne < 50<br>op E {create, hash, is_equal, clone}<br>class_name is written in CamelCase while object names are in snake_case.<br>Max running time of code should be <5 seconds for each test input.<br>There will be no case wherein a non-existent object is operated on.<br>You can assume that all of the inputs are well-formed and are always provided within these constraints. You<br>are not required to handle any errors.<br>Functional Constraints<br>You are required to make sure that each object instantiated will have a hash, is_same, and clone keys in<br>its dispatch dictionary. Failure to do so will mark your code with a score of zero. For the OJ to work, you are<br>also required to use the template code and only edit the parts marked with a FIXME comment before them.<br>The template code contains the hash-generating function get_uuid (), which generates a pseudorandom<br>UUIDV4 ID. For replication purposes, the random seed is always set to the string EEE111, which is reinitialized<br>everytime a new class is created (i.e. new testcase processed).<br>Output Format<br>The output will consist of several blocks for each testcase. Each block shall start with a line Case #t: with t<br>being the serial number of the testcase starting at 1. The next n, lines denote the corresponding values of the<br>hash or is_equal operations queried from the corresponding commands in the testcase.<br>Sample Input 0<br>User<br>create a<br>create b<br>clone a c<br>hash a<br>hash b<br>hash c<br>is_equal a b<br>is_equal a c<br>is_equal b c<br>Sample Output 0<br>Case #1:<br>656c7a06-049e-434c-95e7-03290203de98<br>e37lec9d-f02d-4ee3-a80b-f2d524c85ed5<br>656c7a06-049e-434c-95e7-03290203de98<br>False<br>True<br>False<br>Explanation 0<br>User objects a and c are the same, while b is a different object altogether.<br>

Extracted text: Constraints Input Constraints 1<>< 5="" 0="">< ne="">< 50="" op="" e="" {create,="" hash,="" is_equal,="" clone}="" class_name="" is="" written="" in="" camelcase="" while="" object="" names="" are="" in="" snake_case.="" max="" running="" time="" of="" code="" should="" be=""><5 seconds for each test input. there will be no case wherein a non-existent object is operated on. you can assume that all of the inputs are well-formed and are always provided within these constraints. you are not required to handle any errors. functional constraints you are required to make sure that each object instantiated will have a hash, is_same, and clone keys in its dispatch dictionary. failure to do so will mark your code with a score of zero. for the oj to work, you are also required to use the template code and only edit the parts marked with a fixme comment before them. the template code contains the hash-generating function get_uuid (), which generates a pseudorandom uuidv4 id. for replication purposes, the random seed is always set to the string eee111, which is reinitialized everytime a new class is created (i.e. new testcase processed). output format the output will consist of several blocks for each testcase. each block shall start with a line case #t: with t being the serial number of the testcase starting at 1. the next n, lines denote the corresponding values of the hash or is_equal operations queried from the corresponding commands in the testcase. sample input 0 user create a create b clone a c hash a hash b hash c is_equal a b is_equal a c is_equal b c sample output 0 case #1: 656c7a06-049e-434c-95e7-03290203de98 e37lec9d-f02d-4ee3-a80b-f2d524c85ed5 656c7a06-049e-434c-95e7-03290203de98 false true false explanation 0 user objects a and c are the same, while b is a different object altogether. seconds="" for="" each="" test="" input.="" there="" will="" be="" no="" case="" wherein="" a="" non-existent="" object="" is="" operated="" on.="" you="" can="" assume="" that="" all="" of="" the="" inputs="" are="" well-formed="" and="" are="" always="" provided="" within="" these="" constraints.="" you="" are="" not="" required="" to="" handle="" any="" errors.="" functional="" constraints="" you="" are="" required="" to="" make="" sure="" that="" each="" object="" instantiated="" will="" have="" a="" hash,="" is_same,="" and="" clone="" keys="" in="" its="" dispatch="" dictionary.="" failure="" to="" do="" so="" will="" mark="" your="" code="" with="" a="" score="" of="" zero.="" for="" the="" oj="" to="" work,="" you="" are="" also="" required="" to="" use="" the="" template="" code="" and="" only="" edit="" the="" parts="" marked="" with="" a="" fixme="" comment="" before="" them.="" the="" template="" code="" contains="" the="" hash-generating="" function="" get_uuid="" (),="" which="" generates="" a="" pseudorandom="" uuidv4="" id.="" for="" replication="" purposes,="" the="" random="" seed="" is="" always="" set="" to="" the="" string="" eee111,="" which="" is="" reinitialized="" everytime="" a="" new="" class="" is="" created="" (i.e.="" new="" testcase="" processed).="" output="" format="" the="" output="" will="" consist="" of="" several="" blocks="" for="" each="" testcase.="" each="" block="" shall="" start="" with="" a="" line="" case="" #t:="" with="" t="" being="" the="" serial="" number="" of="" the="" testcase="" starting="" at="" 1.="" the="" next="" n,="" lines="" denote="" the="" corresponding="" values="" of="" the="" hash="" or="" is_equal="" operations="" queried="" from="" the="" corresponding="" commands="" in="" the="" testcase.="" sample="" input="" 0="" user="" create="" a="" create="" b="" clone="" a="" c="" hash="" a="" hash="" b="" hash="" c="" is_equal="" a="" b="" is_equal="" a="" c="" is_equal="" b="" c="" sample="" output="" 0="" case="" #1:="" 656c7a06-049e-434c-95e7-03290203de98="" e37lec9d-f02d-4ee3-a80b-f2d524c85ed5="" 656c7a06-049e-434c-95e7-03290203de98="" false="" true="" false="" explanation="" 0="" user="" objects="" a="" and="" c="" are="" the="" same,="" while="" b="" is="" a="" different="" object="">
Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here