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;
}
2. Implement a class template for a Vector
of elements that has the following methods:
- insert(index, element): inserts the element at the specified index (must be between 0 and size)
- remove(index): removes an element at the specified index
- sort(cmp): sorts the vector by using a comparison function; add an overload that takes no parameters and uses operator< instead
- print: prints the vector elements
The vector should also have a copy/move constructor, along with an operator[] defined, which returns the element at the given index. You MUST have the implementation in the header.
int compare_ints(int x, int y) {
// return -1, x < y
// return 1, x > y
// return 0, x == y
}
int main() {
Vector<int> v;
// index, element
v.insert(0, 10);
v.insert(1, 5);
v.insert(2, 20);
Vector<int> w = v;
// index
v.remove(0);
v.sort(compare_ints);
printf("%d\n", w[0]);
v.print();
}