INF205 lab worksheet 1
Submit through Canvas by 11th February 2025.
1. Environment setup
This and most following work will be easiest if you are working under a POSIX-compliant operating system such as Linux or MacOS. If you usually work with Windows, it could be a good idea to install Linux in a dual-boot setup. With some more installation effort, it is naturally also possible to do C++ code development under Windows, using the GNU tools or others. The Windows Subsystem for Linux (WSL) can be used for this purpose; as can MinGW-w64, for example in combination with Visual Studio.
- Make sure that you have a working C++ compiler (GNU or other), and that you have GNU make. What versions of these do you have now?
- Verify that you can compile the code examples from the first lecture, such as is-prime-three-files.zip.
- Make sure that in your environment, it is possible to execute a program directly from the command line; in the example above, by typing ./is-prime-900 on the command line. On most systems, you should also be able to do a simple runtime measurement by typing time ./is-prime-900 (which should show a runtime equal or close to zero).
- Modify the is-prime example code so that it takes user input for x from the command line, rather than using the hardcoded value 900; to do this, you will need a function header of the form int main(int argc, char** argv), and you will need to include <cstdlib> and use the std::atoi function. Check that this works and that in your environment, you indeed can pass x as a command-line argument.
- Did you experience any major installation/setup or other difficulties? If you have solved these, your advice could be useful to others.
2. Gauss circle problem
Write a C/C++ program that computes how many integer-valued grid points there are within a unit circle of a given integer radius; in other words, how many tuples (x, y) ∈ ℤ2 there are such that x2 + y2 ≤ r2. There, r ∈ ℕ should be passed to the program as a command-line argument.
Try to implement this in a performant way; however, it is OK to submit a simple solution. You are not expected to look into all the literature on the problem (see Wikipedia page).
General information on the worksheets
- There will be three lab worksheets, due on 11.2., 21.2., and 14.3., respectively. You can work on each of these alone or in groups or two or three people; you can decide on this independently for each worksheet.
- The grade in INF205 is obtained by portfolio evaluation (mappe-/gjennomgående vurdering) on the basis of the computer lab work. The first worksheet contributes 20%, the second one 30%, and the third one 50%.
- Your results must be delivered on Canvas. Use your common sense to decide how to deliver the work. Usually a ZIP archive containing a single PDF and the relevant code, in separate folders, is best. It is a good idea to include a Makefile with the code so that it is easy to compile and test. Please do not include the compiled executable binary files in your submission. If you work in a group, only one person should submit on Canvas. Make it clear in your submission that you are a group and who belongs to it.
- For the second and third worksheets, if you work in a group, you will need to state what group member is taking the lead on solving what problem, and each member must do so for at least one problem. For the first worksheet, this is not necessary, and it will be assumed that in the case of a group, all members were contributing to it equally.
Restriction on using AI tools
Within INF205, you are not allowed to deliver any C/C++ code, or fragments of C/C++ code (as part of a larger code), obtained from generative AI. Other use of AI tools is permitted, including for generating test input or any wrapper or batch codes that are not written in C/C++, such as Makefiles or Python scripts used for visualizing results. You must always follow NMBU's guidelines on use of AI, so in particular you must make transparent what AI tools you were using, if any, and how you used them.
The above general information on worksheets and restriction on using AI tools applies to all of INF205, not only this worksheet.
Index