Compare commits
3 Commits
master
...
06571e55c1
Author | SHA1 | Date | |
---|---|---|---|
06571e55c1 | |||
0c74082e67 | |||
d57e32a8b8 |
19
Informatik_I/Bonus_1/README.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Project overview
|
||||||
|
|
||||||
|
The goal of this project is to implement a game called _Dots And Boxes_: two players, **A** and **B**, take turns to draw lines connecting dots on a $m \times n$ (here $2 \times 2$) board.
|
||||||
|
|
||||||
|
If a player manages to close a box (a $1 \times 1$ square surrounded by lines), the player claims the box by placing its token (**A/B**) in the box, and the player gets another turn. The game is finished when all boxes have been claimed, and the player with the most claimed boxes wins. Note that, even if a player claims multiple boxes in a single move, they would only get one extra move.
|
||||||
|
|
||||||
|
For example, in the following game player **A** won:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Your task
|
||||||
|
|
||||||
|
The file `game.cpp` contains a partial implementation of the game. The main game loop is implemented in the function `play_game(grid)`. This function is called from `main.cpp` and gets the game grid as an argument. The game grid is already fully implemented. We describe the functionality it provides in a following section below.
|
||||||
|
|
||||||
|
Your task is extending the game implementation in file `game.cpp` such that it works the way described above. We provide some functions in this file and thus suggest a certain structure -- but you are completely free to do it your way. Add, remove or change anything you want. The only constraint is that you must implement the function play_game which takes the game grid as argument. You are of course free to change the body of this function in whatever way you like.
|
||||||
|
|
||||||
|
If you do decide to change the body of the play_game function be careful to not accidentally change the format of the outputs it generates. For example: If you change the output `std::cout << "Game finished" << std::endl;` to `std::cout << "Game Finished" << std::endl;` you will not pass some test cases. The autograder is very picky when checking whether or not your outputs are correct. You can get all the points in this exercise without changing any of the output lines in the template.
|
||||||
|
|
||||||
|
_Note_: More Information on the the concept of the game on Code Expert.
|
@@ -1,29 +1,3 @@
|
|||||||
#+TITLE: Dot and Boxes
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Project overview
|
|
||||||
|
|
||||||
The goal of this project is to implement a game called _Dots And Boxes_: two players, **A** and **B**, take turns to draw lines connecting dots on a \(m \times n\) (here \(2 \times 2\)) board.
|
|
||||||
|
|
||||||
If a player manages to close a box (a \(1 \times 1\) square surrounded by lines), the player claims the box by placing its token (**A/B**) in the box, and the player gets another turn. The game is finished when all boxes have been claimed, and the player with the most claimed boxes wins. Note that, even if a player claims multiple boxes in a single move, they would only get one extra move.
|
|
||||||
|
|
||||||
For example, in the following game player **A** won:
|
|
||||||
|
|
||||||
[[./pictures/dots_and_boxes.svg]]
|
|
||||||
|
|
||||||
* Your task
|
|
||||||
|
|
||||||
The file =game.cpp= contains a partial implementation of the game. The main game loop is implemented in the function =play_game(grid)=. This function is called from =main.cpp= and gets the game grid as an argument. The game grid is already fully implemented. We describe the functionality it provides in a following section below.
|
|
||||||
|
|
||||||
Your task is extending the game implementation in file =game.cpp= such that it works the way described above. We provide some functions in this file and thus suggest a certain structure -- but you are completely free to do it your way. Add, remove or change anything you want. The only constraint is that you must implement the function play_game which takes the game grid as argument. You are of course free to change the body of this function in whatever way you like.
|
|
||||||
|
|
||||||
If you do decide to change the body of the play_game function be careful to not accidentally change the format of the outputs it generates. For example: If you change the output =std::cout << "Game finished" << std::endl;= to =std::cout << "Game Finished" << std::endl;= you will not pass some test cases. The autograder is very picky when checking whether or not your outputs are correct. You can get all the points in this exercise without changing any of the output lines in the template.
|
|
||||||
|
|
||||||
/Note/: More Information on the the concept of the game on Code Expert.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@@ -266,8 +240,3 @@ void play_game(Grid &grid) {
|
|||||||
std::cout << "Player " << winner << " wins!" << std::endl;
|
std::cout << "Player " << winner << " wins!" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
112
Informatik_I/Bonus_1/pictures/horizontal_00.svg
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="26.53125mm"
|
||||||
|
height="26.53125mm"
|
||||||
|
viewBox="0 0 26.53125 26.53125"
|
||||||
|
version="1.1"
|
||||||
|
id="svg4102"
|
||||||
|
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
|
||||||
|
sodipodi:docname="horizontal_00.svg">
|
||||||
|
<defs
|
||||||
|
id="defs4097" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="3.959798"
|
||||||
|
inkscape:cx="94.057447"
|
||||||
|
inkscape:cy="95.056102"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
showgrid="false"
|
||||||
|
fit-margin-top="0"
|
||||||
|
fit-margin-left="0"
|
||||||
|
fit-margin-right="0"
|
||||||
|
fit-margin-bottom="0"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1003"
|
||||||
|
inkscape:window-x="-9"
|
||||||
|
inkscape:window-y="-9"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg4102" />
|
||||||
|
<metadata
|
||||||
|
id="metadata4100">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<rect
|
||||||
|
width="26.25"
|
||||||
|
height="26.25"
|
||||||
|
x="0.140625"
|
||||||
|
y="0.140625"
|
||||||
|
id="rect2987"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.28125;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="M 3.6235642,3.7463729 H 13.267247"
|
||||||
|
id="path3724-7"
|
||||||
|
style="fill:none;stroke:#a00a0a;stroke-width:1.125;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,3.7895896 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,3.7895896 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-8"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,3.7895896 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-5"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,13.26562 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-0"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,13.26562 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-6"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,13.26562 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-4"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,22.74165 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-62"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,22.74165 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-58"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,22.74165 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-628"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
</svg>
|
After Width: | Height: | Size: 6.7 KiB |
112
Informatik_I/Bonus_1/pictures/horizontal_21.svg
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="26.53125mm"
|
||||||
|
height="26.53125mm"
|
||||||
|
viewBox="0 0 26.53125 26.53125"
|
||||||
|
version="1.1"
|
||||||
|
id="svg4102"
|
||||||
|
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
|
||||||
|
sodipodi:docname="horizontal_21.svg">
|
||||||
|
<defs
|
||||||
|
id="defs4097" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="7.9195959"
|
||||||
|
inkscape:cx="86.150889"
|
||||||
|
inkscape:cy="52.339868"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
showgrid="false"
|
||||||
|
fit-margin-top="0"
|
||||||
|
fit-margin-left="0"
|
||||||
|
fit-margin-right="0"
|
||||||
|
fit-margin-bottom="0"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1003"
|
||||||
|
inkscape:window-x="-9"
|
||||||
|
inkscape:window-y="-9"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg4102" />
|
||||||
|
<metadata
|
||||||
|
id="metadata4100">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<rect
|
||||||
|
width="26.25"
|
||||||
|
height="26.25"
|
||||||
|
x="0.140625"
|
||||||
|
y="0.140625"
|
||||||
|
id="rect2987"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.28125;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 13.011406,22.689101 h 9.643683"
|
||||||
|
id="path3724-7"
|
||||||
|
style="fill:none;stroke:#a00a0a;stroke-width:1.125;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,3.7895896 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,3.7895896 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-8"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,3.7895896 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-5"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,13.26562 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-0"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,13.26562 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-6"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,13.26562 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-4"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,22.74165 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-62"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,22.74165 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-58"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,22.74165 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-628"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
</svg>
|
After Width: | Height: | Size: 6.7 KiB |
208
Informatik_I/Bonus_1/pictures/horizontal_idx.svg
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="26.53125mm"
|
||||||
|
height="26.53125mm"
|
||||||
|
viewBox="0 0 26.53125 26.53125"
|
||||||
|
version="1.1"
|
||||||
|
id="svg4102"
|
||||||
|
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
|
||||||
|
sodipodi:docname="horizontal_idx.svg">
|
||||||
|
<defs
|
||||||
|
id="defs4097" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="1.979899"
|
||||||
|
inkscape:cx="157.29139"
|
||||||
|
inkscape:cy="50.915658"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
showgrid="false"
|
||||||
|
fit-margin-top="0"
|
||||||
|
fit-margin-left="0"
|
||||||
|
fit-margin-right="0"
|
||||||
|
fit-margin-bottom="0"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1003"
|
||||||
|
inkscape:window-x="-9"
|
||||||
|
inkscape:window-y="-9"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg4102"
|
||||||
|
showguides="true"
|
||||||
|
inkscape:guide-bbox="true"
|
||||||
|
inkscape:snap-to-guides="true">
|
||||||
|
<sodipodi:guide
|
||||||
|
position="10.15811,23.930618"
|
||||||
|
orientation="0,1"
|
||||||
|
id="guide4182"
|
||||||
|
inkscape:locked="false" />
|
||||||
|
<sodipodi:guide
|
||||||
|
position="5.9531251,20.930432"
|
||||||
|
orientation="1,0"
|
||||||
|
id="guide4184"
|
||||||
|
inkscape:locked="false" />
|
||||||
|
<sodipodi:guide
|
||||||
|
position="15.686012,20.788691"
|
||||||
|
orientation="1,0"
|
||||||
|
id="guide4186"
|
||||||
|
inkscape:locked="false" />
|
||||||
|
<sodipodi:guide
|
||||||
|
position="13.313364,14.440907"
|
||||||
|
orientation="0,1"
|
||||||
|
id="guide4188"
|
||||||
|
inkscape:locked="false" />
|
||||||
|
<sodipodi:guide
|
||||||
|
position="13.41359,4.9862472"
|
||||||
|
orientation="0,1"
|
||||||
|
id="guide4190"
|
||||||
|
inkscape:locked="false" />
|
||||||
|
</sodipodi:namedview>
|
||||||
|
<metadata
|
||||||
|
id="metadata4100">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title />
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<rect
|
||||||
|
width="26.25"
|
||||||
|
height="26.25"
|
||||||
|
x="0.140625"
|
||||||
|
y="0.140625"
|
||||||
|
id="rect2987"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.28125;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,3.7895896 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,3.7895896 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-8"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,3.7895896 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-5"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,13.26562 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-0"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,13.26562 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-6"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,13.26562 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-4"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,22.74165 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-62"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,22.74165 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-58"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,22.74165 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-628"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:3.02851319px;line-height:1;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25237608"
|
||||||
|
x="6.2189474"
|
||||||
|
y="4.508667"
|
||||||
|
id="text4162"
|
||||||
|
transform="scale(0.95386243,1.0483692)"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan4160"
|
||||||
|
x="6.2189474"
|
||||||
|
y="4.508667"
|
||||||
|
style="font-size:2.69201183px;line-height:1;stroke-width:0.25237608"> 0,0 </tspan></text>
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:3.02851319px;line-height:1;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25237608"
|
||||||
|
x="16.454226"
|
||||||
|
y="4.4836931"
|
||||||
|
id="text4162-1"
|
||||||
|
transform="scale(0.95386244,1.0483692)"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan4160-2"
|
||||||
|
x="16.454226"
|
||||||
|
y="4.4836931"
|
||||||
|
style="font-size:2.69201183px;line-height:1;stroke-width:0.25237608"> 0,1 </tspan></text>
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:3.02851319px;line-height:1;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25237608"
|
||||||
|
x="6.2257996"
|
||||||
|
y="13.564726"
|
||||||
|
id="text4162-5"
|
||||||
|
transform="scale(0.95386244,1.0483692)"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan4160-1"
|
||||||
|
x="6.2257996"
|
||||||
|
y="13.564726"
|
||||||
|
style="font-size:2.69201183px;line-height:1;stroke-width:0.25237608"> 1,0 </tspan></text>
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:3.02851319px;line-height:1;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25237608"
|
||||||
|
x="16.454226"
|
||||||
|
y="13.463326"
|
||||||
|
id="text4162-0"
|
||||||
|
transform="scale(0.95386244,1.0483692)"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan4160-5"
|
||||||
|
x="16.454226"
|
||||||
|
y="13.463326"
|
||||||
|
style="font-size:2.69201183px;line-height:1;stroke-width:0.25237608"> 1,1 </tspan></text>
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:3.02851319px;line-height:1;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25237608"
|
||||||
|
x="6.238183"
|
||||||
|
y="22.533091"
|
||||||
|
id="text4162-4"
|
||||||
|
transform="scale(0.95386244,1.0483692)"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan4160-9"
|
||||||
|
x="6.238183"
|
||||||
|
y="22.533091"
|
||||||
|
style="font-size:2.69201183px;line-height:1;stroke-width:0.25237608"> 2,0 </tspan></text>
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:3.02851319px;line-height:1;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25237608"
|
||||||
|
x="16.454226"
|
||||||
|
y="22.578157"
|
||||||
|
id="text4162-54"
|
||||||
|
transform="scale(0.95386244,1.0483692)"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan4160-8"
|
||||||
|
x="16.454226"
|
||||||
|
y="22.578157"
|
||||||
|
style="font-size:2.69201183px;line-height:1;stroke-width:0.25237608"> 2,1 </tspan></text>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 10 KiB |
122
Informatik_I/Bonus_1/pictures/isboxdrawn0.svg
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="26.53125mm"
|
||||||
|
height="26.53125mm"
|
||||||
|
viewBox="0 0 26.53125 26.53125"
|
||||||
|
version="1.1"
|
||||||
|
id="svg4102"
|
||||||
|
inkscape:version="0.92.3 (2405546, 2018-03-11)"
|
||||||
|
sodipodi:docname="isboxdrawn0.svg">
|
||||||
|
<defs
|
||||||
|
id="defs4097" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="5.6"
|
||||||
|
inkscape:cx="78.567572"
|
||||||
|
inkscape:cy="50.641397"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
showgrid="false"
|
||||||
|
fit-margin-top="0"
|
||||||
|
fit-margin-left="0"
|
||||||
|
fit-margin-right="0"
|
||||||
|
fit-margin-bottom="0"
|
||||||
|
inkscape:window-width="3840"
|
||||||
|
inkscape:window-height="2004"
|
||||||
|
inkscape:window-x="-16"
|
||||||
|
inkscape:window-y="-16"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg4102" />
|
||||||
|
<metadata
|
||||||
|
id="metadata4100">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<rect
|
||||||
|
width="26.25"
|
||||||
|
height="26.25"
|
||||||
|
x="0.140625"
|
||||||
|
y="0.140625"
|
||||||
|
id="rect2987"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.28125;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="M 22.901762,22.588768 H 13.25808"
|
||||||
|
id="path3724-8-7-9-8-1"
|
||||||
|
style="fill:none;stroke:#808080;stroke-width:0.65600002;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="M 22.917891,22.848191 V 13.204509"
|
||||||
|
id="path3724-8-7-9-8-5"
|
||||||
|
style="fill:none;stroke:#808080;stroke-width:0.65600002;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="M 22.917891,13.204509 H 13.274209"
|
||||||
|
id="path3724-8-7-9-8"
|
||||||
|
style="fill:none;stroke:#808080;stroke-width:0.656;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,3.7895896 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,3.7895896 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-8"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,3.7895896 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-5"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,13.26562 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-0"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,13.26562 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-6"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,13.26562 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-4"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,22.74165 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-62"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,22.74165 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-58"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,22.74165 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-628"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
</svg>
|
After Width: | Height: | Size: 7.3 KiB |
151
Informatik_I/Bonus_1/pictures/isboxdrawn1.svg
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="26.53125mm"
|
||||||
|
height="26.53125mm"
|
||||||
|
viewBox="0 0 26.53125 26.53125"
|
||||||
|
version="1.1"
|
||||||
|
id="svg4102"
|
||||||
|
inkscape:version="0.92.3 (2405546, 2018-03-11)"
|
||||||
|
sodipodi:docname="isboxdrawn1.svg">
|
||||||
|
<defs
|
||||||
|
id="defs4097" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="5.6"
|
||||||
|
inkscape:cx="78.567572"
|
||||||
|
inkscape:cy="50.641397"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
showgrid="false"
|
||||||
|
fit-margin-top="0"
|
||||||
|
fit-margin-left="0"
|
||||||
|
fit-margin-right="0"
|
||||||
|
fit-margin-bottom="0"
|
||||||
|
inkscape:window-width="3840"
|
||||||
|
inkscape:window-height="2004"
|
||||||
|
inkscape:window-x="-16"
|
||||||
|
inkscape:window-y="-16"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg4102" />
|
||||||
|
<metadata
|
||||||
|
id="metadata4100">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title />
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<rect
|
||||||
|
width="26.25"
|
||||||
|
height="26.25"
|
||||||
|
x="0.140625"
|
||||||
|
y="0.140625"
|
||||||
|
id="rect2987"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.28125;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="M 22.901762,22.588768 H 13.25808"
|
||||||
|
id="path3724-8-7-9-8-1"
|
||||||
|
style="fill:none;stroke:#808080;stroke-width:0.65600002;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="M 22.917891,22.848191 V 13.204509"
|
||||||
|
id="path3724-8-7-9-8-5"
|
||||||
|
style="fill:none;stroke:#808080;stroke-width:0.65600002;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="M 22.917891,13.204509 H 13.274209"
|
||||||
|
id="path3724-8-7-9-8"
|
||||||
|
style="fill:none;stroke:#808080;stroke-width:0.656;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 13.274209,13.204509 v 9.643682"
|
||||||
|
id="path3724-8"
|
||||||
|
style="fill:none;stroke:#a00a0a;stroke-width:1.125;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,3.7895896 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,3.7895896 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-8"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,3.7895896 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-5"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,13.26562 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-0"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,13.26562 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-6"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,13.26562 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-4"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,22.74165 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-62"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,22.74165 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-58"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,22.74165 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-628"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<g
|
||||||
|
aria-label="?"
|
||||||
|
transform="matrix(0.26458333,0,0,0.26458333,0.04724703,1.839808)"
|
||||||
|
inkscape:transform-center-x="-0.25985863"
|
||||||
|
inkscape:transform-center-y="-0.8031994"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:32px;line-height:1.25;font-family:sans-serif;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#a00a0a;fill-opacity:1;stroke:none"
|
||||||
|
id="flowRoot5525">
|
||||||
|
<path
|
||||||
|
d="m 28.279298,67.208984 h 3.171875 v 3.96875 h -3.171875 z m 3.078125,-2.296875 h -2.984375 v -2.40625 q 0,-1.578125 0.4375,-2.59375 0.4375,-1.015625 1.84375,-2.359375 l 1.40625,-1.390625 q 0.890625,-0.828125 1.28125,-1.5625 0.40625,-0.734375 0.40625,-1.5 0,-1.390625 -1.03125,-2.25 -1.015625,-0.859375 -2.703125,-0.859375 -1.234375,0 -2.640625,0.546875 -1.390625,0.546875 -2.90625,1.59375 v -2.9375 q 1.46875,-0.890625 2.96875,-1.328125 1.515625,-0.4375 3.125,-0.4375 2.875,0 4.609375,1.515625 1.75,1.515625 1.75,4 0,1.1875 -0.5625,2.265625 -0.5625,1.0625 -1.96875,2.40625 l -1.375,1.34375 q -0.734375,0.734375 -1.046875,1.15625 -0.296875,0.40625 -0.421875,0.796875 -0.09375,0.328125 -0.140625,0.796875 -0.04687,0.46875 -0.04687,1.28125 z"
|
||||||
|
style=""
|
||||||
|
id="path5665" />
|
||||||
|
</g>
|
||||||
|
<g
|
||||||
|
aria-label="?"
|
||||||
|
transform="matrix(0.26458333,0,0,0.26458333,10.163647,1.8401771)"
|
||||||
|
inkscape:transform-center-x="-0.25985863"
|
||||||
|
inkscape:transform-center-y="-0.8031994"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:32px;line-height:1.25;font-family:sans-serif;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#a00a0a;fill-opacity:1;stroke:none"
|
||||||
|
id="flowRoot5525-2">
|
||||||
|
<path
|
||||||
|
d="m 28.279298,67.208984 h 3.171875 v 3.96875 h -3.171875 z m 3.078125,-2.296875 h -2.984375 v -2.40625 q 0,-1.578125 0.4375,-2.59375 0.4375,-1.015625 1.84375,-2.359375 l 1.40625,-1.390625 q 0.890625,-0.828125 1.28125,-1.5625 0.40625,-0.734375 0.40625,-1.5 0,-1.390625 -1.03125,-2.25 -1.015625,-0.859375 -2.703125,-0.859375 -1.234375,0 -2.640625,0.546875 -1.390625,0.546875 -2.90625,1.59375 v -2.9375 q 1.46875,-0.890625 2.96875,-1.328125 1.515625,-0.4375 3.125,-0.4375 2.875,0 4.609375,1.515625 1.75,1.515625 1.75,4 0,1.1875 -0.5625,2.265625 -0.5625,1.0625 -1.96875,2.40625 l -1.375,1.34375 q -0.734375,0.734375 -1.046875,1.15625 -0.296875,0.40625 -0.421875,0.796875 -0.09375,0.328125 -0.140625,0.796875 -0.04687,0.46875 -0.04687,1.28125 z"
|
||||||
|
style=""
|
||||||
|
id="path5668" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 10 KiB |
112
Informatik_I/Bonus_1/pictures/vertical_00.svg
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="26.53125mm"
|
||||||
|
height="26.53125mm"
|
||||||
|
viewBox="0 0 26.53125 26.53125"
|
||||||
|
version="1.1"
|
||||||
|
id="svg4102"
|
||||||
|
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
|
||||||
|
sodipodi:docname="vertical_00.svg">
|
||||||
|
<defs
|
||||||
|
id="defs4097" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="3.959798"
|
||||||
|
inkscape:cx="66.875008"
|
||||||
|
inkscape:cy="72.027342"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
showgrid="false"
|
||||||
|
fit-margin-top="0"
|
||||||
|
fit-margin-left="0"
|
||||||
|
fit-margin-right="0"
|
||||||
|
fit-margin-bottom="0"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1003"
|
||||||
|
inkscape:window-x="-9"
|
||||||
|
inkscape:window-y="-9"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg4102" />
|
||||||
|
<metadata
|
||||||
|
id="metadata4100">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<rect
|
||||||
|
width="26.25"
|
||||||
|
height="26.25"
|
||||||
|
x="0.140625"
|
||||||
|
y="0.140625"
|
||||||
|
id="rect2987"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.28125;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 3.6121917,3.944092 v 9.643682"
|
||||||
|
id="path3724-8"
|
||||||
|
style="fill:none;stroke:#a00a0a;stroke-width:1.125;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,3.7895896 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,3.7895896 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-8"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,3.7895896 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-5"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,13.26562 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-0"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,13.26562 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-6"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,13.26562 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-4"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,22.74165 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-62"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,22.74165 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-58"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,22.74165 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-628"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
</svg>
|
After Width: | Height: | Size: 6.7 KiB |
112
Informatik_I/Bonus_1/pictures/vertical_12.svg
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="26.53125mm"
|
||||||
|
height="26.53125mm"
|
||||||
|
viewBox="0 0 26.53125 26.53125"
|
||||||
|
version="1.1"
|
||||||
|
id="svg4102"
|
||||||
|
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
|
||||||
|
sodipodi:docname="vertical_12.svg">
|
||||||
|
<defs
|
||||||
|
id="defs4097" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="2.8"
|
||||||
|
inkscape:cx="114.38062"
|
||||||
|
inkscape:cy="68.130493"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
showgrid="false"
|
||||||
|
fit-margin-top="0"
|
||||||
|
fit-margin-left="0"
|
||||||
|
fit-margin-right="0"
|
||||||
|
fit-margin-bottom="0"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1003"
|
||||||
|
inkscape:window-x="-9"
|
||||||
|
inkscape:window-y="-9"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg4102" />
|
||||||
|
<metadata
|
||||||
|
id="metadata4100">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<rect
|
||||||
|
width="26.25"
|
||||||
|
height="26.25"
|
||||||
|
x="0.140625"
|
||||||
|
y="0.140625"
|
||||||
|
id="rect2987"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.28125;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 22.935124,13.076632 v 9.643682"
|
||||||
|
id="path3724-8"
|
||||||
|
style="fill:none;stroke:#a00a0a;stroke-width:1.125;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,3.7895896 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,3.7895896 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-8"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,3.7895896 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-5"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,13.26562 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-0"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,13.26562 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-6"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,13.26562 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-4"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,22.74165 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-62"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,22.74165 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-58"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,22.74165 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-628"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
</svg>
|
After Width: | Height: | Size: 6.7 KiB |
222
Informatik_I/Bonus_1/pictures/vertical_idx.svg
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="26.53125mm"
|
||||||
|
height="26.53125mm"
|
||||||
|
viewBox="0 0 26.53125 26.53125"
|
||||||
|
version="1.1"
|
||||||
|
id="svg4102"
|
||||||
|
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
|
||||||
|
sodipodi:docname="vertical_idx.svg">
|
||||||
|
<defs
|
||||||
|
id="defs4097" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="2.8"
|
||||||
|
inkscape:cx="160.48283"
|
||||||
|
inkscape:cy="65.287899"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
showgrid="false"
|
||||||
|
fit-margin-top="0"
|
||||||
|
fit-margin-left="0"
|
||||||
|
fit-margin-right="0"
|
||||||
|
fit-margin-bottom="0"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1003"
|
||||||
|
inkscape:window-x="-9"
|
||||||
|
inkscape:window-y="-9"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg4102"
|
||||||
|
showguides="false"
|
||||||
|
inkscape:guide-bbox="true"
|
||||||
|
inkscape:snap-to-guides="true">
|
||||||
|
<sodipodi:guide
|
||||||
|
position="0.88588171,16.335659"
|
||||||
|
orientation="1,0"
|
||||||
|
id="guide4184"
|
||||||
|
inkscape:locked="false" />
|
||||||
|
<sodipodi:guide
|
||||||
|
position="10.547898,15.981306"
|
||||||
|
orientation="1,0"
|
||||||
|
id="guide4186"
|
||||||
|
inkscape:locked="false" />
|
||||||
|
<inkscape:grid
|
||||||
|
type="xygrid"
|
||||||
|
id="grid4254" />
|
||||||
|
<sodipodi:guide
|
||||||
|
position="20.198103,15.733259"
|
||||||
|
orientation="1,0"
|
||||||
|
id="guide4256"
|
||||||
|
inkscape:locked="false" />
|
||||||
|
<sodipodi:guide
|
||||||
|
position="15.969494,19.158669"
|
||||||
|
orientation="0,1"
|
||||||
|
id="guide4336"
|
||||||
|
inkscape:locked="false" />
|
||||||
|
<sodipodi:guide
|
||||||
|
position="8.669829,9.543899"
|
||||||
|
orientation="0,1"
|
||||||
|
id="guide4338"
|
||||||
|
inkscape:locked="false" />
|
||||||
|
</sodipodi:namedview>
|
||||||
|
<metadata
|
||||||
|
id="metadata4100">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<rect
|
||||||
|
width="26.25"
|
||||||
|
height="26.25"
|
||||||
|
x="0.140625"
|
||||||
|
y="0.140625"
|
||||||
|
id="rect2987"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.28125;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,3.7895896 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,3.7895896 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-8"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,3.7895896 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-5"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,13.26562 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-0"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,13.26562 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-6"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,13.26562 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-4"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 4.8865036,22.74165 a 1.2712229,1.2712229 0 1 1 -2.54244,0 1.2712229,1.2712229 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-62"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.536844,22.74165 a 1.271225,1.271225 0 1 1 -2.54245,0 1.271225,1.271225 0 1 1 2.54245,0 z"
|
||||||
|
id="path2989-58"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 24.18717,22.74165 a 1.271223,1.271223 0 1 1 -2.54244,0 1.271223,1.271223 0 1 1 2.54244,0 z"
|
||||||
|
id="path2989-628"
|
||||||
|
style="color:#808080;display:inline;overflow:visible;visibility:visible;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.2700544;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:3.02851319px;line-height:1;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25237608"
|
||||||
|
x="0.90272093"
|
||||||
|
y="9.031786"
|
||||||
|
id="text4162"
|
||||||
|
transform="scale(0.95386243,1.0483692)"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan4160"
|
||||||
|
x="0.90272093"
|
||||||
|
y="9.031786"
|
||||||
|
style="font-size:2.69201183px;line-height:1;stroke-width:0.25237608"> 0,0 </tspan></text>
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:3.02851319px;line-height:1;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25237608"
|
||||||
|
x="11.097216"
|
||||||
|
y="9.0313826"
|
||||||
|
id="text4162-1"
|
||||||
|
transform="scale(0.95386244,1.0483692)"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan4160-2"
|
||||||
|
x="11.097216"
|
||||||
|
y="9.0313826"
|
||||||
|
style="font-size:2.69201183px;line-height:1;stroke-width:0.25237608"> 0,1 </tspan></text>
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:3.02851319px;line-height:1;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25237608"
|
||||||
|
x="0.93034029"
|
||||||
|
y="18.217352"
|
||||||
|
id="text4162-5"
|
||||||
|
transform="scale(0.95386244,1.0483692)"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan4160-1"
|
||||||
|
x="0.93034029"
|
||||||
|
y="18.217352"
|
||||||
|
style="font-size:2.69201183px;line-height:1;stroke-width:0.25237608"> 1,0 </tspan></text>
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:3.02851319px;line-height:1;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25237608"
|
||||||
|
x="21.200579"
|
||||||
|
y="9.0508375"
|
||||||
|
id="text4162-0"
|
||||||
|
transform="scale(0.95386244,1.0483692)"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan4160-5"
|
||||||
|
x="21.200579"
|
||||||
|
y="9.0508375"
|
||||||
|
style="font-size:2.69201183px;line-height:1;stroke-width:0.25237608"> 0,2 </tspan></text>
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:3.02851319px;line-height:1;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25237608"
|
||||||
|
x="11.048577"
|
||||||
|
y="18.167271"
|
||||||
|
id="text4162-4"
|
||||||
|
transform="scale(0.95386244,1.0483692)"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan4160-9"
|
||||||
|
x="11.048577"
|
||||||
|
y="18.167271"
|
||||||
|
style="font-size:2.69201183px;line-height:1;stroke-width:0.25237608"> 1,1 </tspan></text>
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:3.02851319px;line-height:1;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25237608"
|
||||||
|
x="21.25436"
|
||||||
|
y="18.302471"
|
||||||
|
id="text4162-54"
|
||||||
|
transform="scale(0.95386244,1.0483692)"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan4160-8"
|
||||||
|
x="21.25436"
|
||||||
|
y="18.302471"
|
||||||
|
style="font-size:2.69201183px;line-height:1;stroke-width:0.25237608"> 1,2 </tspan></text>
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-style:normal;font-weight:normal;font-size:3.17499995px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
|
||||||
|
x="1.6370258"
|
||||||
|
y="8.5239649"
|
||||||
|
id="text4244"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan4242"
|
||||||
|
x="1.6370258"
|
||||||
|
y="11.333096"
|
||||||
|
style="stroke-width:0.26458332"></tspan></text>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 11 KiB |
@@ -1,182 +0,0 @@
|
|||||||
#+TITLE: Magic Growing
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Magic Wand Tool
|
|
||||||
|
|
||||||
In this task, you will implement the =Magic Wand Tool=, a helpful tool in many image editing softwares (like Photoshop).
|
|
||||||
|
|
||||||
The =Magic Wand Tool= (or MWT) is a selection tool. It allows you to quickly select areas of your images and make independent edits to them. Conceptually, MWT selects all pixels which are /similar/ to a given reference pixel. In this task, a pixel is considered similar to the reference pixel if and only if their intensity is not too different from the reference pixel and they are connected to the reference pixel. We define what we mean by /"not too different"/ and /"connected to the reference pixel"/ more formally later.
|
|
||||||
|
|
||||||
* Images
|
|
||||||
|
|
||||||
Note: For some browsers, the images might not be displayed correctly. Using a Chrome/Chromium-based browser should resolve the issue.
|
|
||||||
|
|
||||||
An image is a 2D array of pixels. Every pixel can be identified by its row index \(i\) and column index \(j\). We assume that row \(0\) is at the top of the image, and column j\(0\) is on the left of the image.
|
|
||||||
|
|
||||||
** Caution!
|
|
||||||
|
|
||||||
Images are commonly stored in a =row-major= format. This means that we store an image as a vector of =rows= and a row as a vector of pixels. When accessing an image, you first get the correct row, then the correct column in that row. For example, if we have an image \(I\) and want to access the pixel at row \(i\) and column \(j\), we would write =I[i][j]=.
|
|
||||||
|
|
||||||
However, pixel coordinates are commonly given as \((x , y)\), where \(x\) refers to the column (or width) and \(y\) to the row (or height). If we want to access the coordinate \((x , y)\) in image \(I\), we would write =I[y][x]= as visualized below.
|
|
||||||
|
|
||||||
[[./pictures/images_explanation.png]]
|
|
||||||
|
|
||||||
This exercise contains three different types of images, which are defined in =bitmap.h= and explained below.
|
|
||||||
|
|
||||||
** RGB Image
|
|
||||||
|
|
||||||
You won't have to deal with this type of image yourself, so feel free to skip this section.
|
|
||||||
|
|
||||||
An RGB image is an image where each pixel consists of three values: \(r\), \(g\), and \(b\). These values indicate how much red, green, and blue light is emitted by the pixel. The three values are in the range \([0, 255]\), giving us \(256^3\) different colors we can represent.
|
|
||||||
|
|
||||||
In this task, an RGB image is stored as an =RGBImage=, which is a type alias for =std::vector<std::vector<std::tuple<int, int, int>>>=. For simplicity, we represent each pixel value using an =int= in the code, and you can assume that our provided images have values in the valid range.
|
|
||||||
|
|
||||||
Note: Since we are using =.bmp= images, the pixels are actually stored in the BGR format.
|
|
||||||
|
|
||||||
** Grayscale Image
|
|
||||||
|
|
||||||
Grayscale images do not contain any color information. Instead, every pixel consists of a single number indicating how bright the pixel is. The values are in the range \([0, 255]\), giving us \(256\) possible brightness values. \(0\) means the pixels emits no light (black), and \(255\) means the pixel emits as much light as possible (white).
|
|
||||||
|
|
||||||
In this task, a grayscale image is stored as a =GrayscaleImage=, which is a type alias for =std::vector<std::vector<int>>=. For simplicity, we represent each pixel value using an =int= in the code, and you can assume that our provided images have values in the valid range.
|
|
||||||
Image Mask
|
|
||||||
|
|
||||||
Image masks are similar to grayscale images, but we represent each pixel with a =bool=. Therefore, pixels can either be /on/ (=true=) or /off/ (=false=).
|
|
||||||
|
|
||||||
In this task, an image mask is stored as an =ImageMask=, which is a type alias for =std::vector<std::vector<bool>>=.
|
|
||||||
|
|
||||||
* Pixel Neighborhood
|
|
||||||
|
|
||||||
A pixel neighborhood defines the set of pixels which are considered neighbors of a given pixel.
|
|
||||||
|
|
||||||
In this exercise, we use the so-called 4-neighborhood, which consists of four pixels, i.e., the pixels to the left, right, top, and bottom of the current pixel. Formally, the 4-neighborhood of a pixel \((x,y)\) is defined as the set of pixels at the coordinates \((x-1,y)\), \((x+1,y)\), \((x,y-1)\), and \((x,y+1)\).
|
|
||||||
|
|
||||||
Of course, the neighborhood only consists of pixels that are part of the image, so a pixel at the left edge of the image does not have a left neighbor.
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
Your task is to implement the function =ImageMask MWT(...)= in =mwt.cpp=. The function takes a grayscale image \(I\), a pixel coordinate \((x,y)\), and a threshold \(T\) as arguments. It returns an image mask \(M\), which indicates for each pixel in the grayscale image whether or not it is similar to the pixel at coordinate \((x,y)\). A pixel \((x',y')\) is considered similar to reference pixel \((x,y)\) if the absolute difference between \(I[(x,y)]\) and \(I[(x,y)\) is at most \(T\) *and* there exists a path of /similar/ pixels from \((x,y)\) to \((x',y')\).
|
|
||||||
|
|
||||||
Formally, \(M[(x',y')]\) is =true= if and only if there exists a sequence of pixels \(P = [p_1, ... , p_n]\) for which the following conditions hold:
|
|
||||||
|
|
||||||
1. \(p_1 = (x,y)\)
|
|
||||||
1. \(p_n = (x',y')\)
|
|
||||||
1. \(p_{i+1}\) is in the 4-neigborhood of \(p_i \forall i \in [1, ... , n-1]\)
|
|
||||||
1. \(|I[p_i] - I[(x',y')]| \leq T \forall i \in [1, ... , n]\)
|
|
||||||
|
|
||||||
** Hints
|
|
||||||
|
|
||||||
- You might need helper functions for the recursive call.
|
|
||||||
- If you pass a *reference* to an image to a function, any changes that function makes to the image will be visible outside of the function.
|
|
||||||
|
|
||||||
* Input
|
|
||||||
|
|
||||||
When the program starts, you are first prompted to select an image. Your options are: /bank/, /field/, /peppers/, and /pigs/.
|
|
||||||
|
|
||||||
Next, you are prompted to enter the \((x,y)\)-coordinate of the reference pixel and the similarity threshold \(T\) as three integers separated by spaces.
|
|
||||||
|
|
||||||
Then, the selected image is loaded, converted to =GrayscaleImage=, and the =ImageMask= indicating similar pixels is computed using the =ImageMask MWT(...)= function.
|
|
||||||
|
|
||||||
Finally, the number of identified similar pixels (including the initial pixel) and the bounding box of the selected area (as \((x_{left}, y_{top}, x_{right}, y_{bottom})\)) are printed to the console.
|
|
||||||
|
|
||||||
Additionally, an image is saved, which visualizes the reference pixel in red, the bounding box in green, and makes non-similar pixels darker, so that the similar pixels can be seen easier. The saved image can be found under the =Files= tab.
|
|
||||||
|
|
||||||
** Example
|
|
||||||
|
|
||||||
#+BEGIN_src shell
|
|
||||||
Select an image: pigs
|
|
||||||
|
|
||||||
Select a pixel (x y) and a threshold (T): 135 360 20
|
|
||||||
|
|
||||||
Number of selected pixels: 712
|
|
||||||
|
|
||||||
Bounding box (97, 328, 153, 375)
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
The example above should result in the following output image:
|
|
||||||
|
|
||||||
[[./pictures/example_pigs_135_360_20.png]]
|
|
||||||
|
|
||||||
** Notes About Program Robustness
|
|
||||||
|
|
||||||
- You don't have to make your code robust against wrongly formatted inputs. This means that you can safely assume that the entered image exists and the coordinates are valid indices of the image.
|
|
||||||
- Large thresholds may produce an excessive number of recursive calls leading to a segmentation fault (=The process exited with code -11=). The current test cases (also the replaced and hidden ones) have relatively small selected regions and should thus not cause segmentation faults for correct implementations.
|
|
||||||
|
|
||||||
* Important: Testing and Grading
|
|
||||||
|
|
||||||
- When grading your solution, we are going to test your submission with two sets of tests: *replaced* and *hidden*, which make up ~70% and ~30% of the total number of points respectively. The *replaced* tests are going to be very similar to the ones that are used by the auto-grader when you click on the “test” button. The *hidden* tests are additional tests that check some tricky corner cases not covered by the typical tests. The *hidden* tests will be used only when grading your final submission after the deadline. The final number of points awarded to your solution is the sum of the points from the *replaced* and *hidden* test cases. As we have not added the hidden test cases yet, the maximum percantage you can achieve before we add them during grading is 71.43%.
|
|
||||||
|
|
||||||
- Please check the autograder output carefully. It is possible to pass test cases, but not get any credits for them. This is the case when your code contains compiler warnings or errors. Note that the message detailing the final score might take some time to appear. For example, with the following output, you would not receive any credits for this bonus exercise even though one test case passes:
|
|
||||||
|
|
||||||
#+BEGIN_src shell
|
|
||||||
Tests result: passed 1 of 10
|
|
||||||
|
|
||||||
[ERROR] Your program had compilation warnings. Please click on the compile button to see them.
|
|
||||||
|
|
||||||
Please fix the errors reported above.
|
|
||||||
|
|
||||||
The final score assigned by automatic checks: 0.00%
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
- We recommend that you print all output that is not part of the output required by us (i.e., additional output that you use for debugging) to =std::cerr= instead of =std::cout=, as additional output might confuse the autograder and lead to hidden or replaced test cases failing.
|
|
||||||
|
|
||||||
- /Hint/: To ensure that your solution passes not only the *replaced* tests but also the *hidden* ones, test it thoroughly with additional examples. When doing so, do not forget to check for edge cases because these are the ones we may focus on in the *hidden* test suite. *Remember!* Passing all tests does not imply that your program is correct: “Program testing can be used to show the presence of bugs, but never to show their absence!” (Edsger W. Dijkstra).
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+BEGIN_src cpp
|
|
||||||
#include "mwt.h"
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
void MWT_rec(int ref, ImageMask &mask, const GrayscaleImage &image, int x,
|
|
||||||
int y, const int T) {
|
|
||||||
int height = image.size();
|
|
||||||
int width = image[0].size();
|
|
||||||
|
|
||||||
if (x < 0 || x > height || y < 0 || y > width)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int new_ref = image[y][x];
|
|
||||||
|
|
||||||
if (std::abs(ref - new_ref) > T) {
|
|
||||||
mask[y][x] = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mask[y][x]) {
|
|
||||||
mask[y][x] = true;
|
|
||||||
MWT_rec(ref, mask, image, x - 1, y, T);
|
|
||||||
MWT_rec(ref, mask, image, x + 1, y, T);
|
|
||||||
MWT_rec(ref, mask, image, x, y - 1, T);
|
|
||||||
MWT_rec(ref, mask, image, x, y + 1, T);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PRE: All rows in image have the same size.
|
|
||||||
// x and y must be valid indices of the image.
|
|
||||||
// POST: Returns a matrix of bools where every true value corresponds to a pixel
|
|
||||||
// with at least one path of T-similar pixels starting at x,y.
|
|
||||||
ImageMask MWT(const GrayscaleImage &image, const int x, const int y,
|
|
||||||
const int T) {
|
|
||||||
// get image dimensions
|
|
||||||
const int height = image.size();
|
|
||||||
assert(height > 0);
|
|
||||||
const int width = image[0].size();
|
|
||||||
assert(y < height && x < width);
|
|
||||||
|
|
||||||
// init mask
|
|
||||||
ImageMask mask(height, ImageMaskRow(width, false));
|
|
||||||
|
|
||||||
int ref = image[y][x];
|
|
||||||
|
|
||||||
MWT_rec(ref, mask, image, x, y, T);
|
|
||||||
|
|
||||||
// return mask
|
|
||||||
return mask;
|
|
||||||
}
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
Before Width: | Height: | Size: 1.8 MiB |
Before Width: | Height: | Size: 1.4 MiB |
@@ -1,15 +0,0 @@
|
|||||||
#+title: Magic Growing
|
|
||||||
|
|
||||||
#+author: JirR02
|
|
||||||
* SIKE!
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: sike
|
|
||||||
:END:
|
|
||||||
[[./pictures/sike.jpg]]
|
|
||||||
|
|
||||||
Spass... ist in einem seperaten Repo
|
|
||||||
[[https://www.youtube.com/watch?v=xvFZjo5PgG0][hier]].
|
|
||||||
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
Before Width: | Height: | Size: 61 KiB |
13
Informatik_I/Examples/Week_1/README.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Task
|
||||||
|
|
||||||
|
Write a program which reads in an integer a larger than `1000` and outputs its last three digits. For example, if `a=14325`, the output should be `3 2 5`.
|
||||||
|
|
||||||
|
_Hint_: You need to use integer division and modulo operators.
|
||||||
|
|
||||||
|
# Input
|
||||||
|
|
||||||
|
An integer larger than `1000`.
|
||||||
|
|
||||||
|
# Output
|
||||||
|
|
||||||
|
Last three digits separated by spaces.
|
22
Informatik_I/Examples/Week_1/main.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
int a;
|
||||||
|
std::cin >> a; // get input of for a
|
||||||
|
|
||||||
|
if (a >= 1000) { // check if input is greater than 1000
|
||||||
|
int b = a % 10; // get last digit
|
||||||
|
a /= 10;
|
||||||
|
int c = a % 10; // get second digit
|
||||||
|
a /= 10;
|
||||||
|
int d = a % 10; // get first digit
|
||||||
|
|
||||||
|
std::cout << d << " " << c << " "
|
||||||
|
<< b; // output first, second, and last digit
|
||||||
|
} else { // if input not greater than 1000 return 0
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
17
Informatik_I/Exercise_1/Task_1/README.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Task
|
||||||
|
|
||||||
|
Let `a`, `b`, `c`, and `d` be variables of type `int`.
|
||||||
|
|
||||||
|
- Which of the following character sequences are valid expressions in the sense that they are accepted by a C++ Compiler? Explain your answer.
|
||||||
|
|
||||||
|
1. a = b = 5
|
||||||
|
1. 1 = a
|
||||||
|
1. ++a + b++
|
||||||
|
1. a + b = c + d
|
||||||
|
1. a = 2 b
|
||||||
|
|
||||||
|
Assume that all the variables have been defined and correctly initialized and that all expressions are completely independent from each other.
|
||||||
|
|
||||||
|
- For each of the expressions that you have identified as valid, decide whether the entire expression is an `lvalue` or an `rvalue`, and explain your decision.
|
||||||
|
|
||||||
|
- Determine the values of the expressions that you have identified as valid and explain how these values are obtained.
|
@@ -1,52 +0,0 @@
|
|||||||
#+TITLE: Task 1: Expressions
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
Let =a=, =b=, =c=, and =d= be variables of type =int=.
|
|
||||||
|
|
||||||
- Which of the following character sequences are valid expressions in the sense that they are accepted by a C++ Compiler? Explain your answer.
|
|
||||||
|
|
||||||
1. a = b = 5
|
|
||||||
1. 1 = a
|
|
||||||
1. ++a + b++
|
|
||||||
1. a + b = c + d
|
|
||||||
1. a = 2 b
|
|
||||||
|
|
||||||
Assume that all the variables have been defined and correctly initialized and that all expressions are completely independent from each other.
|
|
||||||
|
|
||||||
- For each of the expressions that you have identified as valid, decide whether the entire expression is an =lvalue= or an =rvalue=, and explain your decision.
|
|
||||||
|
|
||||||
- Determine the values of the expressions that you have identified as valid and explain how these values are obtained.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src md
|
|
||||||
# Task 1
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Expression 1: `a = b = 5`
|
|
||||||
|
|
||||||
The expression is valid and will be accepted by the CPP compiler. It will result with the l-values `a = 5` and `b = 5`. This is due to the fact the the `=` opperation is read from right to left so `b = 5` will run first and `a = b` afterwards.
|
|
||||||
|
|
||||||
### Expression 2: `1 = a`
|
|
||||||
|
|
||||||
The expression is invalid.
|
|
||||||
|
|
||||||
### Expression 3: `++a + b++`
|
|
||||||
|
|
||||||
The expression is valid and will be accepted by the CPP compiler. It will result in a r-value since the result is not assigned to a variable.
|
|
||||||
|
|
||||||
### Expression 4: `a + b = c + d`
|
|
||||||
|
|
||||||
The expression is invalid.
|
|
||||||
|
|
||||||
### Expression 5: `a = 2 b`
|
|
||||||
|
|
||||||
The expression is valid and will be accepted by the CPP compiler. It will result with the l-value `a = 2 b`. This is valid since a l-value can be a r-value.
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
23
Informatik_I/Exercise_1/Task_1/main.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Task 1
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Expression 1: `a = b = 5`
|
||||||
|
|
||||||
|
The expression is valid and will be accepted by the CPP compiler. It will result with the l-values `a = 5` and `b = 5`. This is due to the fact the the `=` opperation is read from right to left so `b = 5` will run first and `a = b` afterwards.
|
||||||
|
|
||||||
|
### Expression 2: `1 = a`
|
||||||
|
|
||||||
|
The expression is invalid.
|
||||||
|
|
||||||
|
### Expression 3: `++a + b++`
|
||||||
|
|
||||||
|
The expression is valid and will be accepted by the CPP compiler. It will result in a r-value since the result is not assigned to a variable.
|
||||||
|
|
||||||
|
### Expression 4: `a + b = c + d`
|
||||||
|
|
||||||
|
The expression is invalid.
|
||||||
|
|
||||||
|
### Expression 5: `a = 2 b`
|
||||||
|
|
||||||
|
The expression is valid and will be accepted by the CPP compiler. It will result with the l-value `a = 2 b`. This is valid since a l-value can be a r-value.
|
24
Informatik_I/Exercise_1/Task_2/README.md
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Task
|
||||||
|
|
||||||
|
_This task is a text-based task but mostly automatically checked. You are required to write your answers into submission.txt by replacing the question marks with the correct solution. Please, do not change the line formating._
|
||||||
|
|
||||||
|
_You can check whether your solution is correct by clicking on the test button._
|
||||||
|
|
||||||
|
Numbers can be provided in various formats in C++. Literals prefixed with `0b` indicate binary encoding. Assume unsigned arithmetics with sufficient numbers of bits, i.e. no overflows. Convert the following binary numbers into decimal numbers (1-4) and decimal numbers to binary (5-8):
|
||||||
|
|
||||||
|
```txt
|
||||||
|
# Lines starting with # are comments. Spaces is ignored.
|
||||||
|
# Lines starting with a whitespace before # will not be a comment.
|
||||||
|
|
||||||
|
# Convert to decimal:
|
||||||
|
0b1 = ?
|
||||||
|
0b10 = ?
|
||||||
|
0b000001 = ?
|
||||||
|
0b101010 = ?
|
||||||
|
|
||||||
|
# Convert to binary:
|
||||||
|
7 = ?
|
||||||
|
11 = ?
|
||||||
|
28 = ?
|
||||||
|
1024 = ?
|
||||||
|
```
|
@@ -1,50 +0,0 @@
|
|||||||
#+TITLE: Task 2: Representation of Integers
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
/This task is a text-based task but mostly automatically checked. You are required to write your answers into =submission.txt= by replacing the question marks with the correct solution. Please, do not change the line formating./
|
|
||||||
|
|
||||||
/You can check whether your solution is correct by clicking on the test button./
|
|
||||||
|
|
||||||
Numbers can be provided in various formats in C++. Literals prefixed with =0b= indicate binary encoding. Assume unsigned arithmetics with sufficient numbers of bits, i.e. no overflows. Convert the following binary numbers into decimal numbers (1-4) and decimal numbers to binary (5-8):
|
|
||||||
|
|
||||||
#+begin_src txt
|
|
||||||
# Lines starting with # are comments. Spaces is ignored.
|
|
||||||
# Lines starting with a whitespace before # will not be a comment.
|
|
||||||
|
|
||||||
# Convert to decimal:
|
|
||||||
0b1 = ?
|
|
||||||
0b10 = ?
|
|
||||||
0b000001 = ?
|
|
||||||
0b101010 = ?
|
|
||||||
|
|
||||||
# Convert to binary:
|
|
||||||
7 = ?
|
|
||||||
11 = ?
|
|
||||||
28 = ?
|
|
||||||
1024 = ?
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
* Solutions
|
|
||||||
|
|
||||||
#+begin_src txt
|
|
||||||
# Lines starting with # are comments. Spaces are ignored.
|
|
||||||
# Lines starting with a whitespace before # will not be a comment.
|
|
||||||
|
|
||||||
# Convert to decimal:
|
|
||||||
0b1 = 1
|
|
||||||
0b10 = 2
|
|
||||||
0b000001 = 1
|
|
||||||
0b101010 = 42
|
|
||||||
|
|
||||||
# Convert to binary:
|
|
||||||
7 = 0b111
|
|
||||||
11 = 0b1011
|
|
||||||
28 = 0b11100
|
|
||||||
1024 = 0b10000000000
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
—----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
14
Informatik_I/Exercise_1/Task_2/submission.txt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# Lines starting with # are comments. Spaces are ignored.
|
||||||
|
# Lines starting with a whitespace before # will not be a comment.
|
||||||
|
|
||||||
|
# Convert to decimal:
|
||||||
|
0b1 = 1
|
||||||
|
0b10 = 2
|
||||||
|
0b000001 = 1
|
||||||
|
0b101010 = 42
|
||||||
|
|
||||||
|
# Convert to binary:
|
||||||
|
7 = 0b111
|
||||||
|
11 = 0b1011
|
||||||
|
28 = 0b11100
|
||||||
|
1024 = 0b10000000000
|
18
Informatik_I/Exercise_1/Task_3/README.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Task
|
||||||
|
|
||||||
|
Write a program resistance.cpp that computes the equivalent resistance of the following wiring:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
We assume that $R_1$, $R_2$, $R_3$, and $R_4$ have an integer valued resistance. After input of the four values, the program should output the result arithmetically rounded to the nearest integer.
|
||||||
|
|
||||||
|
**Remark:** In order to facilitate the task, you may want to:
|
||||||
|
|
||||||
|
- Conceptually divide the task into sub tasks. For example, start with computation of serial resistors $R_{12}$ and $R_{34}$.
|
||||||
|
- Solve the task first naively using default rounding and then think about how to accomplish arithmetic rounding. Recall that $\text{round}(x) = [x + 0.5] \text{ }\forall \text{ } x \in \mathbb{R}$, i.e., a real number can be rounded arithmetically by adding $0.5$ to it and then rounding down. For example, $\text{round}(8,6) = [8.6 + 0.5] = [9.1] = 9$.
|
||||||
|
|
||||||
|
You can find formulas for computing the total resistance in this [Wikipedia article](https://en.wikipedia.org/wiki/Resistor#Series_and_parallel_resistors).
|
||||||
|
|
||||||
|
**Important:** using anything other than int (e.g., floating point numbers, long, or double long) is forbidden.
|
||||||
|
|
||||||
|
**Important:** using if-else and any other branches is forbidden.
|
@@ -1,55 +0,0 @@
|
|||||||
#+TITLE: Task 3: Equivalent Resistance
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
Write a program resistance.cpp that computes the equivalent resistance of the following wiring:
|
|
||||||
|
|
||||||
[[./resistance.png]]
|
|
||||||
|
|
||||||
We assume that \(R_1\), \(R_2\), \(R_3\), and \(R_4\) have an integer valued resistance. After input of the four values, the program should output the result arithmetically rounded to the nearest integer.
|
|
||||||
|
|
||||||
*Remark:* In order to facilitate the task, you may want to:
|
|
||||||
|
|
||||||
- Conceptually divide the task into sub tasks. For example, start with computation of serial resistors \(R_{12}\) and \(R_{34}\).
|
|
||||||
- Solve the task first naively using default rounding and then think about how to accomplish arithmetic rounding. Recall that \(\text{round}(x) = [x + 0.5] \text{ }\forall \text{ } x \in \mathbb{R}\), i.e., a real number can be rounded arithmetically by adding \(0.5\) to it and then rounding down. For example, \(\text{round}(8,6) = [8.6 + 0.5] = [9.1] = 9\).
|
|
||||||
|
|
||||||
You can find formulas for computing the total resistance in this [[https://en.wikipedia.org/wiki/Resistor#Series_and_parallel_resistors][Wikipedia article]].
|
|
||||||
|
|
||||||
*Important:* using anything other than =int= (e.g., floating point numbers, =long=, or =double long=) is forbidden.
|
|
||||||
|
|
||||||
*Important:* using =if-else= and any other branches is forbidden.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
int r1;
|
|
||||||
int r2;
|
|
||||||
int r3;
|
|
||||||
int r4;
|
|
||||||
int res;
|
|
||||||
|
|
||||||
std::cin >> r1;
|
|
||||||
std::cin >> r2;
|
|
||||||
std::cin >> r3;
|
|
||||||
std::cin >> r4;
|
|
||||||
|
|
||||||
int r12 = r1 + r2;
|
|
||||||
int r34 = r3 + r4;
|
|
||||||
|
|
||||||
res = (r12 * r34 + ((r12 + r34) / 2)) /
|
|
||||||
(r12 + r34); // By adding the average of r12 and r34, the result is
|
|
||||||
// increased enough to get the correct rounded number
|
|
||||||
|
|
||||||
std::cout << res;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-—---
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
25
Informatik_I/Exercise_1/Task_3/resistance.cpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int r1;
|
||||||
|
int r2;
|
||||||
|
int r3;
|
||||||
|
int r4;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
std::cin >> r1;
|
||||||
|
std::cin >> r2;
|
||||||
|
std::cin >> r3;
|
||||||
|
std::cin >> r4;
|
||||||
|
|
||||||
|
int r12 = r1 + r2;
|
||||||
|
int r34 = r3 + r4;
|
||||||
|
|
||||||
|
res = (r12 * r34 + ((r12 + r34) / 2)) /
|
||||||
|
(r12 + r34); // By adding the average of r12 and r34, the result is
|
||||||
|
// increased enough to get the correct rounded number
|
||||||
|
|
||||||
|
std::cout << res;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@@ -1,50 +0,0 @@
|
|||||||
#+title: Task 1a: Understanding Pointers: - Lookup
|
|
||||||
|
|
||||||
#+author: JirR02
|
|
||||||
* Task Description
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: task-description
|
|
||||||
:END:
|
|
||||||
Complete the definition of function lookup by editing the file
|
|
||||||
=lookup.cpp= according to its specified pre- and post conditions.
|
|
||||||
|
|
||||||
We provide a test program using the implemented function to perform
|
|
||||||
lookup on a vector.
|
|
||||||
|
|
||||||
** Input
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: input
|
|
||||||
:END:
|
|
||||||
The program accepts
|
|
||||||
|
|
||||||
- the length of the vector, =l=,
|
|
||||||
- =l= vector elements, and
|
|
||||||
- a lookup index =i=.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
means a 3-element vector =[9, 8, 7]= and the lookup index 1.
|
|
||||||
|
|
||||||
** Output
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: output
|
|
||||||
:END:
|
|
||||||
The test program prints the value of the element at the lookup index.
|
|
||||||
|
|
||||||
For example, for the input given above, this value is 8.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: solution
|
|
||||||
:END:
|
|
||||||
#+begin_src cpp
|
|
||||||
#include "lookup.h"
|
|
||||||
|
|
||||||
// PRE: 0 <= i < vec.size()
|
|
||||||
// POST: Returns the address of the i-th element of vec.
|
|
||||||
const int *lookup(const std::vector<int> &vec, const int i) { return &vec[i]; }
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
@@ -1,49 +0,0 @@
|
|||||||
#+title: Task 1b: Understanding Pointers - Add
|
|
||||||
|
|
||||||
#+author: JirR02
|
|
||||||
* Task Description
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: task-description
|
|
||||||
:END:
|
|
||||||
Complete the definition of function add by editing the file =add.cpp=
|
|
||||||
according to its specified pre- and post conditions.
|
|
||||||
|
|
||||||
We provide a test program using the implemented function to add two
|
|
||||||
values given by the user.
|
|
||||||
|
|
||||||
** Input
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: input
|
|
||||||
:END:
|
|
||||||
Integers a, b.
|
|
||||||
|
|
||||||
For example
|
|
||||||
|
|
||||||
#+begin_src shell
|
|
||||||
21 35
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
** Output
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: output
|
|
||||||
:END:
|
|
||||||
The test program prints the sum of a and b.
|
|
||||||
|
|
||||||
For example, for the input given above this value is 56.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: solution
|
|
||||||
:END:
|
|
||||||
#+begin_src cpp
|
|
||||||
#include "add.h"
|
|
||||||
|
|
||||||
// PRE: a, b, and res are valid pointers to integer values.
|
|
||||||
// POST: integer at location res contains the result of adding the integer at
|
|
||||||
// location a and the integer at location b.
|
|
||||||
void add(int *res, const int *a, const int *b) { *res = *a + *b; }
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
@@ -1,73 +0,0 @@
|
|||||||
#+title: Task 2: [Exam 2022.08 (ITET/MATH/PHYS/RW)] max difference
|
|
||||||
|
|
||||||
#+author: JirR02
|
|
||||||
* Task Description
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: task-description
|
|
||||||
:END:
|
|
||||||
Given the iterators to a vector composed of integers between 0 and
|
|
||||||
2147483647 (included), return the highest absolute difference between
|
|
||||||
two neighbouring elements. You can assume that the given range always
|
|
||||||
includes at least two elements.
|
|
||||||
|
|
||||||
Note: The vector is propagated with values that are provided at the
|
|
||||||
beginning of the execution. The input accepts a sequence of numbers
|
|
||||||
terminated with -1.
|
|
||||||
|
|
||||||
** Function
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: function
|
|
||||||
:END:
|
|
||||||
Implement the function largest_difference in functions.h according to
|
|
||||||
its pre- and postconditions.
|
|
||||||
|
|
||||||
*Rules*:
|
|
||||||
|
|
||||||
- The functions must satisfy their respective postconditions.
|
|
||||||
- You are not allowed to change the function signatures.
|
|
||||||
- You are not allowed to use additional libraries.
|
|
||||||
|
|
||||||
*Hints*:
|
|
||||||
|
|
||||||
- You do not need to check the pre- and postconditions (no asserts
|
|
||||||
necessary).
|
|
||||||
- The program must compile in order for the autograder to work.
|
|
||||||
- We recommend *strongly* to submit partial solutions as soon they are
|
|
||||||
successful.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: solution
|
|
||||||
:END:
|
|
||||||
#+begin_src cpp
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
using iterator = std::vector<int>::const_iterator;
|
|
||||||
|
|
||||||
// PRE: iterator pair [begin,end) specifies a valid range
|
|
||||||
// within a vector (begin is included, end is not) containing numbers
|
|
||||||
// in [0, 2147483647]. The range in the vector comprises at least two
|
|
||||||
// elements.
|
|
||||||
// POST: returns the largest absolute difference between two neighbouring
|
|
||||||
// numbers in the vector.
|
|
||||||
//
|
|
||||||
// Example:
|
|
||||||
// * [1, 5, 2, 5, 7, 6] ~~> 4
|
|
||||||
// * [2, 9, 1] ~~> 8
|
|
||||||
int largest_difference(iterator begin, iterator end) {
|
|
||||||
int max_dif = 0;
|
|
||||||
end = --end;
|
|
||||||
while (begin != end) {
|
|
||||||
int val1 = *begin;
|
|
||||||
int val2 = *++begin;
|
|
||||||
if (std::abs(val2 - val1) > max_dif)
|
|
||||||
max_dif = std::abs(val2 - val1);
|
|
||||||
}
|
|
||||||
return max_dif;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
@@ -1,189 +0,0 @@
|
|||||||
#+title: Task 3: Dynamic Queue
|
|
||||||
|
|
||||||
#+author: JirR02
|
|
||||||
* Task 3: Dynamic Queue
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: task-3-dynamic-queue
|
|
||||||
:END:
|
|
||||||
Your objective is to implement your own queue class with integer values
|
|
||||||
as a dynamic data structure.
|
|
||||||
|
|
||||||
A queue provides the two basic operations: enqueue and dequeue. The
|
|
||||||
operation enqueue adds a new element to the back of the queue. The
|
|
||||||
operation dequeue removes the first element from the queue:
|
|
||||||
|
|
||||||
[[./queue_example.png]]
|
|
||||||
|
|
||||||
A common way to implement a queue is using a linked list, as the one
|
|
||||||
that was shown in the lecture. In order to be able to both enqueue and
|
|
||||||
dequeue, we need to access respectively the first and last elements of
|
|
||||||
the list.
|
|
||||||
|
|
||||||
*Procedure*: The queue declaration is already provided. Your task is to
|
|
||||||
fill the missing definitions for the required functions, marked by
|
|
||||||
comments =// TODO= in =queue.cpp=. Function annotations (pre- and
|
|
||||||
postconditions), found along declarations in the header =queue.h=,
|
|
||||||
explain what each function is supposed to do. You may (and probably will
|
|
||||||
have to) add auxiliary non-member functions in =queue.cpp= in order to
|
|
||||||
implement some of the functions.
|
|
||||||
|
|
||||||
A class invariant helps to detect implementation problems early. For
|
|
||||||
this queue, we have the following class invariant: Either both pointers
|
|
||||||
=first= and =last= are set to =nullptr= or both are not set to
|
|
||||||
=nullptr=. The invariant is checked after every operation. If the
|
|
||||||
invariant is not satisfied, the program exits.
|
|
||||||
|
|
||||||
Subtasks:
|
|
||||||
|
|
||||||
1. Implement the default constructor of class Queue.
|
|
||||||
|
|
||||||
2. Implement the queue operations: member functions enqueue, dequeue and
|
|
||||||
=is_empty=.
|
|
||||||
|
|
||||||
3. Implement the member function =print_reverse= to print the content of
|
|
||||||
a queue to =std::cout= in reverse order. To output the queue content
|
|
||||||
(output operator), use the following format: bracket open ([) , zero
|
|
||||||
or more integer numbers separated by spaces, bracket close (]). E.g.,
|
|
||||||
the empty queue must be output like this: =[]=, the queue containing
|
|
||||||
elements =13, 7, and 42= (from first to last): =[42 7 13]=.
|
|
||||||
|
|
||||||
The function =print_reverse= must be implemented through an auxiliary
|
|
||||||
function traversing the queue recursively, from a Node pointer given as
|
|
||||||
argument. In particular, the implementation of =print_reverse= *must
|
|
||||||
not* use loop structures. We provide implementation of function =print=
|
|
||||||
printing the content of a queue in regular order as a reference.
|
|
||||||
|
|
||||||
/Optional/: Think of ways to implement =print= and =print_reverse= with
|
|
||||||
loops instead of recursion (do not change your submission). In
|
|
||||||
particular, try to find a way to implement =print_reverse= that does not
|
|
||||||
make use of unbounded auxiliary storage.
|
|
||||||
|
|
||||||
** Input & Output
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: input-output
|
|
||||||
:END:
|
|
||||||
The =main= function of the program initially creates an empty queue and
|
|
||||||
enters an endless loop where the following operations can be executed:
|
|
||||||
|
|
||||||
- enqueue x: adds x to the end of the queue
|
|
||||||
- dequeue: removes the first element from the queue and prints it to the
|
|
||||||
console.
|
|
||||||
- is_empty: prints 1 to the console if the queue is empty, otherwise 0.
|
|
||||||
- print: prints the queue (in regular order) to the console.
|
|
||||||
- print_reverse: prints the queue in reverse order to the console.
|
|
||||||
- end: quits the program
|
|
||||||
|
|
||||||
*Example*:
|
|
||||||
|
|
||||||
#+begin_src shell
|
|
||||||
is_empty
|
|
||||||
1
|
|
||||||
enqueue 5
|
|
||||||
enqueue 7
|
|
||||||
print
|
|
||||||
[5 7]
|
|
||||||
print_reverse
|
|
||||||
[7 5]
|
|
||||||
is_empty
|
|
||||||
0
|
|
||||||
dequeue
|
|
||||||
5
|
|
||||||
dequeue
|
|
||||||
7
|
|
||||||
is_empty
|
|
||||||
1
|
|
||||||
end
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
*Note*: Invariant checking is already done outside the class, so there
|
|
||||||
is no need to invoke the check_invariant() method in your code.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: solution
|
|
||||||
:END:
|
|
||||||
#+begin_src cpp
|
|
||||||
#include "queue.h"
|
|
||||||
#include <cassert>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// IMPLEMENTATION
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
Queue::Queue() /*TODO*/ {
|
|
||||||
first = nullptr;
|
|
||||||
last = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Queue::enqueue(int value) {
|
|
||||||
Node *enqVal = new Node(value, nullptr);
|
|
||||||
if (first == nullptr) {
|
|
||||||
first = enqVal;
|
|
||||||
last = enqVal;
|
|
||||||
} else {
|
|
||||||
last->next = enqVal;
|
|
||||||
last = enqVal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int Queue::dequeue() {
|
|
||||||
const int n = first->value;
|
|
||||||
first = first->next;
|
|
||||||
if (is_empty()) {
|
|
||||||
last = nullptr;
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Queue::is_empty() const {
|
|
||||||
if (first == nullptr)
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void rec_print_reverse(Node *refLast, Node *last, Queue &revQueue) {
|
|
||||||
if (refLast == last) {
|
|
||||||
revQueue.enqueue(refLast->value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
rec_print_reverse(refLast->next, last, revQueue);
|
|
||||||
revQueue.enqueue(refLast->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Queue::print_reverse() const {
|
|
||||||
Queue revQueue;
|
|
||||||
if (first == nullptr)
|
|
||||||
revQueue.print();
|
|
||||||
else {
|
|
||||||
Node *refLast = first;
|
|
||||||
|
|
||||||
rec_print_reverse(refLast, last, revQueue);
|
|
||||||
revQueue.print();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PRE: -
|
|
||||||
// POST: print the sequence of integers in nodes reachable from n,
|
|
||||||
// in order, with one space before each integer.
|
|
||||||
void print_node(Node *n) {
|
|
||||||
if (n != nullptr) {
|
|
||||||
std::cout << " " << n->value;
|
|
||||||
print_node(n->next);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Queue::print() const {
|
|
||||||
std::cout << "[";
|
|
||||||
if (first != nullptr) {
|
|
||||||
std::cout << first->value;
|
|
||||||
print_node(first->next);
|
|
||||||
}
|
|
||||||
std::cout << "]";
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
Before Width: | Height: | Size: 7.3 KiB |
@@ -1,128 +0,0 @@
|
|||||||
#+title: Task 4: Decomposing a Set into Intervals
|
|
||||||
|
|
||||||
#+author: JirR02
|
|
||||||
* Task
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: task
|
|
||||||
:END:
|
|
||||||
Any finite set of integers can be uniquely decomposed as a union of
|
|
||||||
disjoint maximal integer intervals, e.g as the union of non-overlapping
|
|
||||||
intervals which are as large as possible. For example, the set
|
|
||||||
\(X = \{ 1,2,3,5,6,8 \}\) decomposes as
|
|
||||||
\(X = [1,3] cup [5,6] cup [8,8]\). Note that
|
|
||||||
\(X = [1,2] cup [3,3] cup [5,6] cup [8,8]\) or
|
|
||||||
\(X = [1,2] cup [5,6] cup [5,6] cup [8,9]\) are not valid
|
|
||||||
decompositions, as \([1,2]\) and \([3,3]\) are not maximal interval
|
|
||||||
subsets of , and intervals may not repeat.
|
|
||||||
|
|
||||||
Write a program that inputs a set of integers, as the (possibly
|
|
||||||
repeating) sequence of its members, and outputs the interval
|
|
||||||
decomposition of the set in ascending order of boundaries.
|
|
||||||
|
|
||||||
/Reminder/: ordered sets can be represented in C++ using the
|
|
||||||
=std::set<...>= container, in which elements are added using the
|
|
||||||
=insert= method. Iteration (using iterators) in ordered sets takes place
|
|
||||||
in increasing order.
|
|
||||||
|
|
||||||
=Hint=: You may first define a function that, from two =std::set=
|
|
||||||
iterators =first= and =last=, finds the largest integer interval
|
|
||||||
starting from =first= and ending before =last=, and returns an iterator
|
|
||||||
just after this interval.
|
|
||||||
|
|
||||||
* Input
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: input
|
|
||||||
:END:
|
|
||||||
A set of non-negative integer, given as the sequence of its members
|
|
||||||
followed by a negative integer. The sequence can be in any order and may
|
|
||||||
feature repetitions.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
#+begin_src shell
|
|
||||||
3 5 8 6 5 3 2 1 -1
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
* Output
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: output
|
|
||||||
:END:
|
|
||||||
The interval decomposition of the input set, with interval given in
|
|
||||||
increasing order of boundaries. The interval decomposition must be given
|
|
||||||
as a parenthesized sequence of intervals, with intervals separated by
|
|
||||||
the character U. Intervals themselves must be given by their lower and
|
|
||||||
upper bound, separated by a comma and parenthesized by brackets, with
|
|
||||||
the lower bound coming first.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
#+begin_src shell
|
|
||||||
([1,3]U[5,6]U[8,8])
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: solution
|
|
||||||
:END:
|
|
||||||
#+begin_src cpp
|
|
||||||
#include <iostream>
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
void find_interval(set<int>::iterator &first, set<int>::iterator &last,
|
|
||||||
set<pair<int, int>> &Interval) {
|
|
||||||
if (first == last)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int firstElement = *first;
|
|
||||||
int curElement = *first;
|
|
||||||
|
|
||||||
while ((++first != last) && (*first - curElement <= 1)) {
|
|
||||||
curElement = *first;
|
|
||||||
}
|
|
||||||
|
|
||||||
pair<int, int> curInterval = {firstElement, curElement};
|
|
||||||
Interval.insert(curInterval);
|
|
||||||
|
|
||||||
find_interval(first, last, Interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
int in;
|
|
||||||
set<int> Set;
|
|
||||||
set<pair<int, int>> Interval;
|
|
||||||
|
|
||||||
cin >> in;
|
|
||||||
|
|
||||||
while (in >= 0) {
|
|
||||||
Set.insert(in);
|
|
||||||
cin >> in;
|
|
||||||
}
|
|
||||||
|
|
||||||
set<int>::iterator first = Set.begin();
|
|
||||||
set<int>::iterator last = Set.end();
|
|
||||||
|
|
||||||
find_interval(first, last, Interval);
|
|
||||||
|
|
||||||
int size = Interval.size();
|
|
||||||
int count = 1;
|
|
||||||
|
|
||||||
cout << "(";
|
|
||||||
for (pair<int, int> h : Interval) {
|
|
||||||
cout << "[" << h.first << "," << h.second;
|
|
||||||
if (count < size)
|
|
||||||
cout << "]" << "U";
|
|
||||||
else
|
|
||||||
cout << "]";
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
cout << ")";
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
@@ -1,175 +0,0 @@
|
|||||||
#+title: [Exam 2022.01 (MATH/PHYS/RW)] Circular Linked List
|
|
||||||
#+author: JirR02
|
|
||||||
|
|
||||||
* Circular Linked List
|
|
||||||
|
|
||||||
A circular linked list is a variation of a linked list in which the last node points to the first node, completing a full circle of nodes. In other words, this variation of the linked list doesn't have a null element at the end.
|
|
||||||
|
|
||||||
Take a brief look at the file Node.hpp.
|
|
||||||
|
|
||||||
A Node contains a pointer to the next Node, as well as a value, which is the data stored in the node:
|
|
||||||
|
|
||||||
#+BEGIN_src cpp
|
|
||||||
struct Node {
|
|
||||||
int value;
|
|
||||||
Node* next;
|
|
||||||
}
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
In our implementation, each Node stores a value of type int. Moreover, we reserve the value 0 to indicate the sentinel Node (see below).
|
|
||||||
|
|
||||||
Now open the the file =CircularLinkedList.hpp=.
|
|
||||||
|
|
||||||
A =CircularLinkedList= contains a single public member variable =Node* sentinel=. The sentinel node is only there to facilitate the implementation. It is the only node in the list when the list is empty, and it can be identified as being the only node where ~value = 0~.
|
|
||||||
|
|
||||||
[[./pictures/1_1.png]]
|
|
||||||
|
|
||||||
Notice that, in an empty list, the next pointer of the sentinel node points to the sentinel itself.
|
|
||||||
|
|
||||||
A list containing a single value 1 looks like in the following image: the sentinel's next points to the first node of the list, and that node points to the sentinel in a circular fashion.
|
|
||||||
|
|
||||||
[[./pictures/one_value.png]]
|
|
||||||
|
|
||||||
New values can be inserted in the list either at the beginning or at the end. A node inserted at the beginning comes immediately after the sentinel, while a node inserted at the end comes immediately before the sentinel.
|
|
||||||
|
|
||||||
** Your Task
|
|
||||||
|
|
||||||
Your task is to implement the following functions in file =tasks.hpp=:
|
|
||||||
|
|
||||||
1. =void CircularLinkedList::insertAtBegin(int value)=: given a strictly positive value, inserts the value in a node at the beginning of the list;
|
|
||||||
1. =void CircularLinkedList::insertAtEnd(int value)=: given a strictly positive value, inserts the value in a node at the end of the list; hint: a sentinel can become a normal node (and vice versa);
|
|
||||||
1. =void CircularLinkedList::removeValues(int value)=: removes all the nodes containing the provided value; leaves the list in the same state if no node with the provided value is present.
|
|
||||||
1. =CircularLinkedList::~CircularLinkedList()=: deconstructs the whole list, which includes deallocating all its nodes and the sentinel
|
|
||||||
|
|
||||||
** Input Format
|
|
||||||
|
|
||||||
Various commands can be entered to test your implementation; each consists of a command followed by appropriate arguments:
|
|
||||||
|
|
||||||
- =ib V= : add value V at the beginning
|
|
||||||
|
|
||||||
- =ie V= : add value V at the end
|
|
||||||
|
|
||||||
- =r V= : removes all nodes with value V
|
|
||||||
|
|
||||||
- =s= : show the current status of the list
|
|
||||||
|
|
||||||
- =exit= : exits the program without checking for the correct deallocation of all the nodes
|
|
||||||
|
|
||||||
- =exitSafe= : exits the program checking the correct deallocation of all the nodes
|
|
||||||
|
|
||||||
*** Sample Interactions
|
|
||||||
|
|
||||||
#+BEGIN_QUOTE
|
|
||||||
Copy & Paste: in the ETH exam room use CTRL+SHIFT+C to copy and CTRL+SHIFT+V to paste into the console.
|
|
||||||
#+END_QUOTE
|
|
||||||
|
|
||||||
**** Creating and showing a simple list with two values
|
|
||||||
|
|
||||||
Input:
|
|
||||||
|
|
||||||
#+BEGIN_src shell
|
|
||||||
ib 1
|
|
||||||
ib 2
|
|
||||||
s
|
|
||||||
exit
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
#+BEGIN_src shell
|
|
||||||
List=[(2)=>(1)]
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
**** Inserting two elements and removing one
|
|
||||||
|
|
||||||
Input:
|
|
||||||
|
|
||||||
#+BEGIN_src shell
|
|
||||||
ib 1
|
|
||||||
ie 2
|
|
||||||
s
|
|
||||||
r 1
|
|
||||||
s
|
|
||||||
exit
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
#+BEGIN_src shell
|
|
||||||
List=[(1)=>(2)]
|
|
||||||
List=[(2)]
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+BEGIN_src cpp
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CircularLinkedList.hpp"
|
|
||||||
#include "Node.hpp"
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
// PRE: value > 0
|
|
||||||
// POST: insert a new Node containing the value at the beginning of the list
|
|
||||||
void CircularLinkedList::insertAtBegin(int value) {
|
|
||||||
assert(value > 0);
|
|
||||||
|
|
||||||
Node *ram = new Node(value);
|
|
||||||
ram->next = sentinel->next;
|
|
||||||
sentinel->next = ram;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PRE: value > 0
|
|
||||||
// POST: insert a new Node containing the value at the end of the list
|
|
||||||
void CircularLinkedList::insertAtEnd(int value) {
|
|
||||||
assert(value > 0);
|
|
||||||
|
|
||||||
Node *last = sentinel->next;
|
|
||||||
|
|
||||||
while (last->next != sentinel)
|
|
||||||
last = last->next;
|
|
||||||
|
|
||||||
Node *ram = new Node(value);
|
|
||||||
last->next = ram;
|
|
||||||
ram->next = sentinel;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PRE: value > 0
|
|
||||||
// POST: removes *all* the nodes with the provided value from the list
|
|
||||||
// and deallocates the memory of the deleted nodes.
|
|
||||||
void CircularLinkedList::removeValues(int value) {
|
|
||||||
assert(value > 0);
|
|
||||||
|
|
||||||
Node *cur = sentinel;
|
|
||||||
Node *ram = cur->next;
|
|
||||||
|
|
||||||
while (ram != sentinel) {
|
|
||||||
if (ram->value == value) {
|
|
||||||
cur->next = ram->next;
|
|
||||||
delete ram;
|
|
||||||
ram = cur->next;
|
|
||||||
} else {
|
|
||||||
cur = ram;
|
|
||||||
ram = cur->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST: Deconstructs the whole list, which includes deallocating
|
|
||||||
// all its nodes and the sentinel
|
|
||||||
CircularLinkedList::~CircularLinkedList() {
|
|
||||||
Node *cur = sentinel;
|
|
||||||
Node *ram = cur->next;
|
|
||||||
|
|
||||||
while (ram != sentinel) {
|
|
||||||
cur->next = ram->next;
|
|
||||||
delete ram;
|
|
||||||
ram = cur->next;
|
|
||||||
}
|
|
||||||
delete ram;
|
|
||||||
}
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 9.8 KiB |
Before Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 22 KiB |
@@ -1,152 +0,0 @@
|
|||||||
#+TITLE: Smart Pointers
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
The objective of this problem is to implement a reference-count smart pointer, with functionality similar to that of a std::shared_ptr. Smart pointers implement the same functionality as regular pointers, but additionally they automatically take care of deallocating the object they point to when it is no longer needed. Reference-count smart pointers achieve this by allocating and maintaining a counter in memory together with the actual pointed-to object, which represents the number of smart pointers currently referencing the object. Any time a new smart pointer to an object is created or one is destroyed, this counter has to be incremented or decremented, respectively. When the last smart pointer to an object is destroyed, the counter will be decremented to
|
|
||||||
|
|
||||||
and the smart pointer will know that the object is no longer referenced; it can then deallocate the object.
|
|
||||||
|
|
||||||
The following example illustrates the process:
|
|
||||||
|
|
||||||
#+BEGIN_src cpp
|
|
||||||
Smart a, b, c;
|
|
||||||
a = Smart(new tracked());
|
|
||||||
// The smart pointer 'a' now points to the new
|
|
||||||
// tracked object with a reference count of 1.
|
|
||||||
c = Smart(new tracked());
|
|
||||||
// Another smart pointer 'c' now points to the
|
|
||||||
// second new tracked object with count 1.
|
|
||||||
b = a;
|
|
||||||
// 'a' and 'b' now both point to the first object,
|
|
||||||
// their shared counter is incremented to 2.
|
|
||||||
c = Smart();
|
|
||||||
// A null smart pointer is assigned to 'c'; the
|
|
||||||
// smart pointer previously stored in 'c' is destroyed
|
|
||||||
// and its counter is decremented. Since the count
|
|
||||||
// is now zero, the second tracked object is deallocated.
|
|
||||||
return;
|
|
||||||
// At the end of the function, the smart
|
|
||||||
// pointers 'a' and 'b' are both destroyed, their
|
|
||||||
// counter is decremented twice, and the first
|
|
||||||
// tracked object is deallocated.
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
|
|
||||||
*Locations*: The declarations of the smart pointer class (Smart) and member functions is provided in file =smart.h=. The implementation of member functions should be done in file =smart.cpp=. Smart pointers encapsulate pointers to objects of class tracked, which is declared in file =smart.h=.
|
|
||||||
|
|
||||||
*Structure*: In class Smart, member variable =ptr= represents the pointer (potentially shared by several object of class Smart) to the underlying pointed-to object. Member variable =count= represents the (shared) location containing the number of objects of class Smart currently holding the pointed-to object. Alternatively, both pointers may be =nullptr=, which corresponds to the notion of a /null/ smart pointer. A null smart pointer does not manage any memory.
|
|
||||||
|
|
||||||
Objects pointed by smart pointers belong to class tracked, which is a linked list node where the next pointer is represented using a smart pointer. In particular, tests will use this structure to build linked lists with shared nodes, and check at the end that everything was correctly deallocated. To that end, every object of class tracked is tracked behind the scenes.
|
|
||||||
|
|
||||||
Steps:
|
|
||||||
|
|
||||||
1. Implement the default constructor for class =Smart=. The default constructor should create a null smart pointer.
|
|
||||||
|
|
||||||
1. Implement the constructor =Smart(tracked* t)=. If =t==nullptr=, this should return a null smart pointer, otherwise, this should create a smart pointer to =t= with a reference count of \(1\). You may assume that =t= points to memory newly allocated by =new= that is not already being managed by another smart pointer.
|
|
||||||
|
|
||||||
1. Implement the copy constructor =Smart(const Smart& src)= that returns a new smart pointer to the memory pointed to by =src= and increments the shared reference counter.
|
|
||||||
|
|
||||||
1. Implement the destructor =~Smart()=. For non-null pointers, it should decrement the reference counter and deallocate the pointed-to object if the resulting count is zero.
|
|
||||||
|
|
||||||
1. Implement the assignment operator =Smart& operator=(const Smart& src)= that creates a copy of the provided smart pointer (incrementing its reference counter) and decrements the counter of the smart pointer of the left hand side of the assignment (and potentially deallocates the memory it points to).
|
|
||||||
|
|
||||||
*Optional*: Figure out the situations in which smart pointers are not suitable for memory management, in the sense that they may lead to memory leaks. You may look at the tests which leak memory for inspiration.
|
|
||||||
|
|
||||||
*Note*: In order to *debug*, you may execute code that you place in the function =your_own_tests= located in the =smart.cpp= file. The main function has a =switch= statement that chooses between a series of functions for different test scenarios. This =switch= defaults to =your_own_tests=. So if you enter =-1= for =test_id=, =your_own_tests= will be executed.
|
|
||||||
|
|
||||||
* Solutions
|
|
||||||
|
|
||||||
#+BEGIN_src cpp
|
|
||||||
#include "smart.h"
|
|
||||||
#include "tracker.h"
|
|
||||||
|
|
||||||
Smart::Smart() {
|
|
||||||
count = nullptr;
|
|
||||||
ptr = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Smart::Smart(tracked *t) /* TODO */ {
|
|
||||||
if (t == nullptr) {
|
|
||||||
count = nullptr;
|
|
||||||
ptr = nullptr;
|
|
||||||
} else {
|
|
||||||
ptr = t;
|
|
||||||
int *counter = new int;
|
|
||||||
*counter = 1;
|
|
||||||
count = counter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Smart::Smart(const Smart &src) /* TODO */ {
|
|
||||||
count = src.count;
|
|
||||||
ptr = src.ptr;
|
|
||||||
if (count != nullptr)
|
|
||||||
(*count)++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Smart::~Smart() {
|
|
||||||
if (count != nullptr) {
|
|
||||||
(*count)--;
|
|
||||||
if (*count == 0) {
|
|
||||||
delete count;
|
|
||||||
delete ptr;
|
|
||||||
count = nullptr;
|
|
||||||
ptr = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Smart &Smart::operator=(const Smart &src) {
|
|
||||||
if (src == *this)
|
|
||||||
return *this;
|
|
||||||
|
|
||||||
if (count != nullptr) {
|
|
||||||
(*count)--;
|
|
||||||
if (*count == 0) {
|
|
||||||
delete count;
|
|
||||||
delete ptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
count = src.count;
|
|
||||||
ptr = src.ptr;
|
|
||||||
|
|
||||||
if (count != nullptr)
|
|
||||||
(*count)++;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
tracked &Smart::operator*() { return *ptr; }
|
|
||||||
|
|
||||||
const tracked &Smart::operator*() const { return *ptr; }
|
|
||||||
|
|
||||||
tracked *Smart::operator->() { return ptr; }
|
|
||||||
|
|
||||||
const tracked *Smart::operator->() const { return ptr; }
|
|
||||||
|
|
||||||
bool Smart::operator==(const Smart &cmp) const { return (ptr == cmp.ptr); }
|
|
||||||
|
|
||||||
bool Smart::operator!=(const Smart &cmp) const { return !(*this == cmp); }
|
|
||||||
|
|
||||||
int Smart::get_count() const {
|
|
||||||
if (this->count == nullptr)
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return *(this->count);
|
|
||||||
}
|
|
||||||
|
|
||||||
void your_own_tests() {
|
|
||||||
// EXTRA TESTS ?
|
|
||||||
}
|
|
||||||
|
|
||||||
// Answer to optional question
|
|
||||||
/*
|
|
||||||
FILL IN WITH YOUR ANSWER
|
|
||||||
*/
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
@@ -1,98 +0,0 @@
|
|||||||
#+TITLE: [Hidden tests][Exam 2019.02 RW] Sorted List
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Sorted Linked List
|
|
||||||
|
|
||||||
In this task you complete the functions =add= and =remove= of a singly linked sorted (in ascending order) list.
|
|
||||||
|
|
||||||
One invariant of the sorted linked list is the following: for subsequent nodes =n= and =next= it holds \(n.value \leq next.value \).
|
|
||||||
|
|
||||||
[[./pictures/SortedLinkedList.png]]
|
|
||||||
|
|
||||||
*** Chosen memory management
|
|
||||||
|
|
||||||
We do not want to deal with the memory management by ourselves. Therefore we use =std::shared_ptr= instead of normal pointers. Behind the scenes, shared pointers contain a counter that counts the number of references to the pointer. As soon as this counter reaches the value zero, the object behind the pointer is removed, i.e. =delete= is called automatically.
|
|
||||||
|
|
||||||
Otherwise, a shared pointer has nearly the same functionality as a normal pointer. For this exercise:
|
|
||||||
|
|
||||||
- Where we previously used the pointer type node*, we now use =std::shared_ptr<node>=
|
|
||||||
- Members of a shared pointer are accessed like on a normal pointer: using the =->= operator.
|
|
||||||
- Assignments and comparisons work in the same way as for normal pointers.
|
|
||||||
- Only allocation, like new node(=value=), is replaced by =std::make_shared<node>(value)=.
|
|
||||||
- Calls to delete can be omitted completely. Shared pointers call delete automatically when required.
|
|
||||||
|
|
||||||
Consider for example the finished implementation of the =print= function and the already implemented part of the add function.
|
|
||||||
|
|
||||||
** Tasks
|
|
||||||
|
|
||||||
1. Complete the function =void sorted_list::add(int value)= such that a new node with the provided value is inserted into the linked list. The list needs to remain sorted in ascending order. Several nodes with the same value may be contained. The order of the nodes with same value is unimportant.
|
|
||||||
|
|
||||||
1. Complete the function bool =sorted_list::remove(int value)= such that a node with the given value is removed from the list. If no node with this value exists, the function should return =false=. Otherwise one (and only one) element is removed and the function returns =true=. *Hint*: help yourself with copy&paste from the previous function add.
|
|
||||||
|
|
||||||
** The command interface
|
|
||||||
|
|
||||||
The main function implements the command interface that understands the following commands:
|
|
||||||
|
|
||||||
- =add {int}= ("add" followed by a sequence of integers) -- calls add on a sorted list for all the integers provided. Example: add 1 2 3 adds numbers 1, 2 and 3 to the list.
|
|
||||||
- =remove {int}= ("remove" followed by a sequence of integers) -- calls remove on a sorted list for all integers provided. Example: remove 3 6 removes an element with value 3 and an element with value 6 from the list (as far as available).
|
|
||||||
- =print= -- calls print on the linked list.
|
|
||||||
- =end= -- ends the program.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+BEGIN_src cpp
|
|
||||||
#include "sorted_list.h"
|
|
||||||
|
|
||||||
// post: add a new node with value to the sorted linked list
|
|
||||||
// several nodes with the same value are possible
|
|
||||||
void sorted_list::add(int value) {
|
|
||||||
// this creates a new node in dynamic memory, wrapped in a shared pointer
|
|
||||||
// analogously to new node(value) for normal pointers
|
|
||||||
node_ptr newNode = std::make_shared<node>(value);
|
|
||||||
|
|
||||||
node_ptr prev = nullptr;
|
|
||||||
node_ptr n = first;
|
|
||||||
while (n != nullptr && n->value < value) {
|
|
||||||
prev = n;
|
|
||||||
n = n->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prev == nullptr) {
|
|
||||||
newNode->next = first;
|
|
||||||
first = newNode;
|
|
||||||
} else {
|
|
||||||
newNode->next = n;
|
|
||||||
prev->next = newNode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// post: remove the first node which holds 'value', if any.
|
|
||||||
// if there is no such node, return false
|
|
||||||
// otherwise return true
|
|
||||||
bool sorted_list::remove(int value) {
|
|
||||||
node_ptr searchNode = std::make_shared<node>(value);
|
|
||||||
|
|
||||||
node_ptr prev = nullptr;
|
|
||||||
node_ptr n = first;
|
|
||||||
while (n != nullptr && n->value != searchNode->value) {
|
|
||||||
prev = n;
|
|
||||||
n = n->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n != nullptr) {
|
|
||||||
if (prev != nullptr) {
|
|
||||||
prev->next = n->next;
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
first = n->next;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
Before Width: | Height: | Size: 11 KiB |
@@ -1,130 +0,0 @@
|
|||||||
#+TITLE: Task 1: Operator delete
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
/This task is a text based task. You do not need to write any program/C++ file: the answer should be written in main.md (and might include code fragments if questions ask for them)./
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
All the following code fragments use operator delete and delete[] to deallocate memory, but not appropriately. This can lead to an error (including undefined behaviour) or to a memory leak. Find the mistake in each code fragment, explain whether it results in a memory leak or an error, and in the case of an error, point out the location at which it occurs.
|
|
||||||
|
|
||||||
#+BEGIN_src cpp
|
|
||||||
class A {
|
|
||||||
public:
|
|
||||||
A(int sz) {
|
|
||||||
ptr = new int[sz];
|
|
||||||
}
|
|
||||||
~A() {
|
|
||||||
delete ptr;
|
|
||||||
}
|
|
||||||
/* copy constructor, assigmnent operator, public methods. */
|
|
||||||
...
|
|
||||||
private:
|
|
||||||
int* ptr;
|
|
||||||
};
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
#+BEGIN_src cpp
|
|
||||||
struct lnode {
|
|
||||||
int value;
|
|
||||||
lnode* next;
|
|
||||||
};
|
|
||||||
|
|
||||||
void recursive_delete_linked_list(lnode* n) {
|
|
||||||
if (n != nullptr) {
|
|
||||||
delete n;
|
|
||||||
recursive_delete_linked_list(n->next);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
#+BEGIN_src cpp
|
|
||||||
class A {
|
|
||||||
public:
|
|
||||||
A() {
|
|
||||||
c = new Cell;
|
|
||||||
c->subcell = new int(0);
|
|
||||||
}
|
|
||||||
~A() {
|
|
||||||
delete c;
|
|
||||||
}
|
|
||||||
/* copy constructor, assignment operator, public methods */
|
|
||||||
...
|
|
||||||
private:
|
|
||||||
struct Cell {
|
|
||||||
int* subcell;
|
|
||||||
};
|
|
||||||
Cell* c;
|
|
||||||
};
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
#+BEGIN_src cpp
|
|
||||||
void do_something(int* p) {
|
|
||||||
/* Do something */
|
|
||||||
...
|
|
||||||
}
|
|
||||||
void f() {
|
|
||||||
int v;
|
|
||||||
int* w = &v;
|
|
||||||
do_something(w);
|
|
||||||
delete w;
|
|
||||||
}
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
#+BEGIN_src cpp
|
|
||||||
class Vec {
|
|
||||||
public:
|
|
||||||
Vec(int size) {
|
|
||||||
array = new int[size];
|
|
||||||
}
|
|
||||||
~Vec() {
|
|
||||||
delete[] array;
|
|
||||||
}
|
|
||||||
int& operator[](int idx) {
|
|
||||||
return array[idx];
|
|
||||||
}
|
|
||||||
/* copy constructor, assignment operator, other public methods */
|
|
||||||
...
|
|
||||||
private:
|
|
||||||
int* array;
|
|
||||||
};
|
|
||||||
|
|
||||||
void f() {
|
|
||||||
Vec v(5);
|
|
||||||
delete[] &v[0];
|
|
||||||
}
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+BEGIN_src md
|
|
||||||
1. Mistake: The mistake is that `delete` was used instead of `delete[]`
|
|
||||||
|
|
||||||
Nature: "error (undefined behaviour)"
|
|
||||||
|
|
||||||
Error location (if applicable): The mistake happens when the deconstructor `~A()` is called.
|
|
||||||
|
|
||||||
2. Mistake: The mistake is that the `lnode` is first deleted and then an attribute of the `lnode` is used, which was already deleted
|
|
||||||
|
|
||||||
Nature: "error" and memory leak"
|
|
||||||
|
|
||||||
Error location (if applicable): The mistake happens in the `if` function when `n` is deleted and recursively recalled.
|
|
||||||
|
|
||||||
3. Mistake: The mistake is that we only delete `c`without deleting the pointer pointing to the `subcell`.
|
|
||||||
|
|
||||||
Nature: "memory leak"
|
|
||||||
|
|
||||||
Error location (if applicable): The mistake happens when `c` is deleted.
|
|
||||||
|
|
||||||
4. Mistake: The mistake is that we try to delete an integer from the stack memory.
|
|
||||||
|
|
||||||
Nature: "error (undefined behaviour)"
|
|
||||||
|
|
||||||
Error location (if applicable): The mistake happens when `w` is deleted
|
|
||||||
|
|
||||||
5. Mistake: The mistake is that `delete` tries to delete the address and not the value allocated tot he memory.
|
|
||||||
|
|
||||||
Nature: "error (undefined behaviour)"
|
|
||||||
|
|
||||||
Error location (if applicable): The mistake happens when `&v[0]` is deleted.
|
|
||||||
|
|
||||||
#+END_src
|
|
@@ -1,46 +0,0 @@
|
|||||||
#+tilte: Task 2a: Understanding Pointers - Num_Elements
|
|
||||||
#+author: JirR02
|
|
||||||
|
|
||||||
* Task Description
|
|
||||||
|
|
||||||
Complete the definition of function =num_elements= by editing the file =num_elements.cpp= according to its specified pre- and post conditions.
|
|
||||||
|
|
||||||
We provide a test program using the implemented function to find the number of elements in a specified interval of a vector.
|
|
||||||
|
|
||||||
** Input
|
|
||||||
|
|
||||||
The test program accepts
|
|
||||||
|
|
||||||
- a vector length,
|
|
||||||
- the start index a, and
|
|
||||||
- the end index b.
|
|
||||||
|
|
||||||
For example
|
|
||||||
|
|
||||||
#+BEGIN_src shell
|
|
||||||
10 3 10
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
means a 10-element vector and the interval between index 3 and 9.
|
|
||||||
|
|
||||||
** Output
|
|
||||||
|
|
||||||
The test program prints the number of elements in the interval [a,b).
|
|
||||||
|
|
||||||
For example the input given above, this value is 7.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+BEGIN_src cpp
|
|
||||||
#include "num_elements.h"
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
// PRE: a <= b are valid pointers to elements of the same contiguous memory
|
|
||||||
// block. POST: Returns the number of elements in between those pointers
|
|
||||||
// (starting at a, not including b).
|
|
||||||
int num_elements(const int *a, const int *b) { return b - a; }
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
@@ -1,51 +0,0 @@
|
|||||||
#+title: Task 2b: Understanding Pointers - First_Char
|
|
||||||
#+author: JirR02
|
|
||||||
|
|
||||||
* Task Description
|
|
||||||
|
|
||||||
Complete the definition of function =first_char= by editing the file =first_char.cpp= according to its specified pre- and post conditions.
|
|
||||||
|
|
||||||
We provide a test program using the implemented function to find the index of the first character in a string.
|
|
||||||
|
|
||||||
** Input
|
|
||||||
|
|
||||||
The program accepts
|
|
||||||
|
|
||||||
* a string s (it may contain whitespaces), followed by a newline, and
|
|
||||||
* a character c for which to search for the index first occurence
|
|
||||||
|
|
||||||
For example
|
|
||||||
|
|
||||||
#+BEGIN_src shell
|
|
||||||
jabberwock
|
|
||||||
b
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
** Output
|
|
||||||
|
|
||||||
The pointer to the first element at string =s= where it is equal to character =c=.
|
|
||||||
|
|
||||||
If there is no match, returns a null pointer.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+BEGIN_src cpp
|
|
||||||
#include "first_char.h"
|
|
||||||
|
|
||||||
// PRE: str points within an allocated memory block which contains
|
|
||||||
// the null character (numerical ASCII value 0) at its last location,
|
|
||||||
// and nowhere else.
|
|
||||||
// POST: Returns the pointer to first element at str or after
|
|
||||||
// that is equal to ch, otherwise return nullptr.
|
|
||||||
const char *first_char(const char *str, const char ch) {
|
|
||||||
for (;; str++)
|
|
||||||
if (*str == ch)
|
|
||||||
return str;
|
|
||||||
else if (*str == '\0')
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
@@ -1,76 +0,0 @@
|
|||||||
#+title: Task 3: Array-based Vector, Rule of Three
|
|
||||||
#+author: JirR02
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
You are provided a partial implementation of an array-based vector class =our_vector=. Declarations are given in file =our_vector.h=, member functions that are already implemented are in file =our_vector_locked.cpp=. Your task is to implement the copy constructor, assignment operator and destructor for class "our_vector", in file =our_vector.cpp=. Note that the vectors store values of type tracked and not =int= as in the lecture, but you can treat them in the same fashion; the tracked values are used behind the scenes for checking your solution.
|
|
||||||
|
|
||||||
*Steps*:
|
|
||||||
|
|
||||||
1. Implement the copy constructor for class =our_vector= so that it creates a copy of the internal array.
|
|
||||||
|
|
||||||
1. Implement the assignment operator so that it creates a copy of the provided =our_vector= and destroys the vector that is currently assigned to the left-hand-side of the assignment (e.g., by swapping its current contents to a local copy, as described in the lecture).
|
|
||||||
|
|
||||||
1. Implement the destructor so that it deallocates the internal array.
|
|
||||||
|
|
||||||
*Memory tracking*: The internal elements of class =our_vector= are objects of class tracked (see file =tracker.h=). Such objects encapsulate a single integer location which is tracked by an internal memory manager. This is used internally to catch as many memory/deallocation errors as possible upon occurrence.
|
|
||||||
|
|
||||||
*Testing*: Tests are already provided in file =main.cpp=. If you want to carry out further testing yourself, you may do so within function =your_own_tests()=, which is called by =main()= when encountering an unknown test identifier. You can edit this function in file =our_vector.cpp=.
|
|
||||||
|
|
||||||
*Valgrind output* After you implemented the copy constructor (subtask 1), you may see the following (or similar) output generated by valgrind:
|
|
||||||
|
|
||||||
#+BEGIN_src shell
|
|
||||||
Remaining tracked elements: 6
|
|
||||||
|
|
||||||
memory errors:
|
|
||||||
[ERROR:Leak_DefinitelyLost] 20 bytes in 1 blocks are definitely lost in loss record 1 of 2
|
|
||||||
in function `our_vector::our_vector(int)` at our_vector_locked.cpp:6
|
|
||||||
in function `test_copy_constructor()` at main.cpp:9
|
|
||||||
in function `main` at main.cpp:63
|
|
||||||
[ERROR:Leak_DefinitelyLost] 20 bytes in 1 blocks are definitely lost in loss record 2 of 2
|
|
||||||
in function `our_vector::our_vector(our_vector const&)` at our_vector.cpp:5
|
|
||||||
in function `test_copy_constructor()` at main.cpp:13
|
|
||||||
in function `main` at main.cpp:63
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
This indicates that in your program some memory has been dynamically allocated (in this case one =our_vector= object), but then this memory is definitely /lost/ when the main function returns (the memory can not be longer accessed).
|
|
||||||
|
|
||||||
To solve this issue, you have to implement the object destructor (subtask 3).
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+BEGIN_src cpp
|
|
||||||
#include "our_vector.h"
|
|
||||||
#include <unordered_set>
|
|
||||||
|
|
||||||
our_vector::our_vector(const our_vector &vec) /* TODO */ {
|
|
||||||
count = vec.count;
|
|
||||||
elements = new tracked[count];
|
|
||||||
for (int i = 0; i < count; ++i) {
|
|
||||||
elements[i] = vec.elements[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
our_vector &our_vector::operator=(const our_vector &t) {
|
|
||||||
if (this != &t) {
|
|
||||||
delete[] elements;
|
|
||||||
|
|
||||||
count = t.count;
|
|
||||||
elements = new tracked[count];
|
|
||||||
|
|
||||||
for (int i = 0; i < count; ++i)
|
|
||||||
elements[i] = t.elements[i];
|
|
||||||
}
|
|
||||||
return (*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
our_vector::~our_vector() { delete[] elements; }
|
|
||||||
|
|
||||||
void your_own_tests() {
|
|
||||||
// Any extra test here.
|
|
||||||
}
|
|
||||||
#+END_src
|
|
||||||
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
14
Informatik_I/Exercise_2/task_1/README.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# Task 1
|
||||||
|
|
||||||
|
This task is a text based task. You do not need to write any program/C++ file: the answer should be written in solutions.txt according to the indicated format. Lines that start with "#" are interpreted as comments. You can run the autograder to check correctness.
|
||||||
|
|
||||||
|
## Task
|
||||||
|
|
||||||
|
Which of the following expressions evaluate to `true`, which to `false`?
|
||||||
|
|
||||||
|
1. `3 >= 3`
|
||||||
|
1. `true || false && false`
|
||||||
|
1. `(true || false) && false`
|
||||||
|
1. `3 > (1 < true)`
|
||||||
|
1. `8 > 4 > 2 > 1`
|
||||||
|
1. `2 < a < 4` (a is a variable of type int)
|
@@ -1,37 +0,0 @@
|
|||||||
#+TITLE: Task 1: Expression Evaluation
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
|
|
||||||
This task is a text based task. You do not need to write any program/C++ file: the answer should be written in solutions.txt according to the indicated format. Lines that start with "#" are interpreted as comments. You can run the autograder to check correctness.
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
Which of the following expressions evaluate to =true=, which to =false=?
|
|
||||||
|
|
||||||
1. =3 >= 3=
|
|
||||||
1. =true || false && false=
|
|
||||||
1. =(true || false) && false=
|
|
||||||
1. =3 > (1 < true)=
|
|
||||||
1. =8 > 4 > 2 > 1=
|
|
||||||
1. =2 < a < 4= (a is a variable of type int)
|
|
||||||
|
|
||||||
* Solutions
|
|
||||||
|
|
||||||
#+begin_src txt
|
|
||||||
# Lines starting with # are comments. Spaces are ignored.
|
|
||||||
|
|
||||||
# Replace the question marks, indicating which of the following expression evaluate to true, which to false.
|
|
||||||
|
|
||||||
|
|
||||||
1. 3 >= 3 == true
|
|
||||||
|
|
||||||
2. true || false && false == true
|
|
||||||
|
|
||||||
3. (true || false) && false == false
|
|
||||||
|
|
||||||
4. 3 > (1 < true) == true
|
|
||||||
|
|
||||||
5. 8 > 4 > 2 > 1 == false
|
|
||||||
|
|
||||||
6. 2 < a < 4 == true
|
|
||||||
#+end_src
|
|
17
Informatik_I/Exercise_2/task_1/solutions.txt
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Lines starting with # are comments. Spaces are ignored.
|
||||||
|
|
||||||
|
# Replace the question marks, indicating which of the following expression evaluate to true, which to false.
|
||||||
|
|
||||||
|
|
||||||
|
1. 3 >= 3 == true
|
||||||
|
|
||||||
|
2. true || false && false == true
|
||||||
|
|
||||||
|
3. (true || false) && false == false
|
||||||
|
|
||||||
|
4. 3 > (1 < true) == true
|
||||||
|
|
||||||
|
5. 8 > 4 > 2 > 1 == false
|
||||||
|
|
||||||
|
6. 2 < a < 4 == true
|
||||||
|
|
25
Informatik_I/Exercise_2/task_2/README.md
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Task
|
||||||
|
|
||||||
|
Translate the following natural language expressions to `C++` expressions. Assume that all the variables are non-negative integers or boolean (of value `true` or `false`).
|
||||||
|
|
||||||
|
_For this task you need to write the solutions in the `solutions.cpp` file, by filling the various functions that have been defined for each subtasks._
|
||||||
|
|
||||||
|
**Example:** $a$ is greater than $3$ and smaller than $5$. $\Longrightarrow$ Solution:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
return a > 3 && a < 5;
|
||||||
|
```
|
||||||
|
|
||||||
|
_Note:_ Do not confuse the bitwise logical operators (e.g., `&`) with their binary logical counterparts (`&&`). The semantics are slightly different — bitwise operators do not exhibit short circuit evaluation.
|
||||||
|
|
||||||
|
1. $a$ greater than $b$ and the difference between $a$ and $b$ is smaller than $15$.
|
||||||
|
1. $a$ is an even natural number greater than $a$.
|
||||||
|
1. $a$ is at most $5$ times greater than $b$ (but can also be smaller than $b$) and at least $5$ times greater than $c$.
|
||||||
|
1. Either $a$ and $b$ are both false or $c$ is true, but not both.
|
||||||
|
1. $a$ is false and $b$ is zero.
|
||||||
|
|
||||||
|
## Input
|
||||||
|
|
||||||
|
The program expects the task number as the first input followed by the parameters to the chosen task. For example, `3 5 1 1` selects task `3` with `a = 5`, `b = 1`, and `c = 1`.
|
||||||
|
|
||||||
|
Note that boolean parameters for tasks 4 and 5 are entered as true and false. For example `4 true false true` would run task `4` with `a = true`, `b = false`, and `c = true`.
|
@@ -1,86 +0,0 @@
|
|||||||
#+TITLE: Task 2: From Natural Language to C++
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
Translate the following natural language expressions to =C++= expressions. Assume that all the variables are non-negative integers or boolean (of value =true= or =false=).
|
|
||||||
|
|
||||||
/For this task you need to write the solutions in the =solutions.cpp= file, by filling the various functions that have been defined for each subtasks./
|
|
||||||
|
|
||||||
*Example:* \(a\) is greater than \(3\) and smaller than \(5\). \(\Longrightarrow\) *Solution:*
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
return a > 3 && a < 5;
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
/Note:/ Do not confuse the bitwise logical operators (e.g., =&=) with their binary logical counterparts (=&&=). The semantics are slightly different — bitwise operators do not exhibit short circuit evaluation.
|
|
||||||
|
|
||||||
1. \(a\) greater than \(b\) and the difference between \(a\) and \(b\) is smaller than \(15\).
|
|
||||||
1. \(a\) is an even natural number greater than \(a\).
|
|
||||||
1. \(a\) is at most \(5\) times greater than \(b\) (but can also be smaller than \(b\)) and at least \(5\) times greater than \(c\).
|
|
||||||
1. Either \(a\) and \(b\) are both false or \(c\) is true, but not both.
|
|
||||||
1. \(a\) is false and \(b\) is zero.
|
|
||||||
|
|
||||||
** Input
|
|
||||||
|
|
||||||
The program expects the task number as the first input followed by the parameters to the chosen task. For example, =3 5 1 1= selects task =3= with =a = 5=, =b = 1=, and =c = 1=.
|
|
||||||
|
|
||||||
Note that boolean parameters for tasks 4 and 5 are entered as true and false. For example =4 true false true= would run task =4= with =a = true=, =b = false=, and =c = true=.
|
|
||||||
|
|
||||||
* Solutions
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include "solutions.h"
|
|
||||||
|
|
||||||
// Fill out each function with the appropriate expression
|
|
||||||
|
|
||||||
bool task1(int a, int b) {
|
|
||||||
// a greater than b and the difference between a and b is smaller than 15.
|
|
||||||
if (a > b && (a - b) < 15) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool task2(int a) {
|
|
||||||
// a is an even natural number greater than 3.
|
|
||||||
if (a > 3 && a % 2 == 0) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool task3(int a, int b, int c) {
|
|
||||||
// a is at most 5 times greater than b (but can also be smaller than b)
|
|
||||||
// and at least 5 times greater than c.
|
|
||||||
if (a <= 5 * b && a >= 5 * c) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool task4(bool a, bool b, bool c) {
|
|
||||||
// Either a and b are both false or c is true, but not both.
|
|
||||||
if ((a == false && b == false) != (c == true)) {
|
|
||||||
return true; // Replace with your solution
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool task5(bool a, int b) {
|
|
||||||
// a is false and b is zero.
|
|
||||||
if (a == false && b == false) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false; // Replace with your solution
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
49
Informatik_I/Exercise_2/task_2/solutions.cpp
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#include "solutions.h"
|
||||||
|
|
||||||
|
// Fill out each function with the appropriate expression
|
||||||
|
|
||||||
|
bool task1(int a, int b) {
|
||||||
|
// a greater than b and the difference between a and b is smaller than 15.
|
||||||
|
if (a > b && (a - b) < 15) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool task2(int a) {
|
||||||
|
// a is an even natural number greater than 3.
|
||||||
|
if (a > 3 && a % 2 == 0) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool task3(int a, int b, int c) {
|
||||||
|
// a is at most 5 times greater than b (but can also be smaller than b)
|
||||||
|
// and at least 5 times greater than c.
|
||||||
|
if (a <= 5 * b && a >= 5 * c) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool task4(bool a, bool b, bool c) {
|
||||||
|
// Either a and b are both false or c is true, but not both.
|
||||||
|
if ((a == false && b == false) != (c == true)) {
|
||||||
|
return true; // Replace with your solution
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool task5(bool a, int b) {
|
||||||
|
// a is false and b is zero.
|
||||||
|
if (a == false && b == false) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false; // Replace with your solution
|
||||||
|
}
|
||||||
|
}
|
21
Informatik_I/Exercise_2/task_3a/README.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Task
|
||||||
|
|
||||||
|
_Fibonacci numbers_ are the integers in the following sequence: $0, 1, 1, 2, 3, 5, 8, 13, 21, ...$. Each number is the sum of the two previous numbers.
|
||||||
|
|
||||||
|
_Fibonacci primes_ are Fibonacci numbers that are also prime numbers. Write a program that asks the user for an integer $m$ and then computes and prints all Fibonacci primes between $0$ and $m$ (including). Print each number on a new line.
|
||||||
|
|
||||||
|
Finally, on a new line print the total number of Fibonacci primes found.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
If your program is asked to print the Fibonacci primes between $0$ and $14$ the output should look something like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
2
|
||||||
|
3
|
||||||
|
5
|
||||||
|
13
|
||||||
|
Found 4 Fibonacci primes
|
||||||
|
```
|
||||||
|
|
||||||
|
**Important:** using anything other than `int` (e.g., `unsigned int`, floating point numbers, `long`, or double `long`) is forbidden.
|
@@ -1,30 +1,3 @@
|
|||||||
#+TITLE: Task 3a: Fibonacci primes
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
/Fibonacci numbers/ are the integers in the following sequence: \(0, 1, 1, 2, 3, 5, 8, 13, 21, ...\). Each number is the sum of the two previous numbers.
|
|
||||||
|
|
||||||
/Fibonacci primes/ are Fibonacci numbers that are also prime numbers. Write a program that asks the user for an integer \(m\) and then computes and prints all Fibonacci primes between \(0\) and \(m\) (including). Print each number on a new line.
|
|
||||||
|
|
||||||
Finally, on a new line print the total number of Fibonacci primes found.
|
|
||||||
|
|
||||||
** Example
|
|
||||||
|
|
||||||
If your program is asked to print the Fibonacci primes between $0$ and $14$ the output should look something like this:
|
|
||||||
|
|
||||||
#+begin_src shell
|
|
||||||
2
|
|
||||||
3
|
|
||||||
5
|
|
||||||
13
|
|
||||||
Found 4 Fibonacci primes
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
*Important:* using anything other than =int= (e.g., =unsigned int=, floating point numbers, =long=, or double =long=) is forbidden.
|
|
||||||
|
|
||||||
* Solutions
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@@ -72,8 +45,3 @@ int main() {
|
|||||||
// End message
|
// End message
|
||||||
std::cout << count << "\n";
|
std::cout << count << "\n";
|
||||||
}
|
}
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-—---
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
58
Informatik_I/Exercise_2/task_3b/README.md
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
# Mistakes
|
||||||
|
|
||||||
|
- The variable `j` goes into overflow which is not allowed!
|
||||||
|
|
||||||
|
# Fibonacci overflow check
|
||||||
|
|
||||||
|
## Background
|
||||||
|
|
||||||
|
_Fibonacci numbers_ are the integers in the following sequence: $0, 1, 1, 2, 3, 5, 8, 13, 21, ...$, where each number is the sum of the two previous numbers.
|
||||||
|
|
||||||
|
## Task
|
||||||
|
|
||||||
|
Fibonacci numbers grow fast, and can thus easily exceed the value range of 32-bit `int`. Think of a general way how you can check if the result of an addition would exceed the range of a 32-bit `int` (i.e. overflow) **without actually performing the addition causing the overflow.**
|
||||||
|
|
||||||
|
Remember that we consider **signed integers.** Because only half of the numbers are positive, this leaves us with 31 bits to store the actual positive number value.
|
||||||
|
|
||||||
|
Write a program that asks the user for an integer $n$ and then prints the first $n$ Fibonacci numbers, each number on a new line. Use an `int` (we assume 32 bits, including the sign) to represent the current Fibonacci number. **Most importantly:** exit the print loop as soon as you detect that an overflow _would occur._
|
||||||
|
|
||||||
|
Finally, again on a new line, output the count $c$ of Fibonacci numbers previously printed, and the initial input $n$ from the user, in the format: `c of n`.
|
||||||
|
|
||||||
|
### Example:
|
||||||
|
|
||||||
|
Let's (wrongly!) assume that $5$ cannot be represented using a 32 bit int. This means that $3$ is the largest 32-bit Fibonacci number. If your program is asked to print the first $4$ Fibonacci numbers the output should look as follows:
|
||||||
|
|
||||||
|
```
|
||||||
|
0
|
||||||
|
1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
Printed 4 of 4 Fibonacci numbers
|
||||||
|
```
|
||||||
|
|
||||||
|
If you instead ask it to print the first 100 Fibonacci numbers the output should look as follows:
|
||||||
|
|
||||||
|
```
|
||||||
|
0
|
||||||
|
1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
Printed 5 of 100 Fibonacci numbers
|
||||||
|
```
|
||||||
|
|
||||||
|
**Important:** using anything other than `int` (e.g., `unsigned int`, floating point numbers, `long`, or double `long`) is forbidden.
|
||||||
|
|
||||||
|
**Restrictions:**
|
||||||
|
|
||||||
|
- The program **must not** rely on the knowledge of its final result. In particular, it is not allowed to hard-code
|
||||||
|
- the largest 32-bits Fibonacci number, or
|
||||||
|
- the number of digits that it has, or
|
||||||
|
- the total number of Fibonacci numbers representable with a 32-bit int
|
||||||
|
- Most importantly: do not perform additions that cause an overflow on 32 bit
|
||||||
|
|
||||||
|
**Note:** It is straightfoward to compute the largest (signed) integer representable with 32 bits. You are also explicitly allowed to hard-code this value in your program.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Warning:** The autograder does not catch if an addition causes an overflow or if you do anything that's disallowed in the "Restrictions" section above, but you will receive 0 points when your TA corrects and catches this.
|
@@ -1,94 +0,0 @@
|
|||||||
#+TITLE: Task 3b: Fibonacci overflow check
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Background
|
|
||||||
|
|
||||||
/Fibonacci numbers/ are the integers in the following sequence: \(0, 1, 1, 2, 3, 5, 8, 13, 21, ...\), where each number is the sum of the two previous numbers.
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
Fibonacci numbers grow fast, and can thus easily exceed the value range of 32-bit =int=. Think of a general way how you can check if the result of an addition would exceed the range of a 32-bit =int= (i.e. overflow) *without actually performing the addition causing the overflow.*
|
|
||||||
|
|
||||||
Remember that we consider *signed integers.* Because only half of the numbers are positive, this leaves us with 31 bits to store the actual positive number value.
|
|
||||||
|
|
||||||
Write a program that asks the user for an integer \(n\) and then prints the first $n$ Fibonacci numbers, each number on a new line. Use an =int= (we assume 32 bits, including the sign) to represent the current Fibonacci number. *Most importantly:* exit the print loop as soon as you detect that an overflow /would occur./
|
|
||||||
|
|
||||||
Finally, again on a new line, output the count \(c\) of Fibonacci numbers previously printed, and the initial input \(n\) from the user, in the format: =c of n=.
|
|
||||||
|
|
||||||
** Example:
|
|
||||||
|
|
||||||
Let's (wrongly!) assume that \(5\) cannot be represented using a 32 bit =int=. This means that \(3\) is the largest 32-bit Fibonacci number. If your program is asked to print the first \(4\) Fibonacci numbers the output should look as follows:
|
|
||||||
|
|
||||||
#+begin_src shell
|
|
||||||
0
|
|
||||||
1
|
|
||||||
1
|
|
||||||
2
|
|
||||||
Printed 4 of 4 Fibonacci numbers
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
If you instead ask it to print the first 100 Fibonacci numbers the output should look as follows:
|
|
||||||
|
|
||||||
#+begin_src shell
|
|
||||||
0
|
|
||||||
1
|
|
||||||
1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
Printed 5 of 100 Fibonacci numbers
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
*Important:* using anything other than =int= (e.g., =unsigned int=, floating point numbers, =long=, or double =long=) is forbidden.
|
|
||||||
|
|
||||||
*Restrictions:*
|
|
||||||
|
|
||||||
- The program **must not** rely on the knowledge of its final result. In particular, it is not allowed to hard-code
|
|
||||||
- the largest 32-bits Fibonacci number, or
|
|
||||||
- the number of digits that it has, or
|
|
||||||
- the total number of Fibonacci numbers representable with a 32-bit int
|
|
||||||
- Most importantly: do not perform additions that cause an overflow on 32 bit
|
|
||||||
|
|
||||||
*Note:* It is straightfoward to compute the largest (signed) integer representable with 32 bits. You are also explicitly allowed to hard-code this value in your program.
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
*Warning:* The autograder does not catch if an addition causes an overflow or if you do anything that's disallowed in the "Restrictions" section above, but you will receive 0 points when your TA corrects and catches this.
|
|
||||||
|
|
||||||
* Mistakes
|
|
||||||
|
|
||||||
- The variable =j= goes into overflow which is not allowed!
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
int a = 0; // First Fibonacci number
|
|
||||||
int b = 1; // Second Fibonacci number
|
|
||||||
int j = 0; // New Fibonacci number
|
|
||||||
int c = 0; // Number of Fibonacci numbers
|
|
||||||
int max = 2147483647;
|
|
||||||
int n; // Input integer
|
|
||||||
|
|
||||||
std::cin >> n;
|
|
||||||
|
|
||||||
for (int i = 0; i < n; ++i) {
|
|
||||||
|
|
||||||
if (max - a < b) { // Check if the new Fibonacci number goes into overflow
|
|
||||||
break;
|
|
||||||
} else { // otherwise, calculate next Fibonacci number
|
|
||||||
std::cout << j << "\n";
|
|
||||||
a = b;
|
|
||||||
b = j;
|
|
||||||
j = a + b;
|
|
||||||
++c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout << c << " of " << n; // End Message
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
—----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
26
Informatik_I/Exercise_2/task_3b/main.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int a = 0; // First Fibonacci number
|
||||||
|
int b = 1; // Second Fibonacci number
|
||||||
|
int j = 0; // New Fibonacci number
|
||||||
|
int c = 0; // Number of Fibonacci numbers
|
||||||
|
int max = 2147483647;
|
||||||
|
int n; // Input integer
|
||||||
|
|
||||||
|
std::cin >> n;
|
||||||
|
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
|
||||||
|
if (max - a < b) { // Check if the new Fibonacci number goes into overflow
|
||||||
|
break;
|
||||||
|
} else { // otherwise, calculate next Fibonacci number
|
||||||
|
std::cout << j << "\n";
|
||||||
|
a = b;
|
||||||
|
b = j;
|
||||||
|
j = a + b;
|
||||||
|
++c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << c << " of " << n; // End Message
|
||||||
|
}
|
14
Informatik_I/Exercise_2/task_4/README.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
## Task
|
||||||
|
|
||||||
|
Write a program that inputs a non-negative integer `n` (but store it as `int`) and outputs the binary digits of `n` in the _correct_ order (i.e., starting with the most significant bit). Do not output the leading zeros or the sign.
|
||||||
|
|
||||||
|
**Hint:** In order to find the largest integer $k$ such that $2^k \leq x$, you can utilize that $k$ is the smallest integer such that $2^k > \frac{x}{2}$. This observation is particularly useful to avoid an overflow for the expression $2^k$ when searching for the most significant bit to represent $x$.
|
||||||
|
|
||||||
|
**Restrictions:**
|
||||||
|
|
||||||
|
- Libraries: only the iostream standard library header is allowed; using arrays, string or cmath is not permitted.
|
||||||
|
- Operators: you may not use bitshift operators to manipulate the numbers.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Warning:** The autograder does not catch if you do anything that's disallowed in the "Restrictions" section above, but you will receive 0 points when your TA corrects and catches this.
|
@@ -1,54 +0,0 @@
|
|||||||
#+TITLE: Task 4: From decimal to binary representation
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
Write a program that inputs a non-negative integer =n= (but store it as =int=) and outputs the binary digits of =n= in the /correct/ order (i.e., starting with the most significant bit). Do not output the leading zeros or the sign.
|
|
||||||
|
|
||||||
*Hint:* In order to find the largest integer \(k\) such that \(2^k \leq x\), you can utilize that \(k\) is the smallest integer such that \(2^k > \frac{x}{2}\). This observation is particularly useful to avoid an overflow for the expression \(2^k\) when searching for the most significant bit to represent \(x\).
|
|
||||||
|
|
||||||
*Restrictions:*
|
|
||||||
|
|
||||||
- Libraries: only the iostream standard library header is allowed; using arrays, string or cmath is not permitted.
|
|
||||||
- Operators: you may not use bitshift operators to manipulate the numbers.
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
*Warning:* The autograder does not catch if you do anything that's disallowed in the "Restrictions" section above, but you will receive 0 points when your TA corrects and catches this.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
int i = 0; // Input integer
|
|
||||||
int d = 0; // Input Number
|
|
||||||
int a = 0; // Part of binary number
|
|
||||||
int b = 0; // Number to divide
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
std::cin >> i;
|
|
||||||
d = i;
|
|
||||||
b = i;
|
|
||||||
|
|
||||||
if (i < 0) {
|
|
||||||
return 0;
|
|
||||||
} else if (i == 0) {
|
|
||||||
std::cout << 0;
|
|
||||||
} else {
|
|
||||||
while (d != 0) {
|
|
||||||
d = d / 2;
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
for (; count > 0; --count) {
|
|
||||||
for (int j = count; j > 1; --j) {
|
|
||||||
b = b / 2;
|
|
||||||
}
|
|
||||||
a = b % 2;
|
|
||||||
std::cout << a;
|
|
||||||
b = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#+end_src
|
|
32
Informatik_I/Exercise_2/task_4/main.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int i = 0; // Input integer
|
||||||
|
int d = 0; // Input Number
|
||||||
|
int a = 0; // Part of binary number
|
||||||
|
int b = 0; // Number to divide
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
std::cin >> i;
|
||||||
|
d = i;
|
||||||
|
b = i;
|
||||||
|
|
||||||
|
if (i < 0) {
|
||||||
|
return 0;
|
||||||
|
} else if (i == 0) {
|
||||||
|
std::cout << 0;
|
||||||
|
} else {
|
||||||
|
while (d != 0) {
|
||||||
|
d = d / 2;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
for (; count > 0; --count) {
|
||||||
|
for (int j = count; j > 1; --j) {
|
||||||
|
b = b / 2;
|
||||||
|
}
|
||||||
|
a = b % 2;
|
||||||
|
std::cout << a;
|
||||||
|
b = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
Informatik_I/Exercise_3/Task_1/README.md
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
_This task is a mixed text/programming task. You need to update the content of loop.cpp according to the instruction provided in the file. For the code part, please check the autograder output._
|
||||||
|
|
||||||
|
# Task
|
||||||
|
|
||||||
|
Considering the snippet
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
int n;
|
||||||
|
std::cin >> n;
|
||||||
|
int f = 1;
|
||||||
|
if (n > 0) {
|
||||||
|
do {
|
||||||
|
f = f * n;
|
||||||
|
--n;
|
||||||
|
} while (n > 0);
|
||||||
|
}
|
||||||
|
std::cout << f << std::endl;
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Describe what it computes.
|
||||||
|
1. Decide which of the other two kind of loops would fit better than the one it is currently using, and describe why.
|
||||||
|
1. Rewrite the snippet into the loop you specified in (2). This part is autograded.
|
||||||
|
|
||||||
|
**Important**: The use of goto statements is prohibited.
|
@@ -1,34 +1,3 @@
|
|||||||
#+TITLE: Task 1: Loop mix-up: Snippet 1
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
/This task is a mixed text/programming task. You need to update the content of loop.cpp according to the instruction provided in the file. For the code part, please check the autograder output./
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
Considering the snippet
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
int n;
|
|
||||||
std::cin >> n;
|
|
||||||
int f = 1;
|
|
||||||
if (n > 0) {
|
|
||||||
do {
|
|
||||||
f = f * n;
|
|
||||||
--n;
|
|
||||||
} while (n > 0);
|
|
||||||
}
|
|
||||||
std::cout << f << std::endl;
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
1. Describe what it computes.
|
|
||||||
1. Decide which of the other two kind of loops would fit better than the one it is currently using, and describe why.
|
|
||||||
1. Rewrite the snippet into the loop you specified in (2). This part is autograded.
|
|
||||||
|
|
||||||
*Important*: The use of goto statements is prohibited.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include "loop.h"
|
#include "loop.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -72,8 +41,3 @@ void loop() {
|
|||||||
|
|
||||||
std::cout << f << std::endl;
|
std::cout << f << std::endl;
|
||||||
}
|
}
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-—---
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
23
Informatik_I/Exercise_3/Task_2/README.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
_This task is a mixed text/programming task. You need to update the content of loop.cpp according to the instruction provided in the file. For the code part, please check the autograder output._
|
||||||
|
|
||||||
|
# Task
|
||||||
|
|
||||||
|
Considering the snippet
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
for (;;) {
|
||||||
|
int i1, i2;
|
||||||
|
std::cin >> i1 >> i2;
|
||||||
|
std::cout << i1 + i2 << "\n";
|
||||||
|
int again;
|
||||||
|
std::cout << "Again? (0/1)\n";
|
||||||
|
std::cin >> again;
|
||||||
|
if (again == 0) break;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Describe what it computes.
|
||||||
|
|
||||||
|
1. Decide which of the other two kind of loops would fit better than the one it is currently using, and describe why.
|
||||||
|
|
||||||
|
1. Rewrite the snippet into the loop you specified in (2). This part is autograded. Note: print the control message "Again? (0/1)" using the same format used in the snippet.
|
@@ -1,33 +1,3 @@
|
|||||||
#+TITLE: Task 2: Loop mix-up: Snippet 2
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
/This task is a mixed text/programming task. You need to update the content of loop.cpp according to the instruction provided in the file. For the code part, please check the autograder output./
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
Considering the snippet
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
for (;;) {
|
|
||||||
int i1, i2;
|
|
||||||
std::cin >> i1 >> i2;
|
|
||||||
std::cout << i1 + i2 << "\n";
|
|
||||||
int again;
|
|
||||||
std::cout << "Again? (0/1)\n";
|
|
||||||
std::cin >> again;
|
|
||||||
if (again == 0) break;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
1. Describe what it computes.
|
|
||||||
|
|
||||||
1. Decide which of the other two kind of loops would fit better than the one it is currently using, and describe why.
|
|
||||||
|
|
||||||
1. Rewrite the snippet into the loop you specified in (2). This part is autograded. Note: print the control message "Again? (0/1)" using the same format used in the snippet.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include "loop.h"
|
#include "loop.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -76,8 +46,3 @@ void loop() {
|
|||||||
std::cin >> again;
|
std::cin >> again;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
27
Informatik_I/Exercise_3/Task_3/README.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
_This task is a mixed text/programming task. You need to update the content of loop.cpp according to the instructions provided in the file. For the code part, please check the autograder output._
|
||||||
|
|
||||||
|
# Task
|
||||||
|
|
||||||
|
Consider the following program:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
int n;
|
||||||
|
std::cin >> n;
|
||||||
|
|
||||||
|
int x = 1;
|
||||||
|
if (n > 0) {
|
||||||
|
bool e = true;
|
||||||
|
do {
|
||||||
|
if (--n == 0) {
|
||||||
|
e = false;
|
||||||
|
}
|
||||||
|
x *= 2;
|
||||||
|
} while (e);
|
||||||
|
}
|
||||||
|
std::cout << x << std::endl;
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Describe the output of the program as a function of its input n.
|
||||||
|
1. For which values of `n` do you expect a correct output `x`? Explain why.
|
||||||
|
1. Show that this program terminates for all values of `n` found in (2). Hint: Make an argument based on the following idea. First prove that the program terminates for the `n=0` and `n=1`. Then show that it terminates for any other `n` knowing that it terminates for `n-1`. This creates a domino effect where the fact that the program terminates for `n=1` proves that the program must also terminate for `n=2`, and this in turn proves that the program must terminate for `n=3`, and so on. This technique is called "proof by induction".
|
||||||
|
1. Provide a more elegant implementation of this function using another type of loop. This part is autograded.
|
@@ -1,92 +0,0 @@
|
|||||||
#+TITLE: Task 3: Loop Analysis
|
|
||||||
|
|
||||||
/This task is a mixed text/programming task. You need to update the content of loop.cpp according to the instructions provided in the file. For the code part, please check the autograder output./
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
Consider the following program:
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
int n;
|
|
||||||
std::cin >> n;
|
|
||||||
|
|
||||||
int x = 1;
|
|
||||||
if (n > 0) {
|
|
||||||
bool e = true;
|
|
||||||
do {
|
|
||||||
if (--n == 0) {
|
|
||||||
e = false;
|
|
||||||
}
|
|
||||||
x *= 2;
|
|
||||||
} while (e);
|
|
||||||
}
|
|
||||||
std::cout << x << std::endl;
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
1. Describe the output of the program as a function of its input \(n\).
|
|
||||||
1. For which values of \(n\) do you expect a correct output \(x\)? Explain why.
|
|
||||||
1. Show that this program terminates for all values of \(n\) found in (2). Hint: Make an argument based on the following idea. First prove that the program terminates for the \(n=0\) and \(n=1\). Then show that it terminates for any other \(n\) knowing that it terminates for \(n-1\). This creates a domino effect where the fact that the program terminates for \(n=1\) proves that the program must also terminate for \(n=2\), and this in turn proves that the program must terminate for \(n=3\), and so on. This technique is called "proof by induction".
|
|
||||||
1. Provide a more elegant implementation of this function using another type of loop. This part is autograded.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include "loop.h"
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
// Fill out the file with the required answers
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Subtask 1: Describe the output of the program as a function of its input n.
|
|
||||||
|
|
||||||
This code snippte computes the powers of 2 with a positive exponential. The
|
|
||||||
exponential is the input by the user.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Subtask 2: For which values of n do you expect a correct output x? Explain
|
|
||||||
why.
|
|
||||||
|
|
||||||
For a exponential between 0 and 30. Anything below zero would result in the
|
|
||||||
wrong answer (1) and anything above 30 would result in an overflow. In
|
|
||||||
addition, if we imporved the code to calculate the powers of 2 with negative
|
|
||||||
exponents, it would not work since the result of the powers of 2 with negative
|
|
||||||
exponents are variables of type float or double and the code snippet is
|
|
||||||
working with integers.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Subtask 3: Show that this program terminates for all values of n found in (2).
|
|
||||||
|
|
||||||
If the input is 31, the output is -2147483648.
|
|
||||||
If the input is -1, the output is 1.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
Subtask 4: Provide a more elegant implementation of this function using
|
|
||||||
another type of loop.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
int n;
|
|
||||||
std::cin >> n;
|
|
||||||
|
|
||||||
int x = 1;
|
|
||||||
|
|
||||||
for (; n > 0; --n)
|
|
||||||
x *= 2;
|
|
||||||
|
|
||||||
std::cout << x << std::endl;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
54
Informatik_I/Exercise_3/Task_3/loop.cpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#include "loop.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// Fill out the file with the required answers
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
Subtask 1: Describe the output of the program as a function of its input n.
|
||||||
|
|
||||||
|
This code snippte computes the powers of 2 with a positive exponential. The
|
||||||
|
exponential is the input by the user.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
Subtask 2: For which values of n do you expect a correct output x? Explain
|
||||||
|
why.
|
||||||
|
|
||||||
|
For a exponential between 0 and 30. Anything below zero would result in the
|
||||||
|
wrong answer (1) and anything above 30 would result in an overflow. In
|
||||||
|
addition, if we imporved the code to calculate the powers of 2 with negative
|
||||||
|
exponents, it would not work since the result of the powers of 2 with negative
|
||||||
|
exponents are variables of type float or double and the code snippet is
|
||||||
|
working with integers.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
Subtask 3: Show that this program terminates for all values of n found in (2).
|
||||||
|
|
||||||
|
If the input is 31, the output is -2147483648.
|
||||||
|
If the input is -1, the output is 1.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Subtask 4: Provide a more elegant implementation of this function using
|
||||||
|
another type of loop.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
int n;
|
||||||
|
std::cin >> n;
|
||||||
|
|
||||||
|
int x = 1;
|
||||||
|
|
||||||
|
for (; n > 0; --n)
|
||||||
|
x *= 2;
|
||||||
|
|
||||||
|
std::cout << x << std::endl;
|
||||||
|
}
|
19
Informatik_I/Exercise_3/Task_4a/README.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Task
|
||||||
|
|
||||||
|
The number $\pi$ can be defined through various infinite sums. The accuracy increases with the number of terms. Considering the following sum, that we call sum 1:
|
||||||
|
|
||||||
|
$$\frac{\pi}{4} = \sum_{j=0}^{m-1} \frac{(-1)^j}{2j + 1} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + ...$$
|
||||||
|
|
||||||
|
Note that $m$ is the number of the terms in the sum. For example, $m=2$ refers to the sum of the terms $1$ (for $j=0$) and $-\frac{1}{3}$ (for $j=1$). This examples yields a value of $4 \cdot (1-\frac{1}{3})$ for $\pi$.
|
||||||
|
|
||||||
|
Write a program that computes and outputs an approximation of Pi, based on sum 1. The input for your program is the number of **terms** $m$ of sum 1 that should be considered in the calculation. The output is the approximation of $\pi$.
|
||||||
|
|
||||||
|
## Input
|
||||||
|
|
||||||
|
A number $m \geq 1$.
|
||||||
|
|
||||||
|
## Output
|
||||||
|
|
||||||
|
The approximation of $\pi$ given by $4 \sum_{j=0}^{m-1} \frac{(-1)^j}{2j + 1}$, rounded to 6 significant digits. Note that 6 significant digits is the default precision of C++ for printing floating-point values. Use a variable of type double to calculate the sum. Note that that $x^0$ is 1 (if $x \neq 0$).
|
||||||
|
|
||||||
|
**Important**: the use of functions from the math library (e.g., pow) is prohibited.
|
@@ -1,61 +0,0 @@
|
|||||||
#+TITLE: Task 4a: Approximation of Pi: Sum 1
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
The number \(\pi\) can be defined through various infinite sums. The accuracy increases with the number of terms. Considering the following sum, that we call sum 1:
|
|
||||||
|
|
||||||
$$\frac{\pi}{4} = \sum_{j=0}^{m-1} \frac{(-1)^j}{2j + 1} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + ...$$
|
|
||||||
|
|
||||||
Note that \(m\) is the number of the terms in the sum. For example, \(m=2\)$ refers to the sum of the terms \(1\) (for \(j=0\)) and \(-\frac{1}{3}\) (for \(j=1\)). This examples yields a value of \(4 \cdot (1-\frac{1}{3})\) for \(\pi\).
|
|
||||||
|
|
||||||
Write a program that computes and outputs an approximation of Pi, based on sum 1. The input for your program is the number of **terms** $m$ of sum 1 that should be considered in the calculation. The output is the approximation of \(\pi\).
|
|
||||||
|
|
||||||
** Input
|
|
||||||
|
|
||||||
A number \(m \geq 1\).
|
|
||||||
|
|
||||||
** Output
|
|
||||||
|
|
||||||
The approximation of \(\pi\) given by \(4 \sum_{j=0}^{m-1} \frac{(-1)^j}{2j + 1}\), rounded to 6 significant digits. Note that 6 significant digits is the default precision of C++ for printing floating-point values. Use a variable of type double to calculate the sum. Note that \(x^0\) is 1 (if \(x \neq 0\)).
|
|
||||||
|
|
||||||
**Important**: the use of functions from the math library (e.g., pow) is prohibited.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
double power(double n, double e) { // Self defined function for exponent
|
|
||||||
int res = 1;
|
|
||||||
for (; e > 0; --e) {
|
|
||||||
res *= n;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
double m; // User Input
|
|
||||||
double pi = 0; // Pi
|
|
||||||
float res; // Outputed result with 6 significant digits
|
|
||||||
|
|
||||||
std::cin >> m;
|
|
||||||
|
|
||||||
if (m < 1) { // Check if Input is greater than 1.
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
for (int i = 0; i < m; ++i) {
|
|
||||||
pi = pi + 4 * ((power(-1, i)) / ((2 * i) + 1)); // calculate Pi
|
|
||||||
}
|
|
||||||
|
|
||||||
res = (float)(pi); // round to 6 significant digits
|
|
||||||
std::cout << res;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
30
Informatik_I/Exercise_3/Task_4a/main.cpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
double power(double n, double e) { // Self defined function for exponent
|
||||||
|
int res = 1;
|
||||||
|
for (; e > 0; --e) {
|
||||||
|
res *= n;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
double m; // User Input
|
||||||
|
double pi = 0; // Pi
|
||||||
|
float res; // Outputed result with 6 significant digits
|
||||||
|
|
||||||
|
std::cin >> m;
|
||||||
|
|
||||||
|
if (m < 1) { // Check if Input is greater than 1.
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < m; ++i) {
|
||||||
|
pi = pi + 4 * ((power(-1, i)) / ((2 * i) + 1)); // calculate Pi
|
||||||
|
}
|
||||||
|
|
||||||
|
res = (float)(pi); // round to 6 significant digits
|
||||||
|
std::cout << res;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
20
Informatik_I/Exercise_3/Task_4b/README.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Task
|
||||||
|
|
||||||
|
The number $\pi$ can be defined through various infinite sums. The accuracy increases with the number of terms. Considering the following sum, which we call sum 2:
|
||||||
|
|
||||||
|
$$\frac{\pi}{2} = 1 + \sum_{j = 1}^{m - 1} \frac{\prod_{i=1}^j i}{\prod_{i=1}^j (2i + 1)} = 1 + \frac{1}{3} + \frac{1 \cdot 2}{3 \cdot 5} + \frac{1 \cdot 2 \cdot 3}{3 \cdot 5 \cdot 7} + ...$$
|
||||||
|
|
||||||
|
Write a program that computes and outputs an approximation of Pi, based on sum 2. The input for your program is the number of **terms** $m$ (including 1) to be included in the calculation to be done. The output is the approximation of $\pi$.
|
||||||
|
|
||||||
|
**Optional**: After you have solved this and the previous task, think about which formula gives a more precise approximation of
|
||||||
|
, sum 1 or sum 2 ? What are the drawbacks? Write your thoughts in a comment below the code.
|
||||||
|
|
||||||
|
## Input
|
||||||
|
|
||||||
|
A natural number $m$ ($m \geq 1$).
|
||||||
|
|
||||||
|
## Output
|
||||||
|
|
||||||
|
The approximation of $\pi$ given by $m$ terms, rounded to 6 significant digits. Note that 6 significant digits is the default precision of C++ for printing floating-point values. Use a double variable to store the sum.
|
||||||
|
|
||||||
|
**Important**: the use of functions from the math library (e.g., pow) is prohibited.
|
@@ -1,66 +0,0 @@
|
|||||||
#+TITLE: Task 4b: Approximation of Pi: Sum 2
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
The number \(\pi\) can be defined through various infinite sums. The accuracy increases with the number of terms. Considering the following sum, which we call sum 2:
|
|
||||||
|
|
||||||
$$\frac{\pi}{2} = 1 + \sum_{j = 1}^{m - 1} \frac{\prod_{i=1}^j i}{\prod_{i=1}^j (2i + 1)} = 1 + \frac{1}{3} + \frac{1 \cdot 2}{3 \cdot 5} + \frac{1 \cdot 2 \cdot 3}{3 \cdot 5 \cdot 7} + ...$$
|
|
||||||
|
|
||||||
Write a program that computes and outputs an approximation of Pi, based on sum 2. The input for your program is the number of **terms** $m$ (including 1) to be included in the calculation to be done. The output is the approximation of \(\pi\).
|
|
||||||
|
|
||||||
**Optional**: After you have solved this and the previous task, think about which formula gives a more precise approximation of \(\pi\), sum 1 or sum 2 ? What are the drawbacks? Write your thoughts in a comment below the code.
|
|
||||||
|
|
||||||
* Input
|
|
||||||
|
|
||||||
A natural number \(m\) (\(m \geq 1\)).
|
|
||||||
|
|
||||||
* Output
|
|
||||||
|
|
||||||
The approximation of $\pi$ given by $m$ terms, rounded to 6 significant digits. Note that 6 significant digits is the default precision of C++ for printing floating-point values. Use a double variable to store the sum.
|
|
||||||
|
|
||||||
**Important**: the use of functions from the math library (e.g., =pow=) is prohibited.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
double productsumnum(double n) {
|
|
||||||
double res = 1;
|
|
||||||
for (int j = 1; j <= n; ++j) {
|
|
||||||
res *= j;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
double productsumden(double n) {
|
|
||||||
double res = 1;
|
|
||||||
for (int j = 1; j <= n; ++j) {
|
|
||||||
res *= (2 * j + 1);
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
|
|
||||||
double m; // User Input
|
|
||||||
double pi = 2; // Pi
|
|
||||||
float res; // Outputed result with 6 significant digits
|
|
||||||
|
|
||||||
std::cin >> m;
|
|
||||||
|
|
||||||
for (int i = 1; i < m; ++i) {
|
|
||||||
pi += (2 * (productsumnum(i) / productsumden(i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
res = (float)(pi);
|
|
||||||
std::cout << res;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
35
Informatik_I/Exercise_3/Task_4b/main.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
double productsumnum(double n) {
|
||||||
|
double res = 1;
|
||||||
|
for (int j = 1; j <= n; ++j) {
|
||||||
|
res *= j;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
double productsumden(double n) {
|
||||||
|
double res = 1;
|
||||||
|
for (int j = 1; j <= n; ++j) {
|
||||||
|
res *= (2 * j + 1);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
double m; // User Input
|
||||||
|
double pi = 2; // Pi
|
||||||
|
float res; // Outputed result with 6 significant digits
|
||||||
|
|
||||||
|
std::cin >> m;
|
||||||
|
|
||||||
|
for (int i = 1; i < m; ++i) {
|
||||||
|
pi += (2 * (productsumnum(i) / productsumden(i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
res = (float)(pi);
|
||||||
|
std::cout << res;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
19
Informatik_I/Exercise_4/Task_1/README.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
_This task is a text-based task but automatically checked. You are required to write your answers into solutions.txt by replacing the question marks with the correct solution. Please, do not change the structure of solutions.txt and be consistent with its syntax (comment-lines start with #)_
|
||||||
|
|
||||||
|
# Task
|
||||||
|
|
||||||
|
We examine the normalized binary representation of floating point numbers in the normalized floating point system $F*(2,4,-3,3)$.
|
||||||
|
|
||||||
|
1. Convert the following decimal numbers to the normalized binary representation. For each number, choose the appropriate exponent $e$ and round to the nearest value if you cannot represent the exact value. If the exact number falls exactly midway between two bracketing finite floating point representations, round to the number with an even least significant bit.
|
||||||
|
|
||||||
|
- $0.75_{10}$
|
||||||
|
- $3.1416_{10}$
|
||||||
|
- $2.718_{10}$
|
||||||
|
- $7_{10}$
|
||||||
|
- $0.11_{10}$
|
||||||
|
|
||||||
|
1. For each number of (2), convert the binary representation back to their decimal form, and determine the absolute rounding error of the conversion.
|
||||||
|
|
||||||
|
1. Calculate $2.718_{10} + 3.1416_{10} + 0.11_{10}$ in the binary representation. What do you observe?
|
||||||
|
|
||||||
|
**Note**: The question of how to round floating point numbers is non-trivial. The IEEE standard lists 5 different modes of rounding of which we only mentioned the most common one at the beginning of this exercise. If you are interested to learn more, you can access the most recent standard through the ETH network.
|
@@ -1,90 +0,0 @@
|
|||||||
#+TITLE: Task 1: Floating-Point Number Representation
|
|
||||||
|
|
||||||
/This task is a text-based task but automatically checked. You are required to write your answers into solutions.txt by replacing the question marks with the correct solution. Please, do not change the structure of solutions.txt and be consistent with its syntax (comment-lines start with #)/
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
We examine the normalized binary representation of floating point numbers in the normalized floating point system $F*(2,4,-3,3)$.
|
|
||||||
|
|
||||||
1. Convert the following decimal numbers to the normalized binary representation. For each number, choose the appropriate exponent $e$ and round to the nearest value if you cannot represent the exact value. If the exact number falls exactly midway between two bracketing finite floating point representations, round to the number with an even least significant bit.
|
|
||||||
|
|
||||||
- \(0.75_{10}\)
|
|
||||||
- \(3.1416_{10}\)
|
|
||||||
- \(2.718_{10}\)
|
|
||||||
- \(7_{10}\)
|
|
||||||
- \(0.11_{10}\)
|
|
||||||
|
|
||||||
1. For each number of (2), convert the binary representation back to their decimal form, and determine the absolute rounding error of the conversion.
|
|
||||||
|
|
||||||
1. Calculate \(2.718_{10} + 3.1416_{10} + 0.11_{10}\) in the binary representation. What do you observe?
|
|
||||||
|
|
||||||
**Note**: The question of how to round floating point numbers is non-trivial. The IEEE standard lists 5 different modes of rounding of which we only mentioned the most common one at the beginning of this exercise. If you are interested to learn more, you can access the most recent standard through the ETH network.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src shell
|
|
||||||
# NOTE: Lines starting with # are comments. Spaces are ignored.
|
|
||||||
# Replace the question marks, with your answer, following the instructions
|
|
||||||
# provided for each subtask.
|
|
||||||
|
|
||||||
|
|
||||||
######################## Subtask 1 ############################
|
|
||||||
# Subtask 1a: convert 0.75.
|
|
||||||
# In the given system, this is equal to "1.100 * 2^-1". The solution
|
|
||||||
# is written as "1.100*2^-1", without spaces and without quotation marks.
|
|
||||||
|
|
||||||
1a) 1.100*2^-1
|
|
||||||
|
|
||||||
# Subtask 1b: convert 3.1416
|
|
||||||
|
|
||||||
1b) 1.101*2^1
|
|
||||||
|
|
||||||
# Subtask 1c: convert 2.718
|
|
||||||
|
|
||||||
1c) 1.011*2^1
|
|
||||||
|
|
||||||
# Subtask 1d: convert 7
|
|
||||||
|
|
||||||
1d) 1.110*2^2
|
|
||||||
|
|
||||||
# Subtask 1e: convert 0.11
|
|
||||||
|
|
||||||
1e) 1.000*2^-3
|
|
||||||
|
|
||||||
######################## Subtask 2 ############################
|
|
||||||
# Convert the first number of previous Sub-Task back to decimal form.
|
|
||||||
# For each number you are required to write the decimal number and the
|
|
||||||
# conversion error (each on a different line).
|
|
||||||
# For your convenience, the first number is already converted.
|
|
||||||
|
|
||||||
|
|
||||||
2a-decimal) 0.75
|
|
||||||
2a-error) 0
|
|
||||||
|
|
||||||
2b-decimal) 3.25
|
|
||||||
2b-error) 0.1084
|
|
||||||
|
|
||||||
2c-decimal) 2.75
|
|
||||||
2c-error) 0.032
|
|
||||||
|
|
||||||
2d-decimal) 7
|
|
||||||
2d-error) 0
|
|
||||||
|
|
||||||
2e-decimal) 0.125
|
|
||||||
2e-error) 0.015
|
|
||||||
|
|
||||||
######################## Subtask 3 ############################
|
|
||||||
|
|
||||||
# Calculate the result of the addition and indicate the result in the
|
|
||||||
# same format as in the first sub-task ("siginificand*2^exp", without
|
|
||||||
# quotation marks). Then, write your observation as a comment right below.
|
|
||||||
|
|
||||||
3) 1.100*2^2
|
|
||||||
|
|
||||||
# Write your observations here
|
|
||||||
# The Decimal System cannot be represented accurately by the binary system. There will always be an error. When adding the number converted from the decimal to the binary sytem, the error becomes greater.
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
60
Informatik_I/Exercise_4/Task_1/solutions.txt
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
# NOTE: Lines starting with # are comments. Spaces are ignored.
|
||||||
|
# Replace the question marks, with your answer, following the instructions
|
||||||
|
# provided for each subtask.
|
||||||
|
|
||||||
|
|
||||||
|
######################## Subtask 1 ############################
|
||||||
|
# Subtask 1a: convert 0.75.
|
||||||
|
# In the given system, this is equal to "1.100 * 2^-1". The solution
|
||||||
|
# is written as "1.100*2^-1", without spaces and without quotation marks.
|
||||||
|
|
||||||
|
1a) 1.100*2^-1
|
||||||
|
|
||||||
|
# Subtask 1b: convert 3.1416
|
||||||
|
|
||||||
|
1b) 1.101*2^1
|
||||||
|
|
||||||
|
# Subtask 1c: convert 2.718
|
||||||
|
|
||||||
|
1c) 1.011*2^1
|
||||||
|
|
||||||
|
# Subtask 1d: convert 7
|
||||||
|
|
||||||
|
1d) 1.110*2^2
|
||||||
|
|
||||||
|
# Subtask 1e: convert 0.11
|
||||||
|
|
||||||
|
1e) 1.000*2^-3
|
||||||
|
|
||||||
|
######################## Subtask 2 ############################
|
||||||
|
# Convert the first number of previous Sub-Task back to decimal form.
|
||||||
|
# For each number you are required to write the decimal number and the
|
||||||
|
# conversion error (each on a different line).
|
||||||
|
# For your convenience, the first number is already converted.
|
||||||
|
|
||||||
|
|
||||||
|
2a-decimal) 0.75
|
||||||
|
2a-error) 0
|
||||||
|
|
||||||
|
2b-decimal) 3.25
|
||||||
|
2b-error) 0.1084
|
||||||
|
|
||||||
|
2c-decimal) 2.75
|
||||||
|
2c-error) 0.032
|
||||||
|
|
||||||
|
2d-decimal) 7
|
||||||
|
2d-error) 0
|
||||||
|
|
||||||
|
2e-decimal) 0.125
|
||||||
|
2e-error) 0.015
|
||||||
|
|
||||||
|
######################## Subtask 3 ############################
|
||||||
|
|
||||||
|
# Calculate the result of the addition and indicate the result in the
|
||||||
|
# same format as in the first sub-task ("siginificand*2^exp", without
|
||||||
|
# quotation marks). Then, write your observation as a comment right below.
|
||||||
|
|
||||||
|
3) 1.100*2^2
|
||||||
|
|
||||||
|
# Write your observations here
|
||||||
|
# The Decimal System cannot be represented accurately by the binary system. There will always be an error. When adding the number converted from the decimal to the binary sytem, the error becomes greater.
|
17
Informatik_I/Exercise_4/Task_2/README.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Task
|
||||||
|
|
||||||
|
Consider a parabola $(\m{P})$ defined as $y = g(x)$, with $g(x) = 0.9 \cdot x^2 + 1.3 \cdot x - 0.7$.
|
||||||
|
|
||||||
|
Write a program that determines if a point $(x,y)$ lies on parabola $(\m{P})$ or not. The input is provided by two decimal numbers in the sequence $x,y$. The program must output `yes`, if the point lies on the parabola, otherwise `no`. Use datatype `double` for all variables and numbers used in the calculation of $g(x)$.
|
||||||
|
|
||||||
|
You will notice that a straight forward approach (comparing for equality) does not work, i.e., for some points that clearly should be on parabola $g$ such an approach returns result `no`.
|
||||||
|
|
||||||
|
_Hint_: Look at the difference between the exact values of the function and the values that your program calculates. Change the program so that it works properly for all points the submission system uses as test input without hard-coding the points. Expect an epsilon within the range $\[ 10^{-6}, 10^{-3}]\$. Experiment yourself to find the epsilon required to pass the test cases.
|
||||||
|
|
||||||
|
**Note**: Output only with `std::cout << "no" << std::endl;` or `std::cout << "yes" << std::endl;`, as the autograder will only accept output that exactly matches `yes\n` or `no\n`. For all other messages, use `std::cerr` as in:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
std::cerr << "This is a test message\n"
|
||||||
|
```
|
||||||
|
|
||||||
|
Those will be ignored by the autograder.
|
@@ -1,54 +0,0 @@
|
|||||||
#+TITLE: Task 2: Point on Parabola?
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
Consider a parabola \((\m{P})\) defined as \(y = g(x)\), with \(g(x) = 0.9 \cdot x^2 + 1.3 \cdot x - 0.7\).
|
|
||||||
|
|
||||||
Write a program that determines if a point \((x,y)\) lies on parabola \((\m{P})\) or not. The input is provided by two decimal numbers in the sequence \(x,y\). The program must output =yes=, if the point lies on the parabola, otherwise =no=. Use datatype =double= for all variables and numbers used in the calculation of \(g(x)\).
|
|
||||||
|
|
||||||
You will notice that a straight forward approach (comparing for equality) does not work, i.e., for some points that clearly should be on parabola $g$ such an approach returns result =no=.
|
|
||||||
|
|
||||||
/Hint/: Look at the difference between the exact values of the function and the values that your program calculates. Change the program so that it works properly for all points the submission system uses as test input without hard-coding the points. Expect an epsilon within the range \([ 10^{-6}, 10^{-3}]\)$. Experiment yourself to find the epsilon required to pass the test cases.
|
|
||||||
|
|
||||||
**Note**: Output only with =std::cout << "no" << std::endl;= or =std::cout << "yes" << std::endl;=, as the autograder will only accept output that exactly matches =yes\n= or =no\n=. For all other messages, use =std::cerr= as in:
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
std::cerr << "This is a test message\n"
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
Those will be ignored by the autograder.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
|
|
||||||
double x = 0; // x inputed by user
|
|
||||||
double yin = 0; // y inputed by user
|
|
||||||
double ycon = 0; // y control
|
|
||||||
double emax = 0.0001;
|
|
||||||
double emin = -0.0001;
|
|
||||||
|
|
||||||
std::cin >> x;
|
|
||||||
std::cin >> yin;
|
|
||||||
|
|
||||||
ycon = 0.9 * x * x + 1.3 * x - 0.7;
|
|
||||||
|
|
||||||
std::cerr << ycon;
|
|
||||||
std::cerr << yin - ycon;
|
|
||||||
|
|
||||||
if (yin == ycon || (yin - ycon <= emax && yin - ycon >= emin))
|
|
||||||
std::cout << "yes";
|
|
||||||
else
|
|
||||||
std::cout << "no";
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
25
Informatik_I/Exercise_4/Task_2/main.cpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
double x = 0; // x inputed by user
|
||||||
|
double yin = 0; // y inputed by user
|
||||||
|
double ycon = 0; // y control
|
||||||
|
double emax = 0.0001;
|
||||||
|
double emin = -0.0001;
|
||||||
|
|
||||||
|
std::cin >> x;
|
||||||
|
std::cin >> yin;
|
||||||
|
|
||||||
|
ycon = 0.9 * x * x + 1.3 * x - 0.7;
|
||||||
|
|
||||||
|
std::cerr << ycon;
|
||||||
|
std::cerr << yin - ycon;
|
||||||
|
|
||||||
|
if (yin == ycon || (yin - ycon <= emax && yin - ycon >= emin))
|
||||||
|
std::cout << "yes";
|
||||||
|
else
|
||||||
|
std::cout << "no";
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
16
Informatik_I/Exercise_4/Task_3/README.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# Task
|
||||||
|
|
||||||
|
Implement the following rounding function that rounds a 64-bit floating point number (type `double`) to the nearest 32-bit integer (type `int`). You may assume that the type `double` complies with the IEEE standard 754. The function is only required to work correctly if the nearest integer is in the value range of the type `int`, otherwise, the return value of the function is undefined.
|
||||||
|
|
||||||
|
**Note: Usage of library rounding functions (standard or others) is not allowed.**
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// PRE: x is roundable to a number in the value range of type @int@
|
||||||
|
// POST: return value is the integer nearest to x, or the one further
|
||||||
|
// away from 0 if x lies right in between two integers.
|
||||||
|
int round_number(double x);
|
||||||
|
```
|
||||||
|
|
||||||
|
Write your solution in `rounding.h`.
|
||||||
|
|
||||||
|
_Hint_: In `C++`, when you convert a `float` or `double` to an `int`, the fractional part gets cut off (truncated). Think about how you can use the truncated number to solve the exercise.
|
@@ -1,41 +0,0 @@
|
|||||||
#+TITLE: Task 3: Rounding
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
Implement the following rounding function that rounds a 64-bit floating point number (type =double=) to the nearest 32-bit integer (type =int=). You may assume that the type =double= complies with the IEEE standard 754. The function is only required to work correctly if the nearest integer is in the value range of the type =int=, otherwise, the return value of the function is undefined.
|
|
||||||
|
|
||||||
**Note: Usage of library rounding functions (standard or others) is not allowed.**
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
// PRE: x is roundable to a number in the value range of type @int@
|
|
||||||
// POST: return value is the integer nearest to x, or the one further
|
|
||||||
// away from 0 if x lies right in between two integers.
|
|
||||||
int round_number(double x);
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
Write your solution in =rounding.h=.
|
|
||||||
|
|
||||||
/Hint/: In =C++=, when you convert a =float= or =double= to an =int=, the fractional part gets cut off (truncated). Think about how you can use the truncated number to solve the exercise.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// PRE: x is roundable to a number in the value range of type int
|
|
||||||
// POST: return value is the integer nearest to x, or the one further
|
|
||||||
// away from 0 if x lies right in between two integers.
|
|
||||||
int round_number(double x) {
|
|
||||||
int res;
|
|
||||||
if (x < 0)
|
|
||||||
res = x - 0.5;
|
|
||||||
else
|
|
||||||
res = x + 0.5;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
13
Informatik_I/Exercise_4/Task_3/rounding.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// PRE: x is roundable to a number in the value range of type int
|
||||||
|
// POST: return value is the integer nearest to x, or the one further
|
||||||
|
// away from 0 if x lies right in between two integers.
|
||||||
|
int round_number(double x) {
|
||||||
|
int res;
|
||||||
|
if (x < 0)
|
||||||
|
res = x - 0.5;
|
||||||
|
else
|
||||||
|
res = x + 0.5;
|
||||||
|
return res;
|
||||||
|
}
|
7
Informatik_I/Exercise_4/Task_4/README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Task
|
||||||
|
|
||||||
|
Write a program that performs the binary expansion for a given decimal input number $x$, where $0 \leq x < 2$. Use the algorithm presented in the lecture. The program must output the first $16$ digits of the number in the format: $b_0, b_1, b_2, ... , b_15$.
|
||||||
|
|
||||||
|
_Important_ Always print all $16$ digits, even the trailing zeros. Do not normalize or round the number.
|
||||||
|
|
||||||
|
You can structure your program into functions to avoid code repetition. Do not forget to annotate functions with pre- and post conditions.
|
@@ -1,47 +0,0 @@
|
|||||||
#+TITLE: Task 4: Binary Expansion
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
Write a program that performs the binary expansion for a given decimal input number \(x\), where \(0 \leq x < 2\). Use the algorithm presented in the lecture. The program must output the first \(16\) digits of the number in the format: \(b_0, b_1, b_2, ... , b_15\).
|
|
||||||
|
|
||||||
/Important/ Always print all \(16\) digits, even the trailing zeros. Do not normalize or round the number.
|
|
||||||
|
|
||||||
You can structure your program into functions to avoid code repetition. Do not forget to annotate functions with pre- and post conditions.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
|
|
||||||
float i;
|
|
||||||
int n;
|
|
||||||
float d;
|
|
||||||
|
|
||||||
std::cin >> i;
|
|
||||||
|
|
||||||
if (i < 0 || i > 2)
|
|
||||||
return 0;
|
|
||||||
else {
|
|
||||||
n = i;
|
|
||||||
d = i - n;
|
|
||||||
|
|
||||||
std::cout << n << ".";
|
|
||||||
|
|
||||||
n = d;
|
|
||||||
d = 2 * (d - n);
|
|
||||||
|
|
||||||
for (int j = 1; j <= 15; ++j) {
|
|
||||||
n = d;
|
|
||||||
d = 2 * (d - n);
|
|
||||||
std::cout << n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
28
Informatik_I/Exercise_4/Task_4/main.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
float i;
|
||||||
|
int n;
|
||||||
|
float d;
|
||||||
|
|
||||||
|
std::cin >> i;
|
||||||
|
|
||||||
|
if (i < 0 || i > 2)
|
||||||
|
return 0;
|
||||||
|
else {
|
||||||
|
n = i;
|
||||||
|
d = i - n;
|
||||||
|
|
||||||
|
std::cout << n << ".";
|
||||||
|
|
||||||
|
n = d;
|
||||||
|
d = 2 * (d - n);
|
||||||
|
|
||||||
|
for (int j = 1; j <= 15; ++j) {
|
||||||
|
n = d;
|
||||||
|
d = 2 * (d - n);
|
||||||
|
std::cout << n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
50
Informatik_I/Exercise_5/Task_1/README.md
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
# Task
|
||||||
|
|
||||||
|
A perpetual calendar can be used to determine the weekday (Monday, ..., Sunday) of any given date. You may for example know that the Berlin wall came down on November 9, 1989, but what was the weekday? It was a Thursday. Or what is the weekday of the 1000th anniversary of the Swiss confederation, to be celebrated on August 1, 2291? It will be a Saturday. The task of this exercise is to write a program that outputs the weekday of a given input date.
|
||||||
|
|
||||||
|
Your program will read the date from the input. The input is given as three integer values in the following order: Day, month, year. First the program must validate the input. Pay attention to special cases of February (leap years!) also, the date must be greater or equal to the reference date. If a date is invalid output invalid date. If the date is valid, calculate the weekday of this day. This can be done by calculating how many days lie between the date in question and a reference date whose weekday is known. As reference date use Monday, 1st January 1900. Finally, output the weekday as one word in English.
|
||||||
|
|
||||||
|
**Approach**: The goal of this exercise is to learn the usage of functions. For that, we split the program into the following sub tasks given as function declarations. Your task is to **implement the provided functions** in the calendar.cpp file, so that they perform the action that is specified in their post condition.
|
||||||
|
|
||||||
|
**Important: There is a well-known mathematical function to calculate the weekday of a date. Using this function is an incorrect solution as it defeats the purpose of this exercise.**
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// PRE: a year greater or equal than 1900
|
||||||
|
// POST: returns whether that year was a leap year
|
||||||
|
bool is_leap_year(int year);
|
||||||
|
|
||||||
|
// PRE: a year greater or equal than 1900
|
||||||
|
// POST: returns the number of days in that year
|
||||||
|
int count_days_in_year(int year);
|
||||||
|
|
||||||
|
// PRE: a month between 1 and 12 and a year greater or equal than 1900
|
||||||
|
// POST: returns the number of days in the month of that year
|
||||||
|
int count_days_in_month(int month, int year);
|
||||||
|
|
||||||
|
// PRE: n/a
|
||||||
|
// POST: returns whether the given values represent a valid date
|
||||||
|
bool is_valid_date(int day, int month, int year);
|
||||||
|
|
||||||
|
// PRE: the given values represent a valid date
|
||||||
|
// POST: returns the number of days between January 1, 1900 and this date (excluding this date)
|
||||||
|
int count_days(int day, int month, int year);
|
||||||
|
|
||||||
|
// PRE: the given values represent a (potentially invalid) date
|
||||||
|
// POST: prints the weekday if the date is valid or "invalid date" otherwise.
|
||||||
|
// Everything must be printed in lowercase.
|
||||||
|
void print_weekday(int day, int month, int year);
|
||||||
|
```
|
||||||
|
|
||||||
|
To complete the task, you have to provide the definition of the aforementioned functions.
|
||||||
|
|
||||||
|
The `calendar.cpp` file contains skeletons of the functions to be implemented. The `main.cpp` file contains testing functions and the main function. In the main function, a menu is printed to select the function that has to be tested.
|
||||||
|
|
||||||
|
**Important** the main is not editable. Required functions must be implemented in `calendar.cpp`.
|
||||||
|
|
||||||
|
**Additional notes:**
|
||||||
|
|
||||||
|
1. For function arguments that do **not** fulfill the precondition, the behavior is undefined.
|
||||||
|
|
||||||
|
1. There are a few opportunities here to use switch statements. Use them if they result in better readable code.
|
||||||
|
|
||||||
|
1. A leap year is defined as follows: It is an integer multiple of 4, except for years evenly divisible by 100, which are not leap years unless evenly divisible by 400. (Source: [Wikipedia](https://en.wikipedia.org/wiki/Leap_year))
|
@@ -1,152 +0,0 @@
|
|||||||
#+TITLE: Task 1: Perpetual calendar
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
A perpetual calendar can be used to determine the weekday (Monday, ..., Sunday) of any given date. You may for example know that the Berlin wall came down on November 9, 1989, but what was the weekday? It was a Thursday. Or what is the weekday of the 1000th anniversary of the Swiss confederation, to be celebrated on August 1, 2291? It will be a Saturday. The task of this exercise is to write a program that outputs the weekday of a given input date.
|
|
||||||
|
|
||||||
Your program will read the date from the input. The input is given as three integer values in the following order: Day, month, year. First the program must validate the input. Pay attention to special cases of February (leap years!) also, the date must be greater or equal to the reference date. If a date is invalid output invalid date. If the date is valid, calculate the weekday of this day. This can be done by calculating how many days lie between the date in question and a reference date whose weekday is known. As reference date use /Monday, 1st January 1900/. Finally, output the weekday as one word in English.
|
|
||||||
|
|
||||||
**Approach**: The goal of this exercise is to learn the usage of functions. For that, we split the program into the following sub tasks given as function declarations. Your task is to **implement the provided functions** in the calendar.cpp file, so that they perform the action that is specified in their post condition.
|
|
||||||
|
|
||||||
**Important: There is a well-known mathematical function to calculate the weekday of a date. Using this function is an incorrect solution as it defeats the purpose of this exercise.**
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
// PRE: a year greater or equal than 1900
|
|
||||||
// POST: returns whether that year was a leap year
|
|
||||||
bool is_leap_year(int year);
|
|
||||||
|
|
||||||
// PRE: a year greater or equal than 1900
|
|
||||||
// POST: returns the number of days in that year
|
|
||||||
int count_days_in_year(int year);
|
|
||||||
|
|
||||||
// PRE: a month between 1 and 12 and a year greater or equal than 1900
|
|
||||||
// POST: returns the number of days in the month of that year
|
|
||||||
int count_days_in_month(int month, int year);
|
|
||||||
|
|
||||||
// PRE: n/a
|
|
||||||
// POST: returns whether the given values represent a valid date
|
|
||||||
bool is_valid_date(int day, int month, int year);
|
|
||||||
|
|
||||||
// PRE: the given values represent a valid date
|
|
||||||
// POST: returns the number of days between January 1, 1900 and this date (excluding this date)
|
|
||||||
int count_days(int day, int month, int year);
|
|
||||||
|
|
||||||
// PRE: the given values represent a (potentially invalid) date
|
|
||||||
// POST: prints the weekday if the date is valid or "invalid date" otherwise.
|
|
||||||
// Everything must be printed in lowercase.
|
|
||||||
void print_weekday(int day, int month, int year);
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
To complete the task, you have to provide the definition of the aforementioned functions.
|
|
||||||
|
|
||||||
The =calendar.cpp= file contains skeletons of the functions to be implemented. The =main.cpp= file contains testing functions and the main function. In the main function, a menu is printed to select the function that has to be tested.
|
|
||||||
|
|
||||||
**Important** the main is not editable. Required functions must be implemented in =calendar.cpp=.
|
|
||||||
|
|
||||||
**Additional notes:**
|
|
||||||
|
|
||||||
1. For function arguments that do **not** fulfill the precondition, the behavior is undefined.
|
|
||||||
|
|
||||||
1. There are a few opportunities here to use switch statements. Use them if they result in better readable code.
|
|
||||||
|
|
||||||
1. A leap year is defined as follows: It is an integer multiple of 4, except for years evenly divisible by 100, which are not leap years unless evenly divisible by 400. (Source: [[https://en.wikipedia.org/wiki/Leap_year][Wikipedia]])
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include "calendar.h"
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
// PRE: a year greater or equal than 1900
|
|
||||||
// POST: returns whether that year was a leap year
|
|
||||||
bool is_leap_year(int year) {
|
|
||||||
if (year >= 1900) {
|
|
||||||
if (year % 4 == 0 && year % 100 != 0)
|
|
||||||
return true;
|
|
||||||
else if (year % 4 == 0 && year % 400 == 0)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PRE: a year greater or equal than 1900
|
|
||||||
// POST: returns the number of days in that year
|
|
||||||
int count_days_in_year(int year) {
|
|
||||||
if (year >= 1900) {
|
|
||||||
if (is_leap_year(year) == true)
|
|
||||||
return 366;
|
|
||||||
return 365;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PRE: a month between 1 and 12 and a year greater or equal than 1900
|
|
||||||
// POST: returns the number of days in the month of that year
|
|
||||||
int count_days_in_month(int month, int year) {
|
|
||||||
if (year >= 1900 && month > 0 && month <= 12) {
|
|
||||||
if (is_leap_year(year) == true) {
|
|
||||||
if (month % 2 != 0 && month != 2 && month <= 7)
|
|
||||||
return 31;
|
|
||||||
else if (month % 2 == 0 && month > 7)
|
|
||||||
return 31;
|
|
||||||
else if (month == 2)
|
|
||||||
return 29;
|
|
||||||
else
|
|
||||||
return 30;
|
|
||||||
} else {
|
|
||||||
if (month % 2 != 0 && month != 2 && month <= 7)
|
|
||||||
return 31;
|
|
||||||
else if (month % 2 == 0 && month > 7)
|
|
||||||
return 31;
|
|
||||||
else if (month == 2)
|
|
||||||
return 28;
|
|
||||||
else
|
|
||||||
return 30;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PRE: n/a
|
|
||||||
// POST: returns whether the given values represent a valid date
|
|
||||||
bool is_valid_date(int day, int month, int year) {
|
|
||||||
if (day > 0 && day <= count_days_in_month(month, year) && month > 0 &&
|
|
||||||
month <= 12 && year >= 1900)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PRE: the given values represent a valid date
|
|
||||||
// POST: returns the number of days between January 1, 1900 and this date
|
|
||||||
// (excluding this date)
|
|
||||||
int count_days(int day, int month, int year) {
|
|
||||||
int res_day = 0;
|
|
||||||
if (is_valid_date(day, month, year) == true) {
|
|
||||||
for (int j = 1900; j < year; ++j) {
|
|
||||||
res_day += count_days_in_year(j);
|
|
||||||
}
|
|
||||||
for (int j = 1; j < month; ++j) {
|
|
||||||
res_day += count_days_in_month(j, year);
|
|
||||||
}
|
|
||||||
res_day += (day - 1);
|
|
||||||
}
|
|
||||||
return res_day;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PRE: the given values represent a (potentially invalid) date
|
|
||||||
// POST: prints the weekday if the date is valid or "invalid date" otherwise.
|
|
||||||
// Everything must be printed in lowercase.
|
|
||||||
void print_weekday(int day, int month, int year) {
|
|
||||||
if (is_valid_date(day, month, year) == true) {
|
|
||||||
std::string days[7] = {"sunday", "monday", "tuesday", "wednesday",
|
|
||||||
"thursday", "friday", "saturday"};
|
|
||||||
std::cout << days[((count_days(day, month, year) + 1) % 7)];
|
|
||||||
} else
|
|
||||||
std::cout << "invalid date";
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
90
Informatik_I/Exercise_5/Task_1/calendar.cpp
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
#include "calendar.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// PRE: a year greater or equal than 1900
|
||||||
|
// POST: returns whether that year was a leap year
|
||||||
|
bool is_leap_year(int year) {
|
||||||
|
if (year >= 1900) {
|
||||||
|
if (year % 4 == 0 && year % 100 != 0)
|
||||||
|
return true;
|
||||||
|
else if (year % 4 == 0 && year % 400 == 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRE: a year greater or equal than 1900
|
||||||
|
// POST: returns the number of days in that year
|
||||||
|
int count_days_in_year(int year) {
|
||||||
|
if (year >= 1900) {
|
||||||
|
if (is_leap_year(year) == true)
|
||||||
|
return 366;
|
||||||
|
return 365;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRE: a month between 1 and 12 and a year greater or equal than 1900
|
||||||
|
// POST: returns the number of days in the month of that year
|
||||||
|
int count_days_in_month(int month, int year) {
|
||||||
|
if (year >= 1900 && month > 0 && month <= 12) {
|
||||||
|
if (is_leap_year(year) == true) {
|
||||||
|
if (month % 2 != 0 && month != 2 && month <= 7)
|
||||||
|
return 31;
|
||||||
|
else if (month % 2 == 0 && month > 7)
|
||||||
|
return 31;
|
||||||
|
else if (month == 2)
|
||||||
|
return 29;
|
||||||
|
else
|
||||||
|
return 30;
|
||||||
|
} else {
|
||||||
|
if (month % 2 != 0 && month != 2 && month <= 7)
|
||||||
|
return 31;
|
||||||
|
else if (month % 2 == 0 && month > 7)
|
||||||
|
return 31;
|
||||||
|
else if (month == 2)
|
||||||
|
return 28;
|
||||||
|
else
|
||||||
|
return 30;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRE: n/a
|
||||||
|
// POST: returns whether the given values represent a valid date
|
||||||
|
bool is_valid_date(int day, int month, int year) {
|
||||||
|
if (day > 0 && day <= count_days_in_month(month, year) && month > 0 &&
|
||||||
|
month <= 12 && year >= 1900)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRE: the given values represent a valid date
|
||||||
|
// POST: returns the number of days between January 1, 1900 and this date
|
||||||
|
// (excluding this date)
|
||||||
|
int count_days(int day, int month, int year) {
|
||||||
|
int res_day = 0;
|
||||||
|
if (is_valid_date(day, month, year) == true) {
|
||||||
|
for (int j = 1900; j < year; ++j) {
|
||||||
|
res_day += count_days_in_year(j);
|
||||||
|
}
|
||||||
|
for (int j = 1; j < month; ++j) {
|
||||||
|
res_day += count_days_in_month(j, year);
|
||||||
|
}
|
||||||
|
res_day += (day - 1);
|
||||||
|
}
|
||||||
|
return res_day;
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRE: the given values represent a (potentially invalid) date
|
||||||
|
// POST: prints the weekday if the date is valid or "invalid date" otherwise.
|
||||||
|
// Everything must be printed in lowercase.
|
||||||
|
void print_weekday(int day, int month, int year) {
|
||||||
|
if (is_valid_date(day, month, year) == true) {
|
||||||
|
std::string days[7] = {"sunday", "monday", "tuesday", "wednesday",
|
||||||
|
"thursday", "friday", "saturday"};
|
||||||
|
std::cout << days[((count_days(day, month, year) + 1) % 7)];
|
||||||
|
} else
|
||||||
|
std::cout << "invalid date";
|
||||||
|
}
|
8
Informatik_I/Exercise_5/Task_2/README.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
_This task is a text-based task. You do not need to write any program/C++ file: the answer should be written in functions.cpp._
|
||||||
|
|
||||||
|
Consider the functions implemented in `functions.cpp`. For each function, add proper pre- and post-conditions.
|
||||||
|
|
||||||
|
- If no pre-condition is needed, you can simply write "n/a".
|
||||||
|
- The post-condition does not have to be a mathematical formula, e.g. it can be an informal description, but it must completely characterize the results and effects of the functions depending on the provided parameters.
|
||||||
|
|
||||||
|
**Note**: For the purposes of this task, you can ignore overflows.
|
@@ -1,57 +0,0 @@
|
|||||||
#+TITLE: Task 2: Pre- and post-conditions
|
|
||||||
|
|
||||||
/This task is a text-based task. You do not need to write any program/C++ file: the answer should be written in functions.cpp./
|
|
||||||
|
|
||||||
Consider the functions implemented in =functions.cpp=. For each function, add proper pre- and post-conditions.
|
|
||||||
|
|
||||||
- If no pre-condition is needed, you can simply write "n/a".
|
|
||||||
- The post-condition does not have to be a mathematical formula, e.g. it can be an informal description, but it must completely characterize the results and effects of the functions depending on the provided parameters.
|
|
||||||
|
|
||||||
**Note**: For the purposes of this task, you can ignore overflows.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
// PRE: x > 0
|
|
||||||
// POST: returns n^x
|
|
||||||
int f1(int n, int x) {
|
|
||||||
int res = 1;
|
|
||||||
for (; x > 0; x--) {
|
|
||||||
res *= n;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PRE: n > 0
|
|
||||||
// POST: returns number of devisions by 10 with n
|
|
||||||
int f2(int n) {
|
|
||||||
int i = 0;
|
|
||||||
while (n > 0) {
|
|
||||||
n = n / 10;
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PRE: n > 1
|
|
||||||
// POST: returns a bool to determine if n is prime
|
|
||||||
bool f3(int n) {
|
|
||||||
int i = 2;
|
|
||||||
for (; n % i != 0; ++i);
|
|
||||||
return n == i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PRE: n is square number
|
|
||||||
// POST: returns root of n
|
|
||||||
int f4(int n) {
|
|
||||||
int i = 0;
|
|
||||||
while (i * i != n) {
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
38
Informatik_I/Exercise_5/Task_2/functions.cpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// PRE: x > 0
|
||||||
|
// POST: returns n^x
|
||||||
|
int f1(int n, int x) {
|
||||||
|
int res = 1;
|
||||||
|
for (; x > 0; x--) {
|
||||||
|
res *= n;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRE: n > 0
|
||||||
|
// POST: returns number of devisions by 10 with n
|
||||||
|
int f2(int n) {
|
||||||
|
int i = 0;
|
||||||
|
while (n > 0) {
|
||||||
|
n = n / 10;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRE: n > 1
|
||||||
|
// POST: returns a bool to determine if n is prime
|
||||||
|
bool f3(int n) {
|
||||||
|
int i = 2;
|
||||||
|
for (; n % i != 0; ++i);
|
||||||
|
return n == i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRE: n is square number
|
||||||
|
// POST: returns root of n
|
||||||
|
int f4(int n) {
|
||||||
|
int i = 0;
|
||||||
|
while (i * i != n) {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
28
Informatik_I/Exercise_5/Task_3/README.md
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
_This task is a text based task. You do not need to write any program/C++ file: the answer should be written in main.md (and might include code fragments if questions ask for them)._
|
||||||
|
|
||||||
|
# Task:
|
||||||
|
|
||||||
|
What are the problems (if any) with the following functions? Fix them and find appropriate [pre-](https://en.wikipedia.org/wiki/Precondition) and [postconditions](https://en.wikipedia.org/wiki/Postcondition).
|
||||||
|
|
||||||
|
1. function is_even:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
|
||||||
|
bool is_even(int i) {
|
||||||
|
if (i % 2 == 0) return true;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
1. function invert:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
double invert(int x) {
|
||||||
|
double result;
|
||||||
|
if (x != 0) {
|
||||||
|
result = 1.0 / x;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Hint**: The C++ compiler does not protect you from certain types of errors. Therefore, even if you run a program in Code Expert, it is not guaranteed that the behaviour you observe is the “real” one. We have prepared a [program tracing handout](https://lec.inf.ethz.ch/ifmp/2023/guides/tracing/intro.html) that shows how to execute a program with a pen and paper and which conditions indicate bugs in the executed program not caught by the C++ compiler.
|
@@ -1,74 +0,0 @@
|
|||||||
#+TITLE: Fixing Functions
|
|
||||||
|
|
||||||
/This task is a text based task. You do not need to write any program/C++ file: the answer should be written in main.md (and might include code fragments if questions ask for them)./
|
|
||||||
|
|
||||||
* Task:
|
|
||||||
|
|
||||||
What are the problems (if any) with the following functions? Fix them and find appropriate [[https://en.wikipedia.org/wiki/Precondition][pre-]] and [[https://en.wikipedia.org/wiki/Postcondition][postconditions]].
|
|
||||||
|
|
||||||
1. function is_even:
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
bool is_even(int i) {
|
|
||||||
if (i % 2 == 0) return true;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
1. function invert:
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
|
|
||||||
double invert(int x) {
|
|
||||||
double result;
|
|
||||||
if (x != 0) {
|
|
||||||
result = 1.0 / x;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
**Hint**: The C++ compiler does not protect you from certain types of errors. Therefore, even if you run a program in Code Expert, it is not guaranteed that the behaviour you observe is the “real” one. We have prepared a [[https://lec.inf.ethz.ch/ifmp/2023/guides/tracing/intro.html][programming tracing handout]] that shows how to execute a program with a pen and paper and which conditions indicate bugs in the executed program not caught by the C++ compiler.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src markdown
|
|
||||||
Please write your solution here.
|
|
||||||
For your convenience we have added a template for your answers below.
|
|
||||||
|
|
||||||
Note: Remember to also describe the problem of the function.
|
|
||||||
|
|
||||||
# Function `c++|is_even`:
|
|
||||||
|
|
||||||
The problem with this function is that it does not return a bool if the number `i` is uneven.
|
|
||||||
|
|
||||||
```c++
|
|
||||||
// PRE: n/a
|
|
||||||
// POST: returns true if i is even. If not it returns false.
|
|
||||||
bool is_even(int i) {
|
|
||||||
if (i % 2 == 0) return true;
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
# Function `c++|invert`:
|
|
||||||
|
|
||||||
The problem with this function is
|
|
||||||
|
|
||||||
```c++
|
|
||||||
// PRE: x is positive or negative but not zero.
|
|
||||||
// POST: returns inverse with respect to multiplication of x.
|
|
||||||
double invert(int x) {
|
|
||||||
// TODO: Fix code below.
|
|
||||||
if (x != 0) {
|
|
||||||
return 1.0 / x;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
std::cout << "0 has no inverse!";
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
35
Informatik_I/Exercise_5/Task_3/main.md
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
Please write your solution here.
|
||||||
|
For your convenience we have added a template for your answers below.
|
||||||
|
|
||||||
|
Note: Remember to also describe the problem of the function.
|
||||||
|
|
||||||
|
# Function `c++|is_even`:
|
||||||
|
|
||||||
|
The problem with this function is that it does not return a bool if the number `i` is uneven.
|
||||||
|
|
||||||
|
```c++
|
||||||
|
// PRE: n/a
|
||||||
|
// POST: returns true if i is even. If not it returns false.
|
||||||
|
bool is_even(int i) {
|
||||||
|
if (i % 2 == 0) return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
# Function `c++|invert`:
|
||||||
|
|
||||||
|
The problem with this function is
|
||||||
|
|
||||||
|
```c++
|
||||||
|
// PRE: x is positive or negative but not zero.
|
||||||
|
// POST: returns inverse with respect to multiplication of x.
|
||||||
|
double invert(int x) {
|
||||||
|
// TODO: Fix code below.
|
||||||
|
if (x != 0) {
|
||||||
|
return 1.0 / x;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
std::cout << "0 has no inverse!";
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
@@ -1,139 +1,64 @@
|
|||||||
#+TITLE: Task 4: Run-length encoding
|
Task
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Task
|
Run-length encoding is a simple data compression technique that represents $N$ consecutive identical values $W$ (a run) by a tuple ($N,W$). This method is applied for image compression, for instance. Example:
|
||||||
|
|
||||||
Run-length encoding is a simple data compression technique that represents \(N\) consecutive identical values \(W\) (a run) by a tuple (\(N,W\)). This method is applied for image compression, for instance. Example:
|

|
||||||
|
|
||||||
[[./pictures/encode_decode.png]]
|
Write a program that implements run-length encoding and decoding of a byte sequence as described above. By a byte, we mean an integer value in the range $\[ 0; 255 \]$. Use the stepwise refinement method to implement the program. **Your solution must consist of at least two functions, encode and decode. Please implement them in `run_length.cpp`.**
|
||||||
|
|
||||||
Write a program that implements run-length encoding and decoding of a byte sequence as described above. By a byte, we mean an integer value in the range \([ 0; 255 ]\). Use the stepwise refinement method to implement the program. **Your solution must consist of at least two functions, encode and decode. Please implement them in =run_length.cpp=.**
|
|
||||||
|
|
||||||
The _input_ is structured as follows:
|
The _input_ is structured as follows:
|
||||||
|
|
||||||
1. One integer that determines whether to encode: \(0\) or decode: \(1\).
|
1. One integer that determines whether to encode: $0$ or decode: $1$.
|
||||||
1. Byte sequence to be encoded or decoded (of arbitrary length). If a value outside the range \([ 0; 255 ]\) (except $-1$) is entered, output =error= and stop the en- or decoding.
|
1. Byte sequence to be encoded or decoded (of arbitrary length). If a value outside the range $\[ 0; 255 \]$(except $-1$) is entered, output `error` and stop the en- or decoding.
|
||||||
1. Integer -1 signaling the end of the byte sequence. Any extra input should be ignored.
|
1. Integer -1 signaling the end of the byte sequence. Any extra input should be ignored.
|
||||||
|
|
||||||
For the example above, the inputs are:
|
For the example above, the inputs are:
|
||||||
|
|
||||||
**Encode:**
|
**Encode:**
|
||||||
|
|
||||||
#+begin_src shell
|
```sh
|
||||||
0 42 42 85 85 85 85 172 172 172 13 13 42 -1
|
0 42 42 85 85 85 85 172 172 172 13 13 42 -1
|
||||||
#+end_src
|
```
|
||||||
|
|
||||||
**Decode:**
|
**Decode:**
|
||||||
|
|
||||||
#+begin_src shell
|
```sh
|
||||||
1 2 42 4 85 3 172 2 13 1 42 -1
|
1 2 42 4 85 3 172 2 13 1 42 -1
|
||||||
#+end_src
|
```
|
||||||
|
|
||||||
_The output_ is expected on a single line in the following format:
|
_The output_ is expected on a single line in the following format:
|
||||||
|
|
||||||
1. A start value to indicate the begin of the sequence: either \(0\) for decoded values or \(1\) for encoded values.
|
1. A start value to indicate the begin of the sequence: either $0$ for decoded values or $1$ for encoded values.
|
||||||
1. The values that make up the encoded or decoded byte sequence.
|
1. The values that make up the encoded or decoded byte sequence.
|
||||||
1. The value \(-1\) to indicate the end of the sequence.
|
1. The value $-1$ to indicate the end of the sequence.
|
||||||
|
|
||||||
I.e., you can 'reuse' the output as the input.
|
I.e., you can 'reuse' the output as the input.
|
||||||
|
|
||||||
**Note 1):** As the encoded sequence must be a _byte_ sequence, runs of length 256 or longer need to be split into multiple runs of length 255 at most.
|
**Note 1):** As the encoded sequence must be a _byte_ sequence, runs of length 256 or longer need to be split into multiple runs of length 255 at most.
|
||||||
|
|
||||||
**Note 2):** The first input element (the integer that determines wether to encode or decode), is already consumed by the =main=, that calls either the encode or decode function.
|
**Note 2):** The first input element (the integer that determines wether to encode or decode), is already consumed by the `main`, that calls either the encode or decode function.
|
||||||
|
|
||||||
**Note 3):** Your output should not be followed by new line (i.e., do not use =std::endl= or =\n= at the end of your printout)
|
**Note 3):** Your output should not be followed by new line (i.e., do not use `std::endl` or `\n` at the end of your printout)
|
||||||
|
|
||||||
**Note 4):** The program will print your output (the result of the decoding or encoding), surrounded by asterisks. You don't have to worry about them, the autograder can safely recognize your solution
|
**Note 4):** The program will print your output (the result of the decoding or encoding), surrounded by asterisks. You don't have to worry about them, the autograder can safely recognize your solution
|
||||||
|
|
||||||
**Note 5):** Output only what is strictly required (the encoded or decoded sequence). The autograder will only accept output that exactly matches the expected result. For all other messages, use =std::cerr= as in:
|
**Note 5):** Output only what is strictly required (the encoded or decoded sequence). The autograder will only accept output that exactly matches the expected result. For all other messages, use `std::cerr` as in:
|
||||||
|
|
||||||
#+begin_src cpp
|
```cpp
|
||||||
std::cerr << "This is a test message\n"
|
std::cerr << "This is a test message\n"
|
||||||
#+end_src
|
```
|
||||||
|
|
||||||
Those will be ignored by the autograder.
|
Those will be ignored by the autograder.
|
||||||
|
|
||||||
**Special cases**: While decoding a byte sequence two special cases can occur. These must be handled as follows:
|
**Special cases**: While decoding a byte sequence two special cases can occur. These must be handled as follows:
|
||||||
|
|
||||||
1. If a byte sequence ends in the middle of a tuple, stop printing the output of en- or decoding and output =error=.
|
1. If a byte sequence ends in the middle of a tuple, stop printing the output of en- or decoding and output `error`.
|
||||||
1. Tuples of run-length 0 are possible. For such tuples, output only the leading indicator (\(0\)/\(1\)) and the trailing \(-1\).
|
1. Tuples of run-length 0 are possible. For such tuples, output only the leading indicator ($0$/$1$) and the trailing $-1$.
|
||||||
|
|
||||||
**Hint**: You can enter multiple numbers at once separated with a space on the console, e.g, you can copy and paste the above examples, and sequentially read them using multiple =std::cin >> _var_= calls.
|
**Hint**: You can enter multiple numbers at once separated with a space on the console, e.g, you can copy and paste the above examples, and sequentially read them using multiple `std::cin >> _var_` calls.
|
||||||
|
|
||||||
Also note that, even though the program's output and the user input are both shown in the same console, they are processed separately internally, so you do not have to worry that the two will mix: if your program outputs something to the console before reading another value, it will only read the user input and not the previous output value. See the Calculator code in the Lecture 4 handout for an example of reading input and producing output in a loop.
|
Also note that, even though the program's output and the user input are both shown in the same console, they are processed separately internally, so you do not have to worry that the two will mix: if your program outputs something to the console before reading another value, it will only read the user input and not the previous output value. See the Calculator code in the Lecture 4 handout for an example of reading input and producing output in a loop.
|
||||||
|
|
||||||
Finally, part of the correctness for this task is the termination of your code, so pay attention to this. The autograder may not catch these kinds of mistakes.
|
Finally, part of the correctness for this task is the termination of your code, so pay attention to this. The autograder may not catch these kinds of mistakes.
|
||||||
|
|
||||||
**Restrictions**: using a vector, an array or a similar data structure in any part of your code is not allowed and would result in 0 points.
|
**Restrictions**: using a vector, an array or a similar data structure in any part of your code is not allowed and would result in 0 points.
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include "run_length.h"
|
|
||||||
|
|
||||||
void encode() {
|
|
||||||
int i;
|
|
||||||
int c;
|
|
||||||
int count;
|
|
||||||
std::cin >> i;
|
|
||||||
std::cout << 1 << " ";
|
|
||||||
while (i != -1) {
|
|
||||||
count = 0;
|
|
||||||
c = i;
|
|
||||||
while (i == c && i >= 0 && i <= 255) {
|
|
||||||
++count;
|
|
||||||
std::cin >> i;
|
|
||||||
if (count == 255) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i < -1 || i > 255) {
|
|
||||||
if (count == 0) {
|
|
||||||
std::cout << "error";
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
std::cout << count << " ";
|
|
||||||
std::cout << c << " ";
|
|
||||||
std::cout << "error";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout << count << " ";
|
|
||||||
std::cout << c << " ";
|
|
||||||
}
|
|
||||||
std::cout << -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void decode() {
|
|
||||||
int i;
|
|
||||||
int count;
|
|
||||||
std::cin >> count;
|
|
||||||
std::cin >> i;
|
|
||||||
std::cout << 0 << " ";
|
|
||||||
while (count != -1) {
|
|
||||||
if (i < -1 || i > 255) {
|
|
||||||
std::cout << "error";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (count < -1 || count > 255) {
|
|
||||||
std::cout << "error";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int j = 0; j < count; ++j) {
|
|
||||||
std::cout << i << " ";
|
|
||||||
}
|
|
||||||
std::cin >> count;
|
|
||||||
if (count != -1)
|
|
||||||
std::cin >> i;
|
|
||||||
if (i == -1) {
|
|
||||||
std::cout << "error";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout << -1;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
63
Informatik_I/Exercise_5/Task_4/run_length.cpp
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#include "run_length.h"
|
||||||
|
|
||||||
|
void encode() {
|
||||||
|
int i;
|
||||||
|
int c;
|
||||||
|
int count;
|
||||||
|
std::cin >> i;
|
||||||
|
std::cout << 1 << " ";
|
||||||
|
while (i != -1) {
|
||||||
|
count = 0;
|
||||||
|
c = i;
|
||||||
|
while (i == c && i >= 0 && i <= 255) {
|
||||||
|
++count;
|
||||||
|
std::cin >> i;
|
||||||
|
if (count == 255) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i < -1 || i > 255) {
|
||||||
|
if (count == 0) {
|
||||||
|
std::cout << "error";
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
std::cout << count << " ";
|
||||||
|
std::cout << c << " ";
|
||||||
|
std::cout << "error";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << count << " ";
|
||||||
|
std::cout << c << " ";
|
||||||
|
}
|
||||||
|
std::cout << -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void decode() {
|
||||||
|
int i;
|
||||||
|
int count;
|
||||||
|
std::cin >> count;
|
||||||
|
std::cin >> i;
|
||||||
|
std::cout << 0 << " ";
|
||||||
|
while (count != -1) {
|
||||||
|
if (i < -1 || i > 255) {
|
||||||
|
std::cout << "error";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (count < -1 || count > 255) {
|
||||||
|
std::cout << "error";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int j = 0; j < count; ++j) {
|
||||||
|
std::cout << i << " ";
|
||||||
|
}
|
||||||
|
std::cin >> count;
|
||||||
|
if (count != -1)
|
||||||
|
std::cin >> i;
|
||||||
|
if (i == -1) {
|
||||||
|
std::cout << "error";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << -1;
|
||||||
|
}
|
@@ -1,140 +0,0 @@
|
|||||||
#+TITLE: Task 1: Const and reference types
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
/This task is a text based task. You do not need to write any program/C++ file: the answer should be written in main.md (and might include code fragments if questions ask for them)./
|
|
||||||
|
|
||||||
*Note:* You can safely ignore any undefined behavior due to integer overflows.
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
Consider the following functions:
|
|
||||||
|
|
||||||
1.
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
int foo(int i) {
|
|
||||||
return ++i;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
2.
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
int foo(const int i) {
|
|
||||||
return ++i;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
3.
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
int foo(int& i) {
|
|
||||||
return ++i;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
4.
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
int& foo(int i) {
|
|
||||||
return ++i;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
5.
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
const int& foo(int& i) {
|
|
||||||
return ++i;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
For each function, answer the following questions:
|
|
||||||
|
|
||||||
a) Does the function attempt to modify const variables? If so, give the reason why (max. 15 words).
|
|
||||||
|
|
||||||
If no, answer the following (otherwise put N/A):
|
|
||||||
|
|
||||||
b) Variable scopes: are the output and side effects of the function well-defined, i.e., free of undefined behavior? If not, give the reason why (max. 15 words).
|
|
||||||
|
|
||||||
c) If the answer in b) is yes, give the precise post condition for the corresponding function foo. In particular, indicate what side effects the function may have.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src md
|
|
||||||
1.
|
|
||||||
|
|
||||||
```c++
|
|
||||||
int foo(int i) {
|
|
||||||
return ++i;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
a) Yes and no, if depends if the input is assigend to a constant or not but generally no.
|
|
||||||
|
|
||||||
b) Yes
|
|
||||||
|
|
||||||
c) `foo` returns the increment by 1 of `i`. The side effect of this function is, that the variable `i` is only accessible inside the function `foo`. To make `i` accessible, one has to use the function as follows: `int b = foo(i)`
|
|
||||||
|
|
||||||
|
|
||||||
2.
|
|
||||||
```c++
|
|
||||||
int foo(const int i) {
|
|
||||||
return ++i;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
a) Yes, since `i` is defined as a constant variable the function foo increments `i`.
|
|
||||||
|
|
||||||
b) N/A
|
|
||||||
|
|
||||||
c) N/A
|
|
||||||
|
|
||||||
|
|
||||||
3.
|
|
||||||
|
|
||||||
```c++
|
|
||||||
int foo(int& i) {
|
|
||||||
return ++i;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
a) Yes and no, it depends if the reference is assigned to a constant variable or not but generally no.
|
|
||||||
|
|
||||||
b) Yes
|
|
||||||
|
|
||||||
c) The variable `i` which is referenced to another variable outside of the function will be incremented. Since it's referenced the variable is not only accessible within the function.
|
|
||||||
|
|
||||||
|
|
||||||
4.
|
|
||||||
|
|
||||||
```c++
|
|
||||||
int& foo(int i) {
|
|
||||||
return ++i;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
a) Yes and no, if depends if the input is assigend to a constant or not but generally no.
|
|
||||||
|
|
||||||
b) Yes
|
|
||||||
|
|
||||||
c) Since the whole function is a referenced, the variable which is inputted into the function will not be incremented. Instead the variable `i` will only be in scope of the function `foo` so as in task two, to use the function one has to use it as follows: `int b = foo(i);`
|
|
||||||
|
|
||||||
5.
|
|
||||||
|
|
||||||
```c++
|
|
||||||
const int& foo(int& i) {
|
|
||||||
return ++i;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
a) Yes and no, if depends if the input is assigend to a constant or not but generally no.
|
|
||||||
|
|
||||||
b) Yes
|
|
||||||
|
|
||||||
c) This function will increment the input and return it as a constant.
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
@@ -1,100 +0,0 @@
|
|||||||
#+TITLE: Task 2: Number of Occurrences
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
Write a program using a vector to perform the following:
|
|
||||||
|
|
||||||
1. Read integer values from standard input and insert them in a vector until a negative integer is encountered;
|
|
||||||
1. Read an extra non-negative integer n;
|
|
||||||
1. Output the number of occurrences of n encountered during phase (1).
|
|
||||||
|
|
||||||
Your solution *must* split the sub-tasks of the program (reading the vector, counting the occurrences, and maybe other sub-tasks) into separate functions. Those functions *must* use the proper reference parameters to access the vector.
|
|
||||||
|
|
||||||
*Note:* we consider solutions as incorrect if they use library functions (or data structures) beyond the ones discussed in the lectures so far to perform the actual computation.
|
|
||||||
|
|
||||||
* Input
|
|
||||||
|
|
||||||
A sequence of of integer values containing a single negative integer, in penultimate position.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
#+begin_src shell
|
|
||||||
0 1 1 2 3 5 8 13 21 -1 1
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
* Output
|
|
||||||
|
|
||||||
The number of occurrences of the last integer in the sequence before the negative integer.
|
|
||||||
|
|
||||||
Example: for the input given above, the number of occurrences of 1 before -1 occurs is
|
|
||||||
|
|
||||||
#+begin_src shell
|
|
||||||
2
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
* Reminder - How to use vector
|
|
||||||
|
|
||||||
To define a vector (for example of integer numbers), you can use the following constructor
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
std::vector<int> my vec = std::vector<int>(length, init_value);
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
You can insert element at the back of the vector with:
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
my_vec.push_back(number);
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
To access the elements of the vector you have to use the random access ([]) operator:
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
std::cout << "First element: " << my_vec[0];
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
void readvec(std::vector<int>& vec, int& num) {
|
|
||||||
vec.push_back(num);
|
|
||||||
}
|
|
||||||
|
|
||||||
int occvec(std::vector<int>& vec, int& num, int& count) {
|
|
||||||
for (unsigned long i = 0; i < vec.size(); ++i) {
|
|
||||||
if (vec[i] == num)
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
|
|
||||||
int i;
|
|
||||||
int con;
|
|
||||||
int count = 0;
|
|
||||||
std::vector<int> vec;
|
|
||||||
|
|
||||||
std::cin >> i;
|
|
||||||
|
|
||||||
while (i >= 0) {
|
|
||||||
readvec(vec, i);
|
|
||||||
std::cin >> i;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cin >> con;
|
|
||||||
|
|
||||||
occvec(vec, con, count);
|
|
||||||
|
|
||||||
std::cout << count;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
@@ -1,100 +0,0 @@
|
|||||||
#+TITLE: Task 3: [Hidden tests] Sorting by Swapping
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
* Task
|
|
||||||
|
|
||||||
Write a program that performs the following:
|
|
||||||
|
|
||||||
1. Read a non-negative integer
|
|
||||||
2. Read \(n\) integers
|
|
||||||
3. Sort the \(n\) integers read in (2) in decreasing order. To that end, we suggest the following method:
|
|
||||||
a. Store the \(n\) integers in a vector
|
|
||||||
b. Iterate through the vector, compare each pair of adjacent values and swap them if they are in the wrong order (i.e increasing order)
|
|
||||||
c. Repeat step (2) as long as swap are performed.
|
|
||||||
4. Output the sorted values.
|
|
||||||
|
|
||||||
Your solution *must* isolate the sorting functionality of the program into a separate function, using a reference parameter with the right constness to access the vector. Other sub-tasks of the program may be isolated as well.
|
|
||||||
|
|
||||||
*Note:* We consider solutions as incorrect if they use library functions (or data structures) beyond the ones discussed in the lectures so far to perform the actual computation. In particular, library sorting functions are forbidden as they defeat the purpose of the exercise.
|
|
||||||
|
|
||||||
*Note:* The function you implement *must* use pass by reference.
|
|
||||||
|
|
||||||
* Input
|
|
||||||
|
|
||||||
A sequence of integers, preceded by its length.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
#+begin_src shell
|
|
||||||
7 3 8 6 3 4 6 5
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
* Output
|
|
||||||
|
|
||||||
The input sequence, minus the length, in decreasing order. The integers are separated by a single space.
|
|
||||||
|
|
||||||
#+begin_src shell
|
|
||||||
8 6 6 5 4 3 3
|
|
||||||
#+end_src
|
|
||||||
* Hidden test cases
|
|
||||||
|
|
||||||
This exercise has some hidden test cases. You will see whether these tests passed or failed, but you will not see the test input or the expected output.
|
|
||||||
|
|
||||||
* Persistent input
|
|
||||||
|
|
||||||
To help you in testing your code, you can enter your custom test input in input.txt. When running the program, you can let CodeExpert read the input from the file.
|
|
||||||
|
|
||||||
Write some program input in input.txt. Run the program as usual. Type f (no spaces) in the terminal window and press Enter. The program will use the contents of input.txt as input. Using this feature is entirely optional and does not affect your score.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include <iostream>
|
|
||||||
// Enable vectors
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
void readvec(std::vector<int>& vec, int& length) {
|
|
||||||
for (int j = 0; j < length; ++j) {
|
|
||||||
int i;
|
|
||||||
std::cin >> i;
|
|
||||||
vec[j] = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sortvec(std::vector<int>& vec, int& length) {
|
|
||||||
for (int j = length - 1; j > 0; --j) {
|
|
||||||
for (int i = 0; i < j; ++i) {
|
|
||||||
if (vec[i] < vec[i+1]) {
|
|
||||||
int prev = vec[i+1];
|
|
||||||
int next = vec[i];
|
|
||||||
vec[i] = prev;
|
|
||||||
vec[i+1] = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void printvec(std::vector<int>& vec, int& length) {
|
|
||||||
for (int j = 0; j < length; ++j)
|
|
||||||
std::cout << vec[j] << " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
int length;
|
|
||||||
std::cin >> length;
|
|
||||||
|
|
||||||
std::vector<int> values(length);
|
|
||||||
|
|
||||||
readvec(values, length);
|
|
||||||
|
|
||||||
sortvec(values, length);
|
|
||||||
|
|
||||||
printvec(values, length);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
@@ -1,279 +0,0 @@
|
|||||||
#+TITLE: Task 4: Vector and matrix operations
|
|
||||||
#+AUTHOR: JirR02
|
|
||||||
|
|
||||||
*Note:* All occurrences of the word /vector/ in this assignment without an explicit =std::= prefix mean vector in the mathematical sense.
|
|
||||||
|
|
||||||
*Task:*
|
|
||||||
|
|
||||||
Write a program that implements the multiplication of integer vectors and matrices using =std::vectors=. The program must support the following three possible operations:
|
|
||||||
|
|
||||||
1. Dot product of two vectors (also called scalar product or inner product)
|
|
||||||
1. Matrix-vector product (application of a matrix to a column vector)
|
|
||||||
1. Matrix product
|
|
||||||
|
|
||||||
Implement the following program structure:
|
|
||||||
|
|
||||||
1. Query for the two operands from the input: the left operand first, then the right operand.
|
|
||||||
1. If none of the three operators described above can be applied, output error then end the program.
|
|
||||||
1. If the two operands have mismatched sizes (e.g. the dot product of a 2D vector and a 3D vector), output error then end the program.
|
|
||||||
1. Output the result of the operation then end the program.
|
|
||||||
|
|
||||||
Note: We already provide a partial implementation of this program in =main.cpp=.
|
|
||||||
|
|
||||||
*Recommendations:*
|
|
||||||
|
|
||||||
1. We provide functions to read and write matrices, vectors, and scalars in io.h. Use them!
|
|
||||||
1. Use one dimensional =std::vectors= to represent vectors and two dimensional =std::vectors= to represent matrices.
|
|
||||||
1. Use functions to implement the three different operations. Use references with proper constness to access =std::vectors= from functions.
|
|
||||||
1. You may assume that all input vector/matrices have non-zero dimensions, and that input will not contain values big enough to cause overflow.
|
|
||||||
|
|
||||||
*Format:*
|
|
||||||
|
|
||||||
The format to represent scalars/vectors/matrices in input/output is the following:
|
|
||||||
|
|
||||||
1. A character among s, v and m to denote whether the data represent a scalar, a vector or a matrix (scalar cannot occur in input for this task).
|
|
||||||
2. A sequence of integers giving the dimensions of the value:
|
|
||||||
a. Nothing for scalar
|
|
||||||
b. A single integer giving the length for vectors
|
|
||||||
c. Two integers giving respectively the number of rows and the number of columns for matrices
|
|
||||||
3. A new line
|
|
||||||
4. A sequence of integers giving the content of the value:
|
|
||||||
a. The scalar itself for scalars
|
|
||||||
b. The content of the vector in order for vectors, on a single line
|
|
||||||
c. The content of the matrix in row-major order for matrices (the content of the first row in column order first, then the second row, etc). Each row should be placed on a distinct line.
|
|
||||||
|
|
||||||
Note: Check =io.h= and =io.cpp=. The functions provided there can handle a large part of the input/output format.
|
|
||||||
|
|
||||||
* Examples
|
|
||||||
|
|
||||||
*Dot product of two 3D vectors*
|
|
||||||
|
|
||||||
#+begin_src shell
|
|
||||||
Left operand
|
|
||||||
v 3
|
|
||||||
1 2 3
|
|
||||||
Right operand
|
|
||||||
v 3
|
|
||||||
3 2 1
|
|
||||||
s
|
|
||||||
10
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
*Multiply 3x2 matrix by 2D vector*
|
|
||||||
|
|
||||||
#+begin_src shell
|
|
||||||
Left operand
|
|
||||||
m 3 2
|
|
||||||
1 2
|
|
||||||
3 4
|
|
||||||
5 6
|
|
||||||
Right operand
|
|
||||||
v 2
|
|
||||||
2 1
|
|
||||||
v 3
|
|
||||||
4 10 16
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
*Multiply 2x4 matrix 4x3 matrix*
|
|
||||||
|
|
||||||
#+begin_src shell
|
|
||||||
Left operand
|
|
||||||
m 2 4
|
|
||||||
1 2 3 4
|
|
||||||
5 6 7 8
|
|
||||||
Right operand
|
|
||||||
m 4 3
|
|
||||||
12 11 10
|
|
||||||
9 8 7
|
|
||||||
6 5 4
|
|
||||||
3 2 1
|
|
||||||
m 2 3
|
|
||||||
60 50 40
|
|
||||||
180 154 128
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
*Multiply 2x3 matrix by 4D vector*
|
|
||||||
|
|
||||||
#+begin_src shell
|
|
||||||
Left operand
|
|
||||||
m 2 3
|
|
||||||
1 2 3
|
|
||||||
4 5 6
|
|
||||||
Right operand
|
|
||||||
v 4
|
|
||||||
4 3 2 1
|
|
||||||
error
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
*Note:* The scalar values should be returned only by scalar products. Even if a matrix-vector multiplication or a matrix-matrix multiplication results in a single value, it should be represented by a single-element vector or matrix. Similarly, if the result of a matrix-matrix multiplication looks like a vector, it should still be represented as a matrix, with one dimension equal to 1.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
#include <iostream>
|
|
||||||
// Enable std::vectors
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "io.h"
|
|
||||||
|
|
||||||
using vec = std::vector<int>;
|
|
||||||
using mat = std::vector<vec>;
|
|
||||||
|
|
||||||
// POST: result of dot product of v1 and v2 is printed to standard output,
|
|
||||||
// or "error" if dimensions are not compatible
|
|
||||||
|
|
||||||
void vector_scalar_product(const vec& v, const int& s) {
|
|
||||||
vec res;
|
|
||||||
res = v;
|
|
||||||
for (unsigned long j = 0; j < v.size(); ++j)
|
|
||||||
res[j] = v[j] * s;
|
|
||||||
print_vector(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
void matrix_scalar_product(const mat& m, const int& s) {
|
|
||||||
mat res;
|
|
||||||
res = m;
|
|
||||||
for (unsigned long j = 0; j < m.size(); ++j) {
|
|
||||||
for (unsigned long i = 0; i < m[0].size(); ++i)
|
|
||||||
res[j][i] = m[j][i] * s;
|
|
||||||
}
|
|
||||||
print_matrix(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
void dot_product(const vec& v1, const vec& v2) {
|
|
||||||
int res = 0;
|
|
||||||
if (v1.size() == v2.size()) {
|
|
||||||
for (unsigned long j = 0; j < v1.size(); ++j)
|
|
||||||
res += (v1[j] * v2[j]);
|
|
||||||
print_scalar(res);
|
|
||||||
} else {
|
|
||||||
std::cout << "error";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void matrix_vector_product(const mat& m, const vec& v) {
|
|
||||||
vec res;
|
|
||||||
if (v.size() == m[0].size()) {
|
|
||||||
for (unsigned long j = 0; j < m.size(); ++j) {
|
|
||||||
int k = 0;
|
|
||||||
for (unsigned long i = 0; i < m[0].size(); ++i) {
|
|
||||||
k += m[j][i] * v[i];
|
|
||||||
}
|
|
||||||
res.push_back(k);
|
|
||||||
}
|
|
||||||
print_vector(res);
|
|
||||||
} else {
|
|
||||||
std::cout << "error";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void matrix_product(const mat& m1, const mat& m2) {
|
|
||||||
mat res(m1.size(), vec(m2[0].size()));
|
|
||||||
if (m1[0].size() == m2.size()) {
|
|
||||||
for (unsigned long i = 0; i < m1.size(); ++i) {
|
|
||||||
for (unsigned long j = 0; j < m2.size(); ++j) {
|
|
||||||
for (unsigned long k = 0; k < m2[0].size(); ++k) {
|
|
||||||
int l = m1[i][j] * m2[j][k];
|
|
||||||
res[i][k] += l;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print_matrix(res);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::cout << "error";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
std::cout << "Left operand" << std::endl;
|
|
||||||
char left_type;
|
|
||||||
std::cin >> left_type;
|
|
||||||
|
|
||||||
if (left_type == 'v') {
|
|
||||||
// left operand is vector
|
|
||||||
|
|
||||||
// get vector from input
|
|
||||||
vec left_operand;
|
|
||||||
read_vector(left_operand);
|
|
||||||
|
|
||||||
// get right operand type
|
|
||||||
std::cout << "Right operand" << std::endl;
|
|
||||||
char right_type;
|
|
||||||
std::cin >> right_type;
|
|
||||||
|
|
||||||
if (right_type == 's') {
|
|
||||||
// right operand is a scalar => compute scalar product
|
|
||||||
|
|
||||||
// get scalar from input
|
|
||||||
int s;
|
|
||||||
std::cin >> s;
|
|
||||||
|
|
||||||
// compute vector scalar product
|
|
||||||
vector_scalar_product(left_operand, s);
|
|
||||||
} else if (right_type == 'v') {
|
|
||||||
// right operand is a vector => compute dot product
|
|
||||||
|
|
||||||
// get vector from input
|
|
||||||
vec right_operand;
|
|
||||||
read_vector(right_operand);
|
|
||||||
|
|
||||||
// compute dot product
|
|
||||||
dot_product(left_operand, right_operand);
|
|
||||||
} else {
|
|
||||||
std::cout << "error";
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (left_type == 'm') {
|
|
||||||
// left operand is matrix
|
|
||||||
|
|
||||||
// get matrix from input
|
|
||||||
mat left_operand;
|
|
||||||
read_matrix(left_operand);
|
|
||||||
|
|
||||||
// get right operand type
|
|
||||||
std::cout << "Right operand" << std::endl;
|
|
||||||
char right_type;
|
|
||||||
std::cin >> right_type;
|
|
||||||
|
|
||||||
if (right_type == 's') {
|
|
||||||
// right operand is a scalar => compute scalar product
|
|
||||||
|
|
||||||
// get scalar from input
|
|
||||||
int s;
|
|
||||||
std::cin >> s;
|
|
||||||
|
|
||||||
// compute matrix scalar product
|
|
||||||
matrix_scalar_product(left_operand, s);
|
|
||||||
} else if (right_type == 'v') {
|
|
||||||
// right operand is a vector => compute dot product
|
|
||||||
|
|
||||||
// get vector from input
|
|
||||||
vec right_operand;
|
|
||||||
read_vector(right_operand);
|
|
||||||
|
|
||||||
// compute matrix vector product
|
|
||||||
matrix_vector_product(left_operand, right_operand);
|
|
||||||
} else if (right_type == 'm') {
|
|
||||||
// right operand is a matrix => compute matrix vector product
|
|
||||||
|
|
||||||
// get matrix from input
|
|
||||||
mat right_operand;
|
|
||||||
read_matrix(right_operand);
|
|
||||||
|
|
||||||
// compute matrix product
|
|
||||||
matrix_product(left_operand, right_operand);
|
|
||||||
} else {
|
|
||||||
std::cout << "error";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
std::cout << "error";
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
@@ -1,81 +0,0 @@
|
|||||||
#+title: Task 1: Recursive function analysis
|
|
||||||
|
|
||||||
#+author: JirR02
|
|
||||||
/This task is a text based task. You do not need to write any
|
|
||||||
program/C++ file: the answer should be written in main.md (and might
|
|
||||||
include code fragments if questions ask for them)./
|
|
||||||
|
|
||||||
* Task
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: task
|
|
||||||
:END:
|
|
||||||
For each of the following recursive functions:
|
|
||||||
|
|
||||||
1.
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
bool f(const int n) {
|
|
||||||
if (n == 0) return false;
|
|
||||||
return !f(n - 1);
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
2. [@2]
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
void g(const int n) {
|
|
||||||
if (n == 0) {
|
|
||||||
std::cout << "*";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
g(n - 1);
|
|
||||||
g(n - 1);
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
1) Formulate pre- and post conditions.
|
|
||||||
|
|
||||||
2) Show that the function terminates. *Hint*: No proof expected, proceed
|
|
||||||
similar as with the lecture example of the factorial function.
|
|
||||||
|
|
||||||
3) Determine the number of functions calls as mathematical function of
|
|
||||||
parameter n. *Note*: include the first non-recursive function call.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: solution
|
|
||||||
:END:
|
|
||||||
#+begin_src markdown
|
|
||||||
1. i) Pre- and post conditions
|
|
||||||
|
|
||||||
```c++
|
|
||||||
// PRE: n is a positive integer
|
|
||||||
// POST: returns true if n is even and false if n is odd.
|
|
||||||
```
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
2) [@2] The function =plain|f= terminates because it has a termination
|
|
||||||
condition. It will terminate once n reaches 0. If the number is
|
|
||||||
negative, it will be in an infinite loop.
|
|
||||||
|
|
||||||
3) \(\text{Calls}_{f}(n) = n\)
|
|
||||||
|
|
||||||
2. [@2]
|
|
||||||
1) Pre- and post conditions
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
// PRE: n is a positive integer
|
|
||||||
// POST: print 2^n *
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
2) [@2] The function =plain|g= terminates because it has a termination
|
|
||||||
condition. It will terminate once n reaches 0. If the number is
|
|
||||||
negative, it will be in an infinite loop.
|
|
||||||
|
|
||||||
3) \(\text{Calls}_{g}(n) = 2^n\)
|
|
||||||
|
|
||||||
#+begin_example
|
|
||||||
|
|
||||||
___
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|
||||||
#+end_example
|
|
@@ -1,92 +0,0 @@
|
|||||||
#+title: Task 2: Bitstrings up to n
|
|
||||||
|
|
||||||
#+author: JirR02
|
|
||||||
* Task
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: task
|
|
||||||
:END:
|
|
||||||
Your task is implementing the function =all_bitstrings_up_to_n= in
|
|
||||||
=solution.cpp= which generates all bitstrings up to length \(n\) in
|
|
||||||
ascending order. The generated bitstrings are returned in a
|
|
||||||
=std::vector<std::string>=.
|
|
||||||
|
|
||||||
*Note*: It is *mandatory* to use *recursive implementation* for this
|
|
||||||
task.
|
|
||||||
|
|
||||||
* Input & Output
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: input-output
|
|
||||||
:END:
|
|
||||||
The program first prompts you to enter the bitstring length \(n\). It
|
|
||||||
then calls the function =all_bitstrings_up_to_n= and prints the returned
|
|
||||||
bitstrings to the console.
|
|
||||||
|
|
||||||
** Example
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: example
|
|
||||||
:END:
|
|
||||||
#+begin_src sh
|
|
||||||
Bitstring length: 2
|
|
||||||
Bitstrings up to length 2
|
|
||||||
|
|
||||||
0
|
|
||||||
1
|
|
||||||
00
|
|
||||||
01
|
|
||||||
10
|
|
||||||
11
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
*Note*: The empty line after Bitstrings up to length 2 is actually the
|
|
||||||
bitstring of length \(0\).
|
|
||||||
|
|
||||||
*Note*: The autograder will only accept output that exactly matches the
|
|
||||||
expected result. Therefore, do not output anything with =std::cout= in
|
|
||||||
the =all_bitstrings_up_to_n= function. For debugging messages, use
|
|
||||||
=std::cerr= as in:
|
|
||||||
|
|
||||||
#+begin_src cpp
|
|
||||||
std::cerr << "This is a test message." << std::endl;
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
Those will be ignored by the autograder.
|
|
||||||
|
|
||||||
* Solution
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: solution
|
|
||||||
:END:
|
|
||||||
#+begin_src cpp
|
|
||||||
#include "solution.h"
|
|
||||||
using vec = std::vector<std::string>;
|
|
||||||
using str = std::string;
|
|
||||||
|
|
||||||
void bitstring(vec &res, str ram, int l) {
|
|
||||||
if (l == 0) {
|
|
||||||
res.push_back(ram);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bitstring(res, ram + "0", l - 1);
|
|
||||||
bitstring(res, ram + "1", l - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void recursion(int count, int n, vec &res) {
|
|
||||||
if (count > n)
|
|
||||||
return;
|
|
||||||
|
|
||||||
bitstring(res, "", count);
|
|
||||||
recursion(count + 1, n, res);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec all_bitstrings_up_to_n(int n) {
|
|
||||||
vec res;
|
|
||||||
|
|
||||||
recursion(0, n, res);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Made by JirR02 in Switzerland 🇨🇭
|
|