Skip to content

Commit bafbb0e

Browse files
authored
[Appendix] Added Fizzbuzz (#151)
* Added fizzbuzz.cpp for clean code apendix Added file fizzbuzz.cpp for the clean code appendix, purposefully written without clean code conventions. Additionally added fizzbuzz_pretty.cpp; Same program, but with indents, code conventions, comments etc. * Updated coding_style and fizzbuzz_pretty Updated coding_style paragraph about indenting and tabs; updated fizzbuzz_pretty to include some more examples of coding practices described in coding_style * created empty files for the compile process, updated .gitignore to not include compiled files and folders generated by IDEs and the compile process * renamed folder that was misspelled * Renamed loads of files to fit the new structure * Fixed parsing of latex escape characters. Fixed missing file for include, renamed incorrectly named file * updated texlive version * Updated checkout and texlive this time with correct config scheme * [hotfix] this function causes the build workflow to fail so i commented it out * corrected directory structure * typo upsiii * renamed includes * Moved files; changed files/fizzbuzz.cpp * Added fizzbuzz.cpp for clean code apendix Added file fizzbuzz.cpp for the clean code appendix, purposefully written without clean code conventions. Additionally added fizzbuzz_pretty.cpp; Same program, but with indents, code conventions, comments etc. * Updated coding_style and fizzbuzz_pretty Updated coding_style paragraph about indenting and tabs; updated fizzbuzz_pretty to include some more examples of coding practices described in coding_style * Moved files; changed files/fizzbuzz.cpp * updated workflows * added new workflow * corrected small typos ---------
1 parent 7a0386b commit bafbb0e

5 files changed

Lines changed: 127 additions & 21 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Build and Run Tests
2+
3+
on:
4+
push: {}
5+
workflow_dispatch: {}
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
timeout-minutes: 30
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
- uses: xu-cheng/texlive-action@v2
15+
with:
16+
scheme: full # Consider changing to 'basic' or 'medium' if possible
17+
run: |
18+
apk add make
19+
apk add g++
20+
apk add zip
21+
make script zip
22+
- uses: actions/upload-artifact@v4
23+
with:
24+
name: PDF_Test
25+
path: vorkurs.pdf
26+
27+
check-links:
28+
runs-on: ubuntu-latest
29+
needs: build
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Download compiled PDF
35+
uses: actions/download-artifact@v4
36+
with:
37+
name: PDF_Test
38+
path: .
39+
40+
- name: Install pdfgrep
41+
run: sudo apt-get update && sudo apt-get install -y pdfgrep
42+
43+
- name: Extract and Check URLs
44+
run: |
45+
urls=$(pdfgrep -o -P 'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)' vorkurs.pdf | sort -u)
46+
error_count=0
47+
48+
for url in $urls; do
49+
echo "Checking URL: $url"
50+
51+
if [[ ! "$url" =~ ^https:// ]]; then
52+
echo "ERROR: URL is not HTTPS: $url"
53+
error_count=$((error_count + 1))
54+
continue
55+
fi
56+
57+
if ! curl -Isf --fail-early --connect-timeout 10 "$url" > /dev/null 2>&1; then
58+
curl_error=$(curl -Isf --fail-early --connect-timeout 10 "$url" 2>&1 > /dev/null)
59+
if [[ $curl_error == *"Failed to connect"* ]]; then
60+
echo "ERROR: Connection failed: $url"
61+
elif [[ $curl_error == *"Could not resolve host"* ]]; then
62+
echo "ERROR: DNS resolution failed: $url"
63+
elif [[ $curl_error == *"SSL certificate problem"* ]]; then
64+
echo "ERROR: Initial SSL certificate problem: $url"
65+
else
66+
echo "ERROR: Failed to access: $url (curl error: $curl_error)"
67+
fi
68+
if ! openssl s_client -connect "$(echo "$url" | sed 's/https\?:\/\///' | cut -d/ -f1):443" -servername "$(echo "$url" | sed 's/https\?:\/\///' | cut -d/ -f1)" 2>/dev/null </dev/null | openssl x509 -noout; then
69+
echo " -> CERTIFICATE ERROR DETECTED!"
70+
fi
71+
72+
error_count=$((error_count + 1))
73+
fi
74+
done
75+
76+
if [ "$error_count" -gt 0 ]; then
77+
echo "::error::Found $error_count broken or insecure links!"
78+
exit 1
79+
fi
80+
shell: bash

appendix/coding_style.tex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
Wie genau eingerückt werden sollte, darüber scheiden sich die Geister.
2424
Man kann mit mehreren Leerzeichen oder durch Tabulatoren einrücken.
2525
Empfehlenswert ist auf jeden Fall, mehrere gleichförmige „Ebenen“ zu
26-
haben (z.B. 4, 8, 12, \dots\ Leerzeichen zu Beginn der Zeile). Eine
26+
haben (z.B. 4, 8, 12, \dots\ Leerzeichen zu Beginn der Zeile). Tabulatoren
27+
haben den Vorteil, dass sie, in der Theorie, über Programme hinweg “standartisiert” sind,
28+
weswegen man denselben Code in mehreren Editoren öffnen und
29+
überall problemlos mit Tabulatoren arbeiten kann. Eine
2730
Faustregel für gut lesbare Einrückung ist, immer wenn man eine
2831
geschweifte Klammer öffnet, eine Ebene tiefer einzurücken und immer,
2932
wenn man eine geschweifte Klammer schließt, wieder eine Ebene zurück zu

files/fizzbuzz.cpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
#include <iostream>
22

3-
int main() {
4-
int i=1;
5-
while (i<100){
6-
if (i%3==0){
7-
if (i%5==0){
8-
std::cout<<"FizzBuzz"<<std::endl;
9-
}else{
10-
std::cout<<"Fizz"<<std::endl;
11-
}}else if(i%5==0){
12-
if(i%3==0){
13-
std::cout<<"FizzBuzz"<<std::endl;
14-
}else{
15-
std::cout<<"Buzz"<<std::endl;
16-
}}else{
17-
std::cout<<i<<std::endl;
18-
}
19-
i=i+1;
3+
int main() {int i=1;
4+
while (i<=100){if (i%3==0){if (i%5==0){
5+
std::cout<<"FizzBuzz"<<std::endl;}else{
6+
std::cout<<"Fizz"<<std::endl;}}else if(i%5==0){if(i%3==0){
7+
std::cout<<"FizzBuzz"<<std::endl;}else{
8+
std::cout<<"Buzz"<<std::endl;}}else{
9+
std::cout<<i<<std::endl;}i=i+1;
2010
}return 0;}

files/fizzbuzz_pretty.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <string>
2+
#include <iostream>
3+
int main() {
4+
std::string output = ""; //Wir kreieren eine Variable für den Output
5+
for(int i = 1; i <= 100; i++){ //Für alle Zahlen von 1 bis 100:
6+
output = "";
7+
if (i % 3 == 0) {
8+
output += "Fizz"; //Falls die Zahl durch 3 Teilbar ist, fügen wir dem Output "Fizz" hinzu
9+
}
10+
if (i % 5 == 0) {
11+
output += "Buzz"; //Falls die Zahl durch 5 Teilbar ist, fügen wir dem Output "Buzz" hinzu
12+
}
13+
/*
14+
if (i % 7 == 0) {
15+
output += "Bizz"; //Falls die Zahl durch 7 teilbar ist, fügen wir dem Output "Bizz" hinzu
16+
}
17+
if (i % 11 == 0) {
18+
output += "Biff"; //Falls die Zahl durch 11 teilbar ist, fügen wir dem Output "Biff" hinzu
19+
}
20+
*/
21+
if(output == ""){
22+
output = std::to_string(i); //Falls der Output danach immer noch leer ist, wird die Zahl zum Output
23+
}
24+
std::cout << output << std::endl; //Wir geben den Output aus
25+
}
26+
}
27+
28+
/*Sprich: Dieses Programm spielt das englische Kinderspiel "FizzBuzz"; Man sagt nacheinander jede Zahl, aber
29+
- wenn die Zahl durch 3 teilbar ist (3, 6,...), sagt man "Fizz"
30+
- wenn die Zahl durch 5 teilbar ist (5, 10,...), sagt man "Buzz"
31+
- Wenn die Zahl durch beides teilbar ist (15, 30,...), sagt man "FizzBuzz".
32+
Der auskommentierte Code dient dazu, das Spiel etwas "komplizierter" zu machen, indem man weitere Regeln hinzufügt.*/

lektionen/arrays_vectors.tex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
hoffentlich die Syntax klar:
1818
\inputcpp{array.cpp} % ToDo: Add this file
1919

20-
Es gibt einige Dinge, zu beachnten, wenn ihr mit Arrays arbeitet. Das
20+
21+
Es gibt einige Dinge, zu beachten, wenn ihr mit Arrays arbeitet. Das
2122
wichtigste ist oben schon genannt -- sich davon verwirren zu lassen, dass
2223
Indizes bei 0 anfangen und aus Versehen über das Array hinaus schreiben oder
2324
lesen ist ein so häufiger Fehler, dass er seinen eigenen Namen bekommen hat:
2425
„Off-by-one error“. Wichtig ist, dass der Compiler diesen Zugriff nicht
25-
verhindern wird! Das ist von daher eine sehr fiese Sache, als dass dieser
26+
verhindern wird! Das ist von daher eine sehr fiese Sache, da dieser
2627
Fehler auch beim Ausführen nicht immer Probleme machen wird -- aber manchmal
2728
lässt er auch euer Programm spontan abstürzen in einem so genannten
2829
\emph{segmentation fault}.
@@ -41,7 +42,7 @@
4142
die generelle Möglichkeit genannt.
4243

4344
\textbf{Praxis:}
44-
Wir wollen die Seite \url{http://www.ich-kann-mich-nicht-entscheiden.de/}
45+
Wir wollen die Seite \url{https://www.ich-kann-mich-nicht-entscheiden.de/}
4546
nachmachen und eine Entscheidungshilfe programmieren, die aus mehreren von der
4647
Nutzerin gegebenen Möglichkeiten eine per Zufall auswählt.
4748

0 commit comments

Comments
 (0)