Question
Task 1 Imagine that you are an engineer on a distant planet. Your ship has crash landed and you are trying to build devices and
Task 1
Imagine that you are an engineer on a distant planet. Your ship has crash landed and you are trying to build devices and machines to send a distress signal. There are two 2 current problems to consider. The first is the heat sink management system for the signal tower and the second is the message dispatcher. Both of these components are ready, but require code in order to function properly. In particular, the rapid pace of your development means that fixed sized structures would be unwise. Therefore you will be implementing a stack and queue through the use of a linked list.
3.1 heatStack
The class is defined according to the simple UML diagram below:
heatStack
-top: heatNode
----------------------------
+heatStack()
+~heatStack()
+push(t: heatNode
+pop():void
+peek():heatNode
+print():void
+validateCooling(heat: int *, numSinks:int):bool
The class variables are defined below: top: The current top of the stack. It will start as null but should refer to the top of the stack. The class methods are defined below:
heatStack: The class constructor. It will start by initialising the variables to null.
heatStack: The class destructor. It will deallocate all of the memory assigned by the class.
push: This will receive a heatNode to add onto the current stack. The node is added from the front.
pop: This will remove the top heatNode from the stack. If it is empty, print out EMPTY with a newline at the end and no quotation marks. When removing the node, it should be deleted.
peek: This will return the top node of the stack but without removing it from the stack.
print: This will print the entire contents of the stack. For each node in the stack (from the top of the stack), print the following information out sequentially, line by line. The format of this is as follows:
Heat Sink CL: X
X refers to the coolant level of a given node.
validateCooling(heat: int *, numSinks:int): This function receives two variables. The first is an array of ints representing a cooling tower configuration. The second is the number of elements in the array. The array represents the cooling requirements of a potential configuration of the signal tower. The first element represents the top of the tower and corresponds to the top of the stack. Its value, an int, indicates how much cooling power the tower needs at that level. This function returns a bool, indicating whether the current heatStacks configuration, ie the heatNodes in the stack, are capable of validating the requirements. It returns true if this is the case and false otherwise. To successfully validate, the following conditions must all be met:
1. There are at least the same number of heatNodes in the stack as the number of sinks required.
2. The cumulative cooling power of the stack is greater than or equal to the requirements provided by the array.
3. No heatNode has a coolant level smaller than the number of heatNodes.
3.1.1 heatNode
The class is defined according to the simple UML diagram below:
heatNode
-coolantLevel: T
+next:heatNode
-power:int
------------------------
+heatNode(i:T,p:int)
+~heatNode()
+getCoolantLevel() const:T
+getPower() const:int
The class variables are defined below:
coolantLevel: This describes the amount of coolant held in the node.
next: A pointer to the next node of the stack.
quantity: A variable which describes the strength of the coolant stored in the heatNode. A larger value indicates a stronger cooling potential. The class methods are defined below:
heatNode: A class constructor. It receives the coolantLevel and power for that node.
heatNode: The class destructor. It should print out Heat Sink Removed with no quotation marks and a new line at the end.
getCoolantLevel(): Returns the coolant level.
getPower(): Returns the power variable.
4 3.1.2 msgQueue
The class is defined according to the simple UML diagram below:
msgQueue
-head: msgNode
-tail:msgNode*
----------------------------
+msgQueue()
+~msgQueue()
+enqueue(t: msgNode
+dequeue():void
+peek():msgNode
+print():void
+compileMessageData():void
The class variables are defined below:
head: The current top of the queue. It will start as null but should refer to the top of the queue.
tail: The end node of the queue. It will also start as null. The class methods are defined below:
msgQueue: The class constructor. It will start by initialising the variables to null.
msgQueue: The class destructor. It will deallocate all of the memory assigned by the class.
enqueue: This will receive a new node to add to the queue.
dequeue: This will remove the top msgNode from the queue. If it is empty, print out EMPTY with a newline at the end and no quotation marks. When removing the node, it should be deleted.
peek: This will return the top node of the queue but without removing it from the queue.
print: This will print the entire contents of the queue,from the head. For each node print the following information out sequentially, line by line. The format of this is as follows:
Message I [Size: Y]
I refers to the message index, with the head being index 0. Y refers to the size of the message in kilobytes.
compileMessageData(): This function compiles a summary of all of the current number of messages in the queue. It should print out the following information:
1. Number of messages: The total number of messages
2. Total Size: The sum of all of the message sizes. The symbol appended to the total should reflect the size of the total. If the sum is smaller than a megabyte, KB should be used. If it is smaller than a gigabyte, MB should be used. The value should reflect this as well representing the conversion.
An example (and format) of the output is as follows:
Total Number of Messages: 13
Size: 1.3MB
3.1.3 msgNode
The class is defined according to the simple UML diagram below:
msgNode
-message:T
+next:msgNode*
-size:int
------------------------
+msgNode(i:T,s:int)
+~msgNode()
+getMessage() const:T
+getSize() const:int
The class variables are defined below:
message: This is the message attached into the node. It can take a variety of different forms depending on the nature of the message.
next: A pointer to the next node of the queue.
size: A variable which indicates the size of the message in kilobytes. The class methods are defined below:
msgNode: A class constructor. It receives the message and the size for that node.
msgNode: The class destructor. It should print out Message Processed with no quotation marks and a new line at the end.
getMessage: This returns message variable.
getSize: This returns the size variable.
The libraries allowed are as follows:
heatNode: iostream, string
msgNode: iostream, string
Step by Step Solution
There are 3 Steps involved in it
Step: 1
![blur-text-image](https://dsd5zvtm8ll6.cloudfront.net/includes/images/document_product_info/blur-text-image.webp)
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
![blur-text-image](https://dsd5zvtm8ll6.cloudfront.net/includes/images/document_product_info/blur-subtext-image.webp)
Step: 3
![blur-text-image](https://dsd5zvtm8ll6.cloudfront.net/includes/images/document_product_info/blur-subtext-image.webp)
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started