Skip to content
Snippets Groups Projects
Commit 566c89cc authored by Stefan Gehr's avatar Stefan Gehr
Browse files

saying numbers

parent e2a95b98
Branches
No related tags found
No related merge requests found
...@@ -9,8 +9,12 @@ ...@@ -9,8 +9,12 @@
\usepackage{siunitx} \usepackage{siunitx}
\usepackage{ragged2e} \usepackage{ragged2e}
\usepackage{booktabs} \usepackage{booktabs}
\usepackage{algorithm}
\usepackage{algpseudocodex}
\usepackage{hyperref} \usepackage{hyperref}
\newcommand{\algorithmautorefname}{Algorithm}
\title{Solar Pump Control} \title{Solar Pump Control}
\subtitle{Arduino Project for the Arduino Block Course 2022} \subtitle{Arduino Project for the Arduino Block Course 2022}
\author{Engelmann, Mario\and Gehr, Stefan} \author{Engelmann, Mario\and Gehr, Stefan}
...@@ -94,7 +98,64 @@ and increments the queue. ...@@ -94,7 +98,64 @@ and increments the queue.
Both index variables get set back to zero in case they reach the the end of the queue. Both index variables get set back to zero in case they reach the the end of the queue.
\section{Saying Numbers} \section{Saying Numbers}
As our ``client'' only speaks German, we needed to implement the way numbers are read in that language.
First we implemented a function sayDigit(\(d\)) that plays the corresponding sound of the digit \(d\).
So ``eins'' for \(d=1\), ``zwei'' for \(d=2\), and so on.
Then for a few special cases we needed to create the function
sayPreNumber(\(n\)) that only says ``ein'' instead of ``eins'' for \(n=1\) and just calls our normal sayNumber(\(n\)) function otherwise.
This is necessary for cases like \(n=31\) which is read as ``EINunddreißig'' instead of ``EINSunddreißig''.
Another special fucntion is sayAftNumber(\(n\)) which only our normal sayNumber(\(\n\)) function if \(n\ne 0\).
It is necessary for numbers like 100, 200, 300, \dots,
as we want to say ``zweihundert'' for \(n=200\) and not ``zweihundertnull''.
\begin{algorithm}
\caption{Pseudocode implementation of the sayNumber function}
\label{alg:saynumber}
\begin{algorithmic}[1]
\Function{sayNumber}{\(n\)}
\If{\(n<0\)}
\Comment{negative number}
\State say(minus)
\State sayNumber(\(-n\))
\ElsIf{\(n < 10\)}
\Comment{1-digit number}
\State sayDigit(\(n\))
\ElsIf{\(n < 100\)}
\Comment{2-digit number}
\If{\(n=11\)}
\Comment{special case ELF}
\State say(elf)
\ElsIf{\(n=12\)}
\Comment{special case ZWÖLF}
\State say(zwölf)
\Else
\State tens \(\gets \lfloor n / 10 \rfloor\)
\State ones \(\gets n - 10 \times \text{tens}\)
\If{\(\text{ones}\ne 0\)}
\Comment{say the 1-digit first}
\State sayPreNumber(ones)
\If{\(\text{tens}\ge 2\)}
\Comment{UND only for numbers \(> 20\)}
\State say(und)
\EndIf
\EndIf
\If{\(\text{tens}=1\)}
\State say(zehn)
\ElsIf{\(\text{tens}=2\)}
\State say(zwanzig)
\ElsIf{\(\hdots\)}
\State \(\vdots\)
\EndIf
\EndIf
\Else
\Comment{3-digit number}
\State hundreds \(\gets \lfloor n / 100 \rfloor\)
\State sayPreNumber(hundreds)
\State sayAftNumber(\(n - 100 \times \text{hundreds}\)
\EndIf
\end{algorithmic}
\end{algorithm}
Finally our main function sayNumber(\(n\)) goes thorugh all the possible cases.
A peudocode implementation of it can be seen in \autoref{alg:saynumber}.
\section{Temperature} \section{Temperature}
%\listoffigures %\listoffigures
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment