$29
CSCI251/CSCI851 Advanced Programming
Laboratory Exercise 12 (Week 13)
Note that lab exercises marked with a * are effectively extension exercises.
Last lab for the session. You can work on the assignment during this lab if you like, but it’s a good
idea to at least try these questions.
1. Consider the code in Quote.cpp. What concept does it illustrate and what does the quote refer to?
2. Write and use some enumerators to do the following:
(a) Take a rainbow colour as an argument to a function and print out the position of that colour
in the rainbow in a sensible way.
(b) Make a collection of what would normally be independent global constants for a program.
Demonstrate how you would now use them.
3. Write a stream manipulator to reverse the alphabet in an input file being read in using the direction
operator. So if you read in an ’a’ you output a ’z’, and if you read in a ’b’ you output a ’y’, and so
on. Anything that is not a lower case letter can be left unchanged.
The direction operator means that if the program is compiled to reverse, you process the file
Input.txt using ...
$ ./reverse < Input.txt
This means you don’t open a filestream you just get things from cin.
4. Write a program to take a phrase from standard in and test if it is a palindrome. Store the phrase
in a vector<char> and use iterators to traverse it.
5. Write a wrapper class to represent integers mod 11. You should:
(a) Write an appropriate constructor that takes any integer but only constructs the integer mod
11. These means, for example, that whether we passed 19 or 8 to the constructor the same
object would be generated.
(b) Overload the addition, subtraction, and multiplication operators to be consistent with those
operations modulo 11. You can try to overload for division too, although if you were dealing
with a different modulus you then have to be careful as to when it would actually be defined.
6. * The following is a valid C++11 program. See http://www.drdobbs.com/cpp/lambdas-in-c11/240168241
and https://www.cprogramming.com/c++11/c++11-lambda-closures.html.
int main(){(([](){})());}
7. Look at questions from the Spring 2017 exams, available from:
https://ereadingsprd.uow.edu.au/listpage.php?prog=CSCI251
Are there any particular areas you do not understand?
c Luke McAven, SCIT-EIS-UOW, 2019.
1