Resource-efficient programming (INF205) lab u36: 8th September 2022
Work on the below and submit as one file through canvas. One person submits individually on behalf of all group members; write somewhere who your group members are.
There is no grade for this, and there are no strict deadlines or rules. The recommendation is to work together in the same groups in which you plan to collaborate for the INF205 programming project: Best in groups of three, alternatively as a group of two. Recall that 100% of the grade for INF205 will come from that project (coding weeks 43-48, presentation week 49f.). It will be an advantage to sort out viable group dynamics and processes in advance.
1. Terminology
We are building a glossary together. Help make it relevant:
- Suggest one term, expression, or keyword for which we should agree on a precise definition and where also a brief explanation might be helpful. It can be from or closely related to this week's lecture or Stroustrup (2018) book sections (1.2, 1.3, 1.8), or from Leiserson et al. (2020), etc.
- What definition would you suggest? Rule of thumb: A good definition is brief.
- What makes you suggest this term: Can you point to a concrete reason? This may help improve the lecture for the future. (For example, is it unusual jargon that was just used in the lecture assuming everybody knew it, or do you know the term in a different meaning from another context, or is it something where a rigorous definition is needed beyond just talking about it, etc.?)
2. Installation
The main purpose of today's lab is to make sure that everybody has a working environment for C++ programming, and that we become aware of any major issues at setting it up.
- The only piece of software that is really strictly needed for this module is a C++ compiler. Under Linux, it is already there; under Windows, try codeblocks-20.03mingw-setup.exe from Code::Blocks (see also older version recommended by Eclipse). Send in the output that you get from the command g++ --version in case you have the GNU C++ Compiler, or the equivalent version output in case of a different compiler.
- GNU make can be useful for compiling projects of intermediate size and complexity. If you have g++ you probably also have make. Check that it does what it should by compiling the u36 lecture example with the command make. Send in the version output from make --version.
- Not strictly needed, but could be helpful: An integrated development environment (IDE) such as Eclipse. Install Eclipse for C/C++. (Load it from there, do not e.g. install the standard ubuntu package, which is the version for Java programming.) Did it work: Can you get Eclipse to compile its built-in Hello World example? If you cannot get it to work, summarize briefly what is going wrong. Another IDE that you might try out is Code::Blocks.
3. From Python to C++
Rewrite in C++. The program should compile and execute, i.e., it will need an int main() function.
# output Fibonacci numbers smaller or equal to x
# return True if x is a Fibonacci number, False if it is not
#
def print_fibo_until(x):
n = 1
fibo_n = 1
fibo_previous = 0
while x >= fibo_n:
print(n, fibo_n, sep="\t", end="\n")
fibo_next = fibo_n + fibo_previous
n += 1
fibo_previous = fibo_n
fibo_n = fibo_next
return x == fibo_previous
y = 17711
if print_fibo_until(y):
print(y, "is a Fibonacci number")
else:
print(y, "is not a Fibonacci number")
If you go by the textbook, beside Section 1.2, 1.3, 1.8, also Section 1.4 about types would be relevant. For the integers, you can use int, and for the return type of print_fibo_until() you can use bool.