Professional Documents
Culture Documents
IP2223 Lab 1
IP2223 Lab 1
This is the first lab of a series of weekly programming labs. You are required to solve these
programming exercises and submit your solutions to the automatic assessment system Themis.
The system is 24/7 online. Note that the weekly deadlines are very strict (they are given for the
CET time zone)! If you are a few seconds late, Themis will not accept your submission (which
means you failed the exercise). Therefore, you are strongly advised to start working on the
weekly labs as soon as they appear. Do not postpone making the labs! You can find Themis via
the url https://themis.housing.rug.nl
All lab exercises assume that you are running Linux. If you do not, do not expect help from
the teaching assistants in solving computer related problems. If you do not have Linux on your
computer, you are strongly advised to install it. You can install it next to your current operating
system (a so called dual boot system system) or you can run it in a virtual machine. If you
do not have experience installing an operating system (or a dual boot system), then the safest
option is to use a virtual machine. You can run a virtual machine (also on Apple Mac’s) using
the program virtualbox, which is freely available via https://www.virtualbox.org/.
Once you installed virtualbox, you can install any Linux distribution. If you want to install
Linux in a virtual machine yourself, then we advise the Ubuntu distribution that uses the XFCE
desktop which is called xubuntu (see https://xubuntu.org/). However, we made a
pre-configured virtual machine image which you can download from Themis (this is a very large
file (26 GB), so downloading it will take some time).
Note: In lab session 1 you are only allowed to make use of constructs that are taught in
week 1 (so no loops, arrays, functions, etc).
1
cd week1
mkdir hello
cd hello
Create the file hello.c using an editor (for example geany).
geany hello.c &
Type the following program, replace ... by the right information, and save it.
/* file: hello.c */
/* author: ...... (email: ....) */
/* date: ...... */
/* version: ..... */
/* Description: This program prints ’Hello world’ */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
6. If you are convinced that your program works well, you can submit it to the online as-
sessment system Themis. You have completed this first task once Themis accepted your
submission.
2
Problem 2: Scrap Paper
During exams, you will get a few sheets of scrap paper. Scrap paper is packaged in bundles. For
example, for an exam with 500 students, packages that contain 200 sheets, and each student gets
2 sheets of scrap paper, we clearly need 5 packages of scrap paper.
You are requested to write a program that reads from the input three positive integers: the
first integer is the number of students that take part in an exam, the second number is the number
of sheets that each student gets, and the last number is the number of sheets in a package. The
output of the program should be the number of packages needed.
Make sure that the output must have the format as in the following examples. Moreover,
your output must end with a newline (\n).
Example 3:
input:
7264
output:
7264=7*1000 + 2*100 + 6*10 + 4
3
Problem 4: Stock Market
Consider the following scenario. You buy 100 stocks (or crypto coins, or any other alike invest-
ment), priced 1.00C each, so you invest 100.00C. In one year, the stocks go up by 10.0%, so
after one year you have 100 × 1.10 = 110.00C. The next year, the stocks go up again by 10%,
and at the end you have 110 × 1.10 = 121.00C. Overall, after two years your profit is 21.00C.
Write a program that accepts on its input 4 numbers. The first number is a positive integer,
denoting the number of stocks that an invester bought at some point in time. The second number
is a floating point number, denoting the price per stock at that time. The third number is a floating
point number which is a percentage that denotes the rise of the stocks (or fall, in which case this
number is negative) after the first year. The third number is the rise or fall in the second year.
The output of your program should be the profit or loss of the inverstment after two years. Make
sure that your output matches with the following examples. Note that prices are rounded (and
printed) to the level of cents, so a profit (or loss) of less than one cent is considered a tie (no loss,
no profit).
Example 1: Example 2: Example 3:
input: input: input:
100 1.00 10.0 10.0 100 1.00 10.0 -10.0 123 456.78 0.00 0.00
output: output: output:
Profit 21.00 Loss 1.00 Tie