Skip to content

chryysmad/Imperative-programming

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Imperative Programming in C

These are old exams for the course Imperative Programming (CS) at the University of Groningen, which are great for practice. All exams are in separate folders, containing a PDF of the exam and a separate subfolder for each exam problem. These 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, because, remember, only practice makes perfect!

If you happen to have a copy of an exam for this particular course that is not yet in this repository, please send it to pl3onasm@gmail.com and I will include it. The same holds if you wrote a solution that is faster, and/or more elegant: send it to me and I will include your solution with your name mentioned as the author.

Final exams

Midterm exams

Compilation

gcc -O2 -std=c99 -pedantic -Wall -o a.out myprogram.c -lm

Execution

./a.out < tests/input.in

Testing

You can test your own code with the test 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.

In order to use it, you basically have two options:

1. Execution from script's location in the root of the repository

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

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 the $PATH. 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

      

Note that if you want to use less, you should add the -r flag (to keep the colors intact):

ctest.sh myprogram.c | less -r

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

      
Example output of the test script:
      

Example output

About

Imperative Programming in C

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 97.6%
  • Shell 2.4%