Skip to content

pl3onasm/Programming-fundamentals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

$\huge{\color{cadetblue} \text{Programming}} \space {\color{cadetblue} \text{Fundamentals}}$


This repository contains old exams for the course ${\color{rosybrown}\text{Imperative}}$ ${\color{rosybrown}\text{Programming}}$ (IP) at the University of Groningen. In 2023, this course was merged with the course ${\color{rosybrown}\text{Program}}$ ${\color{rosybrown}\text{Correctness}}$ (PC) into the new course ${\color{rosybrown}\text{Programming}}$ ${\color{rosybrown}\text{Fundamentals}}$ (PF). This is why you will find exams for both courses in this repository. All exams were created by dr. A. Meijster, and make for some good practice material.

For the C questions, the subfolders each hold one or more example solutions, a folder with test cases, and a file called myprogram.c which you can use to write and test your own solution. For the proof questions, both exam questions and answers are given in Dafny.

Found this repository useful? Help out your (future) fellow students by mailing your exam paper to me or submitting a pull request. Scans or pictures with handwritten notes are perfectly fine, as any annotations will be removed. Also, feel free to report any issues you find.



$\Large{\color{darkseagreen}\text{IP Finals}}$

2012 exam 2013 exam 2014 exam
2015 exam 2015 resit 2016 exam
2017 exam 2017 resit 2018 exam
2018 resit 2019 exam 2019 resit
2020 exam 2021 exam 2022 exam

$\Large{\color{darkseagreen}\text{IP Midterms}}$

2013 exam 2015 exam 2016 exam
2016 resit 2017 exam 2017 resit
2018 exam 2018 resit 2019 exam
2019 resit 2020 exam 2020 resit
2021 exam 2021 resit 2022 exam

$\Large{\color{darkseagreen}\text{PF 1-3 exams}}$

2023 exam 2023 resit 2024 exam
2025 exam

$\Large{\color{darkseagreen}\text{PF 2-3 exams}}$

2023 exam 2023 resit 2024 exam
2024 resit 2025 exam

$\Large{\color{darkseagreen}\text{PF 3-3 exams}}$

2024 exam 2024 resit 2025 exam
2025 resit 2026 exam


$\Large{\color{cadetblue}\text{Testing}}$

You can test your own C code with the test script. The script compiles your program, runs it on all .in test cases, and compares the output with the corresponding .out files.

By default you get a clean summary (PASS or FAIL per test case).

If a test fails, and you want to see the difference in expected and actual output, or you want to have extra Valgrind tests, you can use the following options:

  • --show-diff or -d shows a small preview of the output differences for failed tests, including the first 5 lines of the expected output and the first 5 lines of your actual output (both indented under the test case).
  • --valgrind or -v enables Valgrind checks (PASS or FAIL per test case).
  • --show-vg or -e shows Valgrind error details for failed Valgrind checks.
  • --help or -h prints the full usage message.

If you want to use this script, you basically have two options:


$\Large{\color{rosybrown}\text{1. Execution from script's}}$ $\Large{\color{rosybrown}\text{repo location}}$

Opening a terminal from the working directory containing your program, the solution, and the folder with the tests, run the below commands.
First, make the script executable:

chmod +x ../../../ctest.sh

Then run the script by using the following command:

../../../ctest.sh myprogram.c

You can also add options after the program name:

../../../ctest.sh myprogram.c -d -v

$\Large{\color{rosybrown}\text{2. Execution from PATH}}$

Alternatively, you can add the script to your PATH variable and run it from anywhere. To display the current $PATH, run the following command:

echo $PATH

Then, copy the script to one of the folders in $PATH. If you have copied the script to the folder before, the command will simply overwrite the previous version. For example:

sudo cp ctest.sh /usr/bin/

Now you can run the script from the directory containing your program and the folder with test cases by using the following command:

ctest.sh myprogram.c

You may also choose to redirect the output to a file, in which case the script automatically disables ANSI colors to render a plain text file:

ctest.sh myprogram.c > results.txt


$\Large{\color{cadetblue}\text{C-library}}$

The folder C-library contains a small C utility library called clib comprising various helpers for arrays, strings, matrices, sorting, searching, etc. This library is intended to be used as a support library for the exercises in this repository.

It is easy to extend: you can add your own helpers under C-library/src and declare them under C-library/include/clib, rebuild the static library, and all programs in the repo can immediately use the new functionality while the core stays compact and maintainable.

The library is organized as:

  • headers in C-library/include/clib/
  • sources in C-library/src/
  • build output in C-library/build/

You can include the full library with the umbrella header:

#include "../../C-library/include/clib.h"

Or include only what you need (for example just integers):

#include "../../C-library/include/integers.h"

Available headers include:
clib.h, integers.h, strings.h, sorting.h, searching.h, cmath.h, memory.h, and macros.h.

The library is built as a static library via the Makefile in the C-library folder. You can build it manually by running make in that folder. This will create the static library file build/libclib.a. However, when you use ctest.sh, and include a header from the library in your program, the script will automatically call the Makefile to build the library if it is not already built.

Some concrete examples of how to use the library can be found in the C-library and Exercises folders.



$\Large{\color{cadetblue}\text{Notes}}$

All commands were given with Ubuntu in mind. If you are using a different Linux distribution, you may need to change the commands accordingly.

The script was tested on Ubuntu 24.04 LTS, using GCC 14.2.0, and Valgrind 3.22.0.

If you want to compile and test your code manually, you can use the following commands:

gcc -O2 -std=c99 -pedantic -Wall -o a.out myprogram.c -lm
valgrind --leak-check=full ./a.out < tests/1.in


$\Large{\color{cadetblue}\text{Output examples of the script}}$

im01 im02
im03 im04
im05 im06
im07

Releases

No releases published

Packages

 
 
 

Contributors