Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
# 4003CEM-iterators
## lab_iterators
Complete the print_vector function so that it prints out
all the values in the vector seperated by commas.
First in forward and then in reverse order.
You must use iterators to do this.
E.g. if the vector contains the value 1, 2 and 3 then code
should output:
1, 2, 3, 3, 2, 1
## lab_stl
Complete the function so that it calculates the sum of the
unique values in the given sequence.
I.e. if the sequence was 1, 2, 3, 2, 4, 2
then the unique values would be 1, 2, 3, 4
the sum of these unique values would be 10
Make use of the EXISTING features of the STL, it is possible
to solve this entirely using existing functions.
The algorithms library in particular may be helpful
https://en.cppreference.com/w/cpp/algorithm
## lab_find
Write a function (find_position) to find the position of
the first occurance of a given value in a vector.
The function must be called find_position.
It must take 3 parameters:
* an iterator to the beginning of a vector of integers
* an iterator to the end of a vector of integers
* an integer value to search for
The function must return an integer representing the position of
the search value in the vector.
If the value is not in the vector then you should return -1
## lab_algorithm
Your program should print every possible combination
of the values seperated by commas.
Make sure to research the <algorithm> library.
E.g. if items contains the value 3, 2, 1 then code should
output the following in any order:
* 1, 2, 3,
* 1, 3, 2,
* 2, 1, 3,
* 2, 3, 1,
* 3, 1, 2,
* 3, 2, 1,
The order of the permutations does not matter although the
order of values in each permutation obviously does.
The values are supplied as command line arguments
when running the program.
I.e.
bin/lab_algorithm 3 2 1
# Advanced
* postcodes.txt contains several thousand UK postcodes.
Using the STL, write a program and nessecary functions so that you can open the file and output an exact count for the number of postcodes in the file.
* Expand your program so that it can output a list of the distinct outward codes in the file (669).
The outward code is the first half of the postcode, for example the univeristy postcode is CV1 5FB so the outward code is CV1.
You may find it helpful to look at the std::set container.
* Expand your program so that output how many postcodes are listed for each outward code (e.g. CV1 has 463).
You may find it helpful to look at the std::map container.
* **Extra tricky.** postcodes.txt contains 3 fake postcodes, expand your program so that it can identify the invalid postcodes.
You may find it helpful to explore the std::regex_search or std::regex_match functions.