Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PROG-material-public
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yue Wu
PROG-material-public
Commits
ca18a472
Commit
ca18a472
authored
1 year ago
by
dali662d
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
ac386c70
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Sonderuebung/WiSe23-24/SU10_2024_01_09/01_taskmanager_2.f95
+555
-0
555 additions, 0 deletions
Sonderuebung/WiSe23-24/SU10_2024_01_09/01_taskmanager_2.f95
with
555 additions
and
0 deletions
Sonderuebung/WiSe23-24/SU10_2024_01_09/01_taskmanager_2.f95
0 → 100644
+
555
−
0
View file @
ca18a472
module
zeit_mod
implicit
none
private
public
::
zeit
,
GET
,
operator
(
<
),
operator
(
+
),
operator
(
-
),
zeit_string
,
zeit_null
type
zeit
private
integer
::
h
integer
::
m
real
::
s
end
type
type
(
zeit
)
::
zeit_null
=
zeit
(
0
,
0
,
0
)
interface
GET
module
procedure
zeit_einlesen
end
interface
interface
operator
(
<
)
module
procedure
zeit_vgl
end
interface
interface
operator
(
+
)
module
procedure
zeit_add
end
interface
interface
operator
(
-
)
module
procedure
zeit_diff
end
interface
contains
subroutine
zeit_einlesen
(
time
)
type
(
zeit
),
intent
(
out
)
::
time
do
read
(
*
,
*
)
time
if
(
time
%
h
>=
0
.and.
time
%
m
>=
0
.and.
time
%
m
<
60
.and.
time
%
s
>=
0
.and.
time
%
s
<
60
)
exit
write
(
*
,
*
)
"Eingabe fehlerhaft. Gebe die Stunden, Minuten und Sekunden erneut ein."
end
do
end
subroutine
zeit_einlesen
function
zeit_string
(
time
)
! gibt die time als string (character) in der form hh:mm:ss zurück
type
(
zeit
),
intent
(
in
)
::
time
character
(
len
=
8
)
::
zeit_string
character
(
len
=
2
)
::
help
! trage stunden in string ein
write
(
help
,
'(I2)'
)
time
%
h
if
(
time
%
h
*
0.1
<
1
)
help
(
1
:
1
)
=
"0"
zeit_string
(
1
:
3
)
=
help
//
":"
! trage minuten in string ein
write
(
help
,
'(I2)'
)
time
%
m
if
(
time
%
m
*
0.1
<
1
)
help
(
1
:
1
)
=
"0"
zeit_string
(
4
:
6
)
=
help
//
":"
! trage sekunden in string ein
write
(
help
,
'(I2)'
)
nint
(
time
%
s
)
if
(
time
%
s
*
0.1
<
1
)
help
(
1
:
1
)
=
"0"
zeit_string
(
7
:
8
)
=
help
end
function
function
zeit_vgl
(
time1
,
time2
)
result
(
kleiner
)
type
(
zeit
),
intent
(
in
)
::
time1
,
time2
logical
::
kleiner
!rückgabevariable
kleiner
=
.false.
if
(
time1
%
h
<
time2
%
h
)
then
! vgl stunden
kleiner
=
.true.
elseif
(
time1
%
h
==
time2
%
h
)
then
if
(
time1
%
m
<
time2
%
m
)
then
kleiner
=
.true.
elseif
(
time1
%
m
==
time2
%
m
)
then
if
(
time1
%
s
<
time2
%
s
)
kleiner
=
.true.
end
if
end
if
end
function
zeit_vgl
function
zeit_add
(
time1
,
time2
)
result
(
sum
)
type
(
zeit
),
intent
(
in
)
::
time1
,
time2
type
(
zeit
)
::
sum
! rückgabewert
sum
=
zeit
(
0
,
0
,
0
)
sum
%
s
=
time1
%
s
+
time2
%
s
if
(
sum
%
s
>=
60
)
then
sum
%
s
=
sum
%
s
-
60
sum
%
m
=
1
end
if
sum
%
m
=
sum
%
m
+
time1
%
m
+
time2
%
m
if
(
sum
%
m
>=
60
)
then
sum
%
m
=
sum
%
m
-
60
sum
%
h
=
1
end
if
sum
%
h
=
sum
%
h
+
time1
%
h
+
time2
%
h
end
function
zeit_add
function
zeit_diff
(
time1
,
time2
)
result
(
diff
)
type
(
zeit
),
intent
(
in
)
::
time1
,
time2
type
(
zeit
)
::
diff
! rückgabewert
real
::
t1
,
t2
,
d
t1
=
time1
%
s
+
time1
%
m
*
60.
+
time1
%
h
*
60.
*
60.
t2
=
time2
%
s
+
time2
%
m
*
60.
+
time2
%
h
*
60.
*
60.
d
=
abs
(
t1
-
t2
)
diff
%
h
=
int
(
d
/
(
60.
*
60.
))
d
=
mod
(
d
,
60.
*
60.
)
diff
%
m
=
int
(
d
/
60.
)
d
=
mod
(
d
,
60.
)
diff
%
s
=
d
end
function
end
module
zeit_mod
module
wichtel_mod
use
zeit_mod
implicit
none
private
public
::
wichtel
,
GET
,
PUT
,
update_zeit
,
search
,
recommend
type
wichtel
private
character
(
len
=
20
)
::
name
type
(
zeit
)
::
zeit_worked
! stunden an arbeit
end
type
interface
GET
module
procedure
einlesen_wichtel
,
build_db_wichtel
end
interface
interface
PUT
module
procedure
ausgeben_wichtel
,
ausgeben_db_wichtel
end
interface
interface
update_zeit
module
procedure
update_zeit_worked
end
interface
interface
recommend
module
procedure
recommend_wichtel
end
interface
interface
search
module
procedure
suche_wichtel
end
interface
contains
subroutine
einlesen_wichtel
(
elf
)
type
(
wichtel
),
intent
(
out
)
::
elf
write
(
*
,
*
)
"Wie heisst der Wichtel?"
read
(
*
,
*
)
elf
%
name
write
(
*
,
*
)
"Wie viele Stunden, Minuten und Sekunden hat "
,
trim
(
elf
%
name
),
" gearbeitet?"
call
get
(
elf
%
zeit_worked
)
end
subroutine
einlesen_wichtel
subroutine
ausgeben_wichtel
(
elf
)
type
(
wichtel
),
intent
(
in
)
::
elf
write
(
*
,
*
)
"Der Wichtel "
,
trim
(
elf
%
name
),
" hat insgesamt "
,
zeit_string
(
elf
%
zeit_worked
),
" Stunden gearbeitet."
end
subroutine
subroutine
update_zeit_worked
(
elf
,
time
)
type
(
wichtel
),
intent
(
inout
)
::
elf
type
(
zeit
),
intent
(
in
)
::
time
elf
%
zeit_worked
=
elf
%
zeit_worked
+
time
end
subroutine
! neue Funktionen
subroutine
build_db_wichtel
(
elf_db
)
type
(
wichtel
),
dimension
(:),
allocatable
,
intent
(
out
)
::
elf_db
integer
::
n
,
i
write
(
*
,
*
)
"Wie viele Wichtel sind in der Datenbank?"
do
read
(
*
,
*
)
n
if
(
n
>
0
)
exit
write
(
*
,
*
)
"Zahl muss >0 sein. Erneute Eingabe!"
end
do
allocate
(
elf_db
(
n
))
write
(
*
,
*
)
"Gebe die Daten der Wichtel nacheinander ein."
do
i
=
1
,
n
call
GET
(
elf_db
(
i
))
end
do
end
subroutine
subroutine
ausgeben_db_wichtel
(
elf_db
)
type
(
wichtel
),
dimension
(:),
intent
(
in
)
::
elf_db
integer
::
i
write
(
*
,
*
)
"Es folgen alle Wichtel in der Datenbank:"
do
i
=
1
,
size
(
elf_db
,
1
)
call
put
(
elf_db
(
i
))
end
do
end
subroutine
subroutine
recommend_wichtel
(
elf_db
)
type
(
wichtel
),
dimension
(:),
intent
(
in
)
::
elf_db
integer
::
i
,
min
=
1
if
(
size
(
elf_db
,
1
)
>
1
)
then
do
i
=
2
,
size
(
elf_db
,
1
)
if
(
elf_db
(
i
)
%
zeit_worked
<
elf_db
(
min
)
%
zeit_worked
)
min
=
i
end
do
end
if
write
(
*
,
*
)
"Der folgende Wichtel sollte als naechstes an einer Aufgabe arbeiten:"
call
put
(
elf_db
(
min
))
end
subroutine
subroutine
suche_wichtel
(
elf_db
)
type
(
wichtel
),
dimension
(:),
intent
(
in
)
::
elf_db
integer
::
i
,
count
=
0
character
(
len
=
20
)
::
name_ges
write
(
*
,
*
)
"Gebe den Namen des Wichtels ein der gesucht wird:"
read
(
*
,
*
)
name_ges
do
i
=
1
,
size
(
elf_db
,
1
)
if
(
elf_db
(
i
)
%
name
==
name_ges
)
then
write
(
*
,
*
)
"Index: "
,
i
call
put
(
elf_db
(
i
))
count
=
count
+
1
end
if
end
do
if
(
count
==
0
)
write
(
*
,
*
)
"Es wurden keine Wichtel gefunden."
end
subroutine
end
module
wichtel_mod
module
aufgaben_mod
use
zeit_mod
use
wichtel_mod
implicit
none
private
public
::
aufgabe
,
GET
,
PUT
,
update_zeit
,
aufgabe_status
,
recommend
,
search
type
aufgabe
character
(
len
=
20
)
::
name
character
(
len
=
50
)
::
beschreibung
type
(
zeit
)
::
soll
! notwendige time zum vollenden
type
(
zeit
)
::
habe
! gearbeitete time
end
type
interface
GET
module
procedure
einlesen_aufgabe
,
build_db_aufgabe
end
interface
interface
PUT
module
procedure
ausgeben_aufgabe
,
ausgeben_db_aufgabe
end
interface
interface
update_zeit
module
procedure
update_zeit_habe
end
interface
interface
recommend
module
procedure
recommend_aufgabe
end
interface
interface
search
module
procedure
suche_aufgabe
end
interface
contains
subroutine
einlesen_aufgabe
(
task
)
type
(
aufgabe
),
intent
(
out
)
::
task
write
(
*
,
*
)
"Was ist der Name der Aufgabe?"
read
(
*
,
*
)
task
%
name
write
(
*
,
*
)
"Was ist die Beschreibung der Aufgabe? Schreibe am Anfang und Ende ein ' oder "
,
'".'
read
(
*
,
*
)
task
%
beschreibung
write
(
*
,
*
)
"Wie lange dauert die Aufgabe? (hh, mm, ss.sss)"
call
get
(
task
%
soll
)
write
(
*
,
*
)
"Wie lange wurde schon an der Aufgabe gearbeitet? (hh, mm, ss.sss)"
call
get
(
task
%
habe
)
end
subroutine
einlesen_aufgabe
subroutine
ausgeben_aufgabe
(
task
)
type
(
aufgabe
),
intent
(
in
)
::
task
write
(
*
,
*
)
"Aufgabe "
,
trim
(
task
%
name
),
" : "
,
trim
(
task
%
beschreibung
)
write
(
*
,
*
)
"Es wurden "
,
zeit_string
(
task
%
habe
),
" von "
,
zeit_string
(
task
%
soll
),
" gearbeitet."
end
subroutine
ausgeben_aufgabe
subroutine
update_zeit_habe
(
task
,
time
)
type
(
aufgabe
),
intent
(
inout
)
::
task
type
(
zeit
),
intent
(
in
)
::
time
task
%
habe
=
task
%
habe
+
time
end
subroutine
update_zeit_habe
! neue Funktionen
function
aufgabe_status
(
task
)
result
(
status
)
type
(
aufgabe
),
intent
(
in
)
::
task
integer
::
status
if
(
task
%
habe
<
task
%
soll
)
then
if
(
zeit_null
<
task
%
habe
)
then
status
=
1
! aufgabe wurde begonnen
else
status
=
0
! aufgabe wurde noch nicht begonnen
end
if
else
status
=
2
! aufgabe ist fertiggestellt
end
if
end
function
aufgabe_status
subroutine
build_db_aufgabe
(
task_db
)
type
(
aufgabe
),
dimension
(:),
allocatable
,
intent
(
out
)
::
task_db
integer
::
n
,
i
write
(
*
,
*
)
"Wie viele Aufgaben sind in der Datenbank?"
do
read
(
*
,
*
)
n
if
(
n
>
0
)
exit
write
(
*
,
*
)
"Zahl muss >0 sein. Erneute Eingabe!"
end
do
allocate
(
task_db
(
n
))
write
(
*
,
*
)
"Gebe die Daten der Aufgaben nacheinander ein."
do
i
=
1
,
n
call
GET
(
task_db
(
i
))
end
do
end
subroutine
subroutine
ausgeben_db_aufgabe
(
task_db
)
type
(
aufgabe
),
dimension
(:),
intent
(
in
)
::
task_db
integer
::
i
write
(
*
,
*
)
"Es folgen alle Aufgaben in der Datenbank:"
do
i
=
1
,
size
(
task_db
,
1
)
call
put
(
task_db
(
i
))
end
do
end
subroutine
subroutine
recommend_aufgabe
(
task_db
)
type
(
aufgabe
),
dimension
(:),
intent
(
in
)
::
task_db
integer
,
dimension
(
size
(
task_db
,
1
))
::
status
integer
::
i
,
max
=
1
do
i
=
1
,
size
(
task_db
,
1
)
! berechnet den status von allen aufgaben in der datenbank
status
(
i
)
=
aufgabe_status
(
task_db
(
i
))
end
do
if
(
any
(
status
==
1
))
then
! gibt es Aufgaben die schon begonnen wurden?
! wählt die unangefangene Aufgabe, die am wenigsten restarbeitszeit hat
if
(
size
(
task_db
,
1
)
>
1
)
then
do
i
=
2
,
size
(
task_db
,
1
)
if
(
status
(
i
)
==
1
)
then
if
((
task_db
(
i
)
%
soll
-
task_db
(
i
)
%
habe
)
<
(
task_db
(
max
)
%
soll
-
task_db
(
max
)
%
habe
))
max
=
i
end
if
end
do
end
if
write
(
*
,
*
)
"Die folgende Aufgabe hat am wenigsten Arbeitszeit uebrig:"
call
put
(
task_db
(
max
))
elseif
(
any
(
status
==
0
))
then
! gibt es Aufgaben die noch nicht erledigt wurden?
! wählt die erste Aufgabe die noch nicht begonnen wurde
do
i
=
1
,
size
(
task_db
,
1
)
if
(
aufgabe_status
(
task_db
(
i
))
==
0
)
then
write
(
*
,
*
)
"Es wurde noch keine Aufgabe begonnen. Hier ist eine noch nicht begonnene Aufgabe:"
call
put
(
task_db
(
i
))
exit
end
if
end
do
else
write
(
*
,
*
)
"Alle Aufgaben in der Datenbank sind erledigt."
end
if
end
subroutine
subroutine
suche_aufgabe
(
task_db
)
type
(
aufgabe
),
dimension
(:),
intent
(
in
)
::
task_db
integer
::
i
,
count
=
0
character
(
len
=
20
)
::
name_ges
write
(
*
,
*
)
"Gebe den Namen der Aufgabe ein die gesucht wird:"
read
(
*
,
*
)
name_ges
do
i
=
1
,
size
(
task_db
,
1
)
if
(
task_db
(
i
)
%
name
==
name_ges
)
then
write
(
*
,
*
)
"Index: "
,
i
call
put
(
task_db
(
i
))
count
=
count
+
1
end
if
end
do
if
(
count
==
0
)
write
(
*
,
*
)
"Es wurden keine Aufgaben gefunden."
end
subroutine
suche_aufgabe
end
module
aufgaben_mod
module
management_mod
use
zeit_mod
use
wichtel_mod
use
aufgaben_mod
implicit
none
private
public
::
update_work
contains
subroutine
update_work
(
elf_db
,
task_db
)
type
(
wichtel
),
dimension
(:),
intent
(
inout
)
::
elf_db
type
(
aufgabe
),
dimension
(:),
intent
(
inout
)
::
task_db
type
(
zeit
)
::
time
integer
::
n
character
::
logi
write
(
*
,
*
)
"Es wurde an einer Aufgabe gearbeitet, die Daten sollen aktualisiert werden."
write
(
*
,
*
)
"Wie lange wurde gearbeitet?"
call
get
(
time
)
do
write
(
*
,
*
)
"Was ist der Index von dem Wichtel?"
read
(
*
,
*
)
n
! man müsste hier eigentlich noch prüfen ob n im richtigen bereich liegt
write
(
*
,
*
)
"Ist dies der richtige Wichtel? (j/n)"
call
put
(
elf_db
(
n
))
read
(
*
,
*
)
logi
if
(
logi
==
"j"
)
exit
end
do
call
update_zeit
(
elf_db
(
n
),
time
)
do
write
(
*
,
*
)
"Was ist der Index von der Aufgabe?"
read
(
*
,
*
)
n
! man müsste hier eigentlich noch prüfen ob n im richtigen bereich liegt
write
(
*
,
*
)
"Ist dies die richtige Aufgabe? (j/n)"
call
put
(
task_db
(
n
))
read
(
*
,
*
)
logi
if
(
logi
==
"j"
)
exit
end
do
call
update_zeit
(
task_db
(
n
),
time
)
end
subroutine
end
module
management_mod
program
taskmanager
use
zeit_mod
use
wichtel_mod
use
aufgaben_mod
use
management_mod
implicit
none
type
(
zeit
)
::
time1
,
time2
type
(
wichtel
)
::
elf
type
(
aufgabe
)
::
task
type
(
wichtel
),
dimension
(:),
allocatable
::
elf_db
type
(
aufgabe
),
dimension
(:),
allocatable
::
task_db
! sonderuebung 09
! test zeit mod
!write(*,*) "gebe 2 zeiten ein"
!call get(time1)
!call get(time2)
!write(*,*) "Vgl ", time1 < time2
!write(*,*) "Add ", zeit_string(time1 + time2)
! test wichtel mod
!call get(elf)
!call change_zeit(elf, time1)
!call put(elf)
! test aufgaben mod
!call get(task)
!call change_zeit(task, time2)
!call put(task)
! sonderuebung 10
call
get
(
elf_db
)
call
get
(
task_db
)
call
recommend
(
elf_db
)
call
recommend
(
task_db
)
call
search
(
elf_db
)
call
search
(
task_db
)
call
update_work
(
elf_db
,
task_db
)
call
put
(
elf_db
)
call
put
(
task_db
)
deallocate
(
elf_db
,
task_db
)
end
program
taskmanager
! deallokieren der Aufgaben und Wichtel Datenbanken im Programm
\ No newline at end of file
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