Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Exercises and exam solutions for programming in C and Dafny (1st-year CS course)

License

NotificationsYou must be signed in to change notification settings

pl3onasm/Programming-fundamentals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 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 bydr. 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 calledmyprogram.c which you can use to write and test your own solution. For the proof questions, both exam questions and answers are given inDafny.

Found this repository useful? Help out your (future) fellow students by mailing your exam paper tome or sending a pull request. It's up to you to keep this repository up to date!



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

201220132014
20152015 resit2016
20172017 resit2018
2018 resit20192019 resit
202020212022

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

201320152016
2016 resit20172017 resit
20182018 resit2019
2019 resit20202020 resit
20212021 resit2022

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

20232023 resit2024
2025

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

20232023 resit2024
2024 resit2025

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

20242024 resit2025


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

You can test your own C code with thetest script. It will try to compile your code and run it on all the test cases. It will also compare your output with the expected output, and check for memory leaks by running a Valgrind test. If a test fails, the script will display the line numbers where a mismatch between the expected and the actual output was found, followed by the corresponding lines themselves, so you can easily spot the error. Lines in green and preceded by< represent the expected output, while lines in red and preceded by> are the actual (incorrect) output. If you only see lines in red, it means that your program produced the expected output, but also some additional, unexpected output. The script will only display the first 5 lines where mismatches were found and will indicate how many more there are if applicable.

If you want to use the 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

$\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 color codes will be removed automatically to render a plain text file:

ctest.sh myprogram.c> results.txt


$\Large{\color{cadetblue}\text{Functions library}}$

The folderfunctions contains some useful function implementations in C. Have a look at theheader file to see which functions are available and how to use them.

You can choose to include these functions in your own code, or use them as a reference to write your own implementation. If you want to work with these functions, just add the include directive with the appropriate path. For example:

#include"../../../Functions/clib/clib.h"

Including the header file in this way will also make the test script compile your own code along with the functions from the library. Since the library is small, it is not necessary to work with a static or dynamic library. Some concrete examples of how to use the functions can be found in theFunctions andExtra-C 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 22.04 LTS, using GCC 13.1.0, Valgrind 3.18.1, and GNU bash 5.1.16(1)-release.

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 example of the script}}$

Example output


[8]ページ先頭

©2009-2025 Movatter.jp