From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../examples/buchlist.pl | 140 +++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 Bachelor/Systemprogrammierung in Perl/examples/buchlist.pl (limited to 'Bachelor/Systemprogrammierung in Perl/examples/buchlist.pl') diff --git a/Bachelor/Systemprogrammierung in Perl/examples/buchlist.pl b/Bachelor/Systemprogrammierung in Perl/examples/buchlist.pl new file mode 100644 index 0000000..2b9dad8 --- /dev/null +++ b/Bachelor/Systemprogrammierung in Perl/examples/buchlist.pl @@ -0,0 +1,140 @@ +#!c:/perl/bin/perl.exe +my ( @Buchlist, $buchzeiger ); +my ($anz); +my ($mittelwert); +my (%mfunc) = ( + 1 => sub {$anz = @Buchlist; print " Die Anzahl der Buecher ist $anz \n" ; }, + 2 => sub { &mittelwert; print "Der mittlere Preis betraegt $mittelpreis \n";}, + 3 => \&teuer, + 4 => \&billig, + 5 => \&mittel, + 6 => \&nextBuch, + 7 => \&lastBuch, + 8 => \&searchBuch, + 9 => sub {exit();} + ); +openfile(); # File einlesen +menu(); # print menue + +while ( 1 ) { + chomp ($prompt = ); + if ( $mfunc{$prompt} ){ + $mfunc{$prompt}() ; + } + else { + &menu; + } +} + +sub menu { + print <; + open ( FILE, $name ) or die "konnte $name nicht oeffnen"; + while ( ) { + ($Titel, $Autor, $Verlag,$Preis, $Bestell) = split ";"; + push( @Buchlist, + { + TITEL => $Titel, + VERLAG => $Verlag, + AUTOR => $Autor, + PREIS => $Preis, + BESTELL => $Bestell + }); + } + $anz = scalar @Buchlist; + mittelwert(); + print " Es wurden $anz Buecher eingelesen \n"; +} + +sub mittelwert { + my($buch); + $mittelpreis = 0; + + $anz = @Buchlist; + foreach $buch (@Buchlist) { + $mittelpreis += $buch->{PREIS}; + } + $mittelpreis /= $anz; +} + +sub billig { + my ($low) = 0; + my($buch); + foreach $buch (@Buchlist) { + if ( $buch->{PREIS} < $mittelpreis ) { + print "$buch->{TITEL} \n"; + $low++; + } + } + print "\nDie Anzahl der Buecher billiger als der Durchschnitt ist $low \n"; +} + +sub teuer { + my ($high ) = 0; + my ($buch ); + foreach $buch (@Buchlist) { + if ( $buch->{PREIS} > $mittelpreis ) { + print "$buch->{TITEL} \n"; + $high++; + } + } + print "\nDie Anzahl der Buecher teurer als der Durchschnitt ist $high \n"; +} + +sub mittel { + my( $lowLimit, $highLimit ); + my ($buch ); + print "untere Preisschranke ? "; + $lowLimit = ; + print "obere Preisschranke ? "; + $highLimit = ; + foreach $buch (@Buchlist) { + if ( $buch->{PREIS} > $lowLimit && $buch->{PREIS} < $highLimit ) { + print "$buch->{TITEL} \n"; + } + } +} + +sub nextBuch { + printbuch( $Buchlist[$buchzeiger++] ) if $buchzeiger < $anz; +} + +sub lastBuch { + printbuch( $Buchlist[$buchzeiger--] ) if $buchzeiger >= 0; +} + +sub searchBuch { + my ($buch ); + my ($search ); + print "Suchbegriff : "; + chomp ($search = ); + + foreach $buch (@Buchlist) { + print "$buch->{TITEL} \n" if $buch->{TITEL} =~ /\Q$search\E/ ; + } +} +sub printbuch{ + my ($buch ) = shift @_; + print " Titel = $buch->{TITEL} \n"; + print " Verlag = $buch->{VERLAG} \n"; + print " Autor = $buch->{AUTOR} \n"; + print " Preis = $buch->{PREIS} \n"; + print " Bestellnr = $buch->{BESTELL} \n"; + print " \n"; +} + -- cgit v1.2.3