Question: Write in python language: Question 1 : The class car is defined as below: class car: def __init__(self, brand, reg_no): self.__brand = brand self.__reg_no =

Write in python language:

Question 1 :

The class car is defined as below:

class car: def __init__(self, brand, reg_no): self.__brand = brand self.__reg_no = reg_no def __str__(self): return (str(self.__brand)+":"+str(self.__reg_no)) 

Write a circular queue to provide line-up function of the cars. The skeleton of class Queuecircular is shown below:

class Queuecircular: def __init__(self, n): """ Initialize the list of object, cars, with size n def enqueue(self, item): """ Enqueue def dequeue(self): """ Dequeue and return the dequeued car def printfront(self): """ Print the information of the front car def printback(self): """ Print the information of the back car def printall(self): """ Print the information of all the cars on the queue (start from the front)

Write the Car class and Queuecircular class in the answer box below. Note - keep a copy of your solution to this task because you will be extending it step by step in subsequent tasks.

For example:

Test Result
q = Queuecircular(2) car1 = car("BMW", "AB1234") car2 = car("Porsche", "GF1455") q.enqueue(car1) q.enqueue(car2) q.printfront() q.printback()
BMW:AB1234 Porsche:GF1455
q = Queuecircular(2) car1 = car("BMW", "AB1234") car2 = car("Porsche", "GF1455") q.enqueue(car1) q.enqueue(car2) q.printfront() q.printback() q.printall()
BMW:AB1234 Porsche:GF1455 BMW:AB1234 Porsche:GF1455

Question 2:

Starting with your solution to the previous task (or re-typing it all if you are keen!), modify the Queuecircular class. We should check whether the queue is full or empty this time.

For example, you should:

 def enqueue(self, item): """ Enqueue only if the queue is not full def dequeue(self): """ Dequeue and return the dequeued car only if the queue is not empty ... 

Write the Car class and Queuecircular class in the answer box below.

For example:

Test Result
q = Queuecircular(1) car1 = car("BMW", "AB1234") car2 = car("Porsche", "GF1455") q.enqueue(car1) q.enqueue(car2) q.printfront() q.printback()
Queue is full! BMW:AB1234 BMW:AB1234
q = Queuecircular(2) car1 = car("BMW", "AB1234") q.enqueue(car1) q.printfront() q.printback() q.printall() q.dequeue() q.dequeue()
BMW:AB1234 BMW:AB1234 BMW:AB1234 Queue is empty!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!