Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Peter Gerwinski
hp
Commits
bd2ab4cc
Commit
bd2ab4cc
authored
4 years ago
by
Peter Gerwinski
Browse files
Options
Downloads
Patches
Plain Diff
Neue Übungsaufgabe 14.1.2021
parent
0e6f468f
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
20210114/aufgabe-3.c
+10
-25
10 additions, 25 deletions
20210114/aufgabe-3.c
20210114/hp-uebung-20210114.pdf
+0
-0
0 additions, 0 deletions
20210114/hp-uebung-20210114.pdf
20210114/hp-uebung-20210114.tex
+95
-1
95 additions, 1 deletion
20210114/hp-uebung-20210114.tex
with
105 additions
and
26 deletions
20210114/aufgabe-3.c
+
10
−
25
View file @
bd2ab4cc
#include
<stdint.h>
#include
<stdio.h>
#include
<avr/io.h>
#include
<string.h>
#include
<avr/interrupt.h>
uint8_t
counter
=
1
;
void
insert_into_string
(
char
src
,
char
*
target
,
int
pos
)
uint8_t
leds
=
0
;
ISR
(
TIMER0_COMP_vect
)
{
if
(
counter
==
0
)
{
leds
=
(
leds
+
1
)
%
8
;
PORTC
=
leds
<<
4
;
}
counter
++
;
}
void
init
(
void
)
{
{
cli
();
int
len
=
strlen
(
target
);
TCCR0
=
(
1
<<
CS01
)
|
(
1
<<
CS00
);
for
(
int
i
=
pos
;
i
<
len
;
i
++
)
TIMSK
=
1
<<
OCIE0
;
target
[
i
+
1
]
=
target
[
i
];
sei
();
target
[
pos
]
=
src
;
DDRC
=
0x70
;
}
}
int
main
(
void
)
int
main
(
void
)
{
{
init
()
;
char
test
[
100
]
=
"Hochshule Bochum"
;
while
(
1
)
insert_into_string
(
'c'
,
test
,
5
);
;
/* do nothing */
printf
(
"%s
\n
"
,
test
);
return
0
;
return
0
;
}
}
This diff is collapsed.
Click to expand it.
20210114/hp-uebung-20210114.pdf
+
0
−
0
View file @
bd2ab4cc
No preview for this file type
This diff is collapsed.
Click to expand it.
20210114/hp-uebung-20210114.tex
+
95
−
1
View file @
bd2ab4cc
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
% Attribution-ShareAlike 3.0 Unported License along with this
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
% document. If not, see <http://creativecommons.org/licenses/>.
% README: Zahlensysteme, Mikrocontroller,
LED-Blinkmuster
% README: Zahlensysteme, Mikrocontroller,
Einfügen in Strings (Ergänzung)
\documentclass
[a4paper]
{
article
}
\documentclass
[a4paper]
{
article
}
...
@@ -161,6 +161,100 @@
...
@@ -161,6 +161,100 @@
\end{itemize}
\end{itemize}
\end{minipage}
\end{minipage}
\exercise
{
Einfügen in Strings (Ergänzung)
}
Diese Aufgabe ist eine Ergänzung von Aufgabe 2 der Übung vom 10.
\
Dezember
2020 um die Teilaufgaben (e), (f) und (g). Für den "`Klausur-Modus"' können
Sie die Teilaufgaben (a) bis (d) als "`bereits gelöst"' voraussetzen.
Wir betrachten das folgende Programm (
\gitfile
{
hp
}{
2020ws/20210114
}{
aufgabe-3.c
}
):
% \begin{lstlisting}[style=numbered]
\begin{lstlisting}
#include <stdio.h>
#include <string.h>
void insert
_
into
_
string (char src, char *target, int pos)
{
int len = strlen (target);
for (int i = pos; i < len; i++)
target[i+1] = target[i];
target[pos] = src;
}
int main (void)
{
char test[100] = "Hochshule Bochum";
insert
_
into
_
string ('c', test, 5);
printf ("
%s\n", test);
return 0;
}
\end{lstlisting}
Die Ausgabe des Programms lautet:
\lstinline
[style=terminal]
{
Hochschhhhhhhhhhh
}
\begin{enumerate}
[
\quad
(a)]
\item
Erklären Sie, wie die Ausgabe zustandekommt.
% \points{3}
% \workspace{12}
\item
Schreiben Sie die Funktion
\lstinline
|insert
_
into
_
string()| so um,
daß sie den Buchstaben
\lstinline
{
src
}
an der Stelle
\lstinline
{
pos
}
in den String
\lstinline
{
target
}
einfügt.
\par
Die Ausgabe des Programms müßte dann
\lstinline
[style=terminal]
{
Hochschule Bochum
}
lauten.
% \points{2}
% \workspace{13}
\item
Was kann passieren, wenn Sie die Zeile
\lstinline
{
char test[100] = "Hochshule Bochum";
}
\\
durch
\lstinline
{
char test[] = "Hochshule Bochum";
}
ersetzen?
Begründen Sie Ihre Antwort.
% \points{2}
% \workspace{10}
\item
Was kann passieren, wenn Sie die Zeile
\lstinline
{
char test[100] = "Hochshule Bochum";
}
\\
durch
\lstinline
{
char *test = "Hochshule Bochum";
}
ersetzen?
Begründen Sie Ihre Antwort.
% \points{2}
% \workspace{10}
\item
Schreiben Sie eine Funktion
\lstinline
{
void insert
_
into
_
string
_
sorted (char src, char *target)
}
,
die voraussetzt, daß der String
\lstinline
{
target
}
alphabetisch sortiert ist
und den Buchstaben
\lstinline
{
src
}
an der alphabetisch richtigen Stelle
einfügt. Diese Funktion darf die bereits vorhandene Funktion
\lstinline
|insert
_
into
_
string()| aufrufen.
\\
\points
{
4
}
\par
Zum Testen eignen sich die folgenden Zeilen im Hauptprogramm:
\begin{lstlisting}
[gobble=8]
char test[100] = "";
insert
_
into
_
string
_
sorted ('c', test);
insert
_
into
_
string
_
sorted ('a', test);
insert
_
into
_
string
_
sorted ('d', test);
insert
_
into
_
string
_
sorted ('b', test);
\end{lstlisting}
Danach sollte
\lstinline
{
test[]
}
die Zeichenfolge
\lstinline
{
"abcd"
}
enthalten.
% \workspace{14}
\item
Wie schnell (Landau-Symbol in Abhängigkeit von der Länge
$
n
$
des Strings)
arbeitet Ihre Funktion
\lstinline
{
void insert
_
into
_
string
_
sorted (char src, char *target)
}
?
Begründen Sie Ihre Antwort.
\points
{
1
}
% \workspace{10}
\item
Beschreiben Sie -- in Worten oder als C-Quelltext --, wie man die Funktion
\\
\lstinline
{
void insert
_
into
_
string
_
sorted (char src, char *target)
}
so gestalten kann,
\\
daß sie in
$
\mathcal
{
O
}
(
\log
n
)
$
arbeitet.
\points
{
3
}
% \workspace{35}
\end{enumerate}
\begin{flushright}
\begin{flushright}
\textit
{
Viel Erfolg!
}
\textit
{
Viel Erfolg!
}
\end{flushright}
\end{flushright}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment