Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
4003CEM-templates_orig/README.md
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
40 lines (25 sloc)
1.58 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 4003CEM-templates | |
## lab_templates | |
1. Replace the multiple `times()` functions in `lab_templates.h` with a single templated function. | |
2. `times()` takes two parameters of the same type. | |
3. `times()` should return a value equal to the two input parameters multiplied together. | |
4. You MUST use templates for this task. | |
## lab_special_template | |
1. Building on your solution from lab_templates, a special case has been introduced in this task. | |
2. If the `times()` function is supplied with a string (a) and and an int (b) as parameters the function should return the string repeated b times. | |
3. Write your solution in the `lab_special_template.h` file. | |
## lab_template_iterators | |
* In the `lab_template_iterators.h` file, write the templated function called `how_long()` | |
* `how_long()` should take two iterators as its input parameters, these iterators represent the beginning and end of a sequence. | |
* `how_long()` should return an integer saying how many elements are in the supplied sequence. | |
* You MUST use templates for this task. | |
## lab_template_return | |
* Complete the template definition of the `add_together()` function. | |
- Should take two iterators as its input parameters. | |
- Should return the sum of the values in the given sequence. | |
* You will need to use `iterator_traits`. | |
## Extended work | |
* Investigate templating C++ classes. | |
- Can be used to create classes that can contain different types of variables. | |
- Use the supplied `stack.h` file combined with your own stack code from the data structures week to implement a templated `Stack` class. | |
{Check It!|assessment}(test-3802955942) | |