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.

  1. 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?
  2. Verify that you can compile the code examples from the first lecture, such as is-prime-three-files.zip.
  3. 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).
  4. 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.
  5. 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 + y2r2. 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

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