Lab 7

  1. Write two C++ literals for Kelvin and Fahrenheit conversions to Celsius so that the following code works.
int main() {
    float a = 300_Kelvin;
    float b = 120_Fahrenheit;
    return 0;
}

Organize the code in the following way:

  • a main file called main.cpp that contains the main function and has an example on how to use those two literals (similar to the explained in the previous main function)
  • Use the following link for explanation on how to convert from Kelvin and Fahrenheit to Celsius.
  1. Write a template that simulates a tree template. Each node in the tree will contain a value of type T (the template type) and a list of children. YOU ARE NOT ALLOWED TO USE ANY STL TEMPLATE TO STORE THE LIST OF CHILDREN.

Add the following methods:

  • add_node method (to add new node to the tree). The method will receive the parent node or nullptr (in the last case, the new node will be the root of the tree).
  • get_node method (returns a reference / method to a node). The method receives a pointer/reference to its parent (if the reference is nullptr, than the root node will be returned).
  • delete_node method (deletes a node and all its children)
  • find method --> recursively search all nodes for a parameter. The method will receive a pointer to a function that will compare the parameter received to the value T from each node. Thre method returns the first occurence.
  • insert method (insert an new node in a tree at a specific index, given its parent note.)
  • sort method (sort all children from a specific node ==> use a callback function to provide a way to compare two elements. If the callback function is not present (nullptr), operator< is used.)
  • count method (returns how many children a node has). This method walks recursively through all children. If call with nullptr, it returns the count of all children from the root of the tree