#!/usr/bin/perl -w #define pi... $pi = 3.141; # This part basically defines which rule you want to use.... print "Welcome to the Lawrence's maths coursework, trig sepcial! \n"; print "What rule do you want to use? (cos/SIN) "; chomp($whatrule = ); if ( $whatrule eq "cos") { &sub_cos; }elsif ($whatrule eq "sin") { &sub_sin; }else{ &sub_haiku; print "$haiku"; } # What to do if the rule is CoSine sub sub_cos { my ($whatfind0) = @_; print "What do you want to find? "; chomp($whatfind0 = ); if ( $whatfind0 eq "a") { &sub_a_cos; }elsif ( $whatfind0 eq "b") { &sub_b_cos; }elsif ($whatfind0 eq "c") { &sub_c_cos; }else{ &sub_haiku; print $haiku; } $whatfind = $whatfind0; } # What to do if the rule is Sin sub sub_sin { my ($whatfind0) = @_; print "What do you want to find? "; chomp($whatfind0 = ); if ( $whatfind0 eq "a") { &sub_a_sin; }elsif ( $whatfind0 eq "b") { &sub_b_sin; }elsif ($whatfind0 eq "c") { &sub_c_sin; }else{ &sub_haiku; print $haiku; } $whatfind = $whatfind0; } # A subroutine to find a when the rule is cos..... sub sub_a_cos { my ($b,$c,$A,$cosA,$asq,$noradA) = @_; print "What is b? "; chomp($b = ); print "What is c? "; chomp($c = ); print "What is A? "; chomp($A = ); $cosA = &cos($A); $noradA = $cosA*180/$pi; $asq = ($b*$b+$c*$c-2*$b*$c*$noradA); $answer = sqrt($asq); $reala = "?"; $realb = $b; $realc = $c; $realA = $A; $realB = "?"; $realC = "?"; &work; } # A subroutine to find b when the rule is cos..... sub sub_b_cos { my ($a,$c,$B,$bsq,$cosB,$noradB) = @_; print "What is a? "; chomp($a = ); print "What is c? "; chomp($c = ); print "What is B? "; chomp($B = ); $cosB = &cos($B); $noradB = $cosB*180/$pi; $bsq = ($a*$a+$c*$c-2*$a*$c*$noradB); $answer = sqrt($bsq); $reala = $a; $realb = "?"; $realc = $c; $realA = "?"; $realB = $B; $realC = "?"; &work; } # A subroutine to find c when the rule is cos..... sub sub_c_cos { my ($a,$b,$C,$csq,$cosC,$cunrad) = @_; print "What is a? "; chomp($a = ); print "What is b? "; chomp($c = ); print "What is C? "; chomp($B = ); $cosC = &cos($C); $cunrad = $cosC*180/$pi; $csq = ($a*$a+$b+$b-2*$a*$b*$cunrad); $answer = sqrt($csq); $reala = $a; $realb = $b; $realc = "?"; $realA = "?"; $realB = "?"; $realC = $C; &work; } # A subroutine to find a when the rule is sin..... sub sub_a_sin { my ($b,$B,$A,$C,$c,$whathave,$aans,$sinA,$sinB,$sinC,$Aunrad,$Bunrad,$Cunrad) = @_; print "What do you have? [AbB/AcC] "; chomp($whathave = ); if ($whathave eq "AbB") { print "What is A?"; chomp($A = ); print "What is b?"; chomp($b = ); print "What is B?"; chomp($B = ); $sinA = &sin($A); $Aunrad = $sinA*180/$pi; $sinB = &sin($B); $Bunrad = $sinB*180/$pi; $aans = $b*$Aunrad/$Bunrad; $answer = $aans; $reala = "?"; $realb = $b; $realc = "?"; $realA = $A; $realB = $B; $realC = "?"; $whatfound = a1; }elsif ($whathave eq "AcC") { print "What is A?"; chomp($A = ); print "What is c?"; chomp($c = ); print "What is C?"; chomp($C = ); $sinC = &sin($C); $Cunrad = $sinC*180/$pi; $sinB = &sin($B); $Bunrad = $sinB*180/$pi; $aans = $b*$Cunrad/$Bunrad; $answer = $aans; $reala = "?"; $realb = "?"; $realc = $c; $realA = $A; $realB = "?"; $realC = $C; $whatfound = a2; }else{ print "$haiku\n"; } &work; } # A subroutine to find b when the rule is sin..... # Here too..... sub sub_b_sin { my ($a,$B,$A,$C,$c,$whathave,$bans,$sinA,$sinB,$sinC,$Aunrad,$Bunrad,$Cunrad) = @_; print "What do you have? [aBA/cBC] "; chomp ($whathave = ); if ($whathave eq "aBA") { print "What is a?"; chomp($a = ); print "What is B?"; chomp($B = ); print "What is A?"; chomp($A = ); $sinB = &sin($B); $Bunrad = $sinB*180/$pi; $sinA = sin($A); $Aunrad = $sinA*180/$pi; $bans = $a*$Bunrad/$Aunrad; $answer = $bans; $reala = $a; $realb = "?"; $realc = "?"; $realA = $A; $realB = $B; $realC = "?"; $whatfound = b1; }elsif ($whathave eq "cBC") { print "What is c?"; chomp($c = ); print "What is B?"; chomp($B = ); print "What is C?"; chomp($C = ); $sinB = sin($B); $Bunrad = $sinB*180/$pi; $sinC = sin($C); $Cunrad = $sinC*180/$pi; $bans = $c*$Bunrad/$Cunrad; $answer = $bans; $reala = "?"; $realb = "?"; $realc = $c; $realA = "?"; $realB = $B; $realC = $C; $whatfound = b2; }else{ &sub_haiku; print "$haiku\n"; } &work; } # A subroutine to find c when the rule is sin..... sub sub_c_sin { my ($a,$b,$B,$A,$C,$whathave,$cans,$sinC,$Cunrad,$sinB,$Bunrad,$sinA,$Aunrad) = @_; print "What do you have? [bCB/aCA] "; chomp($whathave = ); if ($whathave eq "bCB") { print "What is b?"; chomp($b = ); print "What is C?"; chomp($C = ); print "What is B?"; chomp($B = ); $sinC = sin($C); $Cunrad = $sinC*180/$pi; $sinB = sin($B); $Bunrad = $sinB*180/$pi; $cans = $b*$Cunrad/$Bunrad; $answer = $cans; $reala = "?"; $realb = $b; $realc = "?"; $realA = "?"; $realB = $B; $realC = $C; $whatfound = c1; }elsif ($whathave eq "aCA") { print "What is a?"; chomp($a = ); print "What is C?"; chomp($C = ); print "What is A?"; chomp($A = ); $sinC = sin($C); $Cunrad = $sinC*180/$pi; $sinB = sin($A); $Bunrad = $sinA*180/$pi; $cans = $a*$Cunrad/$Aunrad; $answer = $cans; $reala = $a; $realb = "?"; $realc = "?"; $realA = $A; $realB = "?"; $realC = $C; $whatfound = c2; }else{ &sub_haiku; print "$haiku\n"; } &work; } # A subroutine to decide which working to print..... sub work { if ($whatrule eq "sin") { &sin_work_gen; }elsif ($whatrule eq "cos") { &cos_work_gen; } &to_file; } # A sine working generator..... sub sin_work_gen { if ($whatfind eq "a") { $workgubbins = "

a² = b² + c² - (2bc CosA)

"; }elsif ($whatfind eq "b") { $workgubbins = "

b² = a² + c² - (2ac CosB)

"; }elsif ($whatfind eq "c") { $workgubbins = "

c² = a² + b² - (2ab CosC)

"; }else{ &sub_haiku; print "$haiku\n";} } # A CoSine working generator..... sub cos_work_gen { if ($whatfound eq "a1") { $workgubbins = "

a   =   b
SinA   SinB
SinB x a = b x SinA
a = b x SinA
             SinB

"; }elsif ($whatfound eq "a2") { $workgubbins = "

a   =   c
SinA   SinC
SinC x a = c x SinA
a = c x SinA
             SinC

"; }elsif ($whatfound eq "b1") { $workgubbins = "

b   =   a
SinB   SinA
b x SinA = a x SinB
b = a x SinB
             SinA

"; }elsif ($whatfound eq "b2") { $workgubbins = "

b   =   c
SinB   SinC
b x SinC = c x SinB
b = c x SinB
             SinC

"; }elsif ($whatfound eq "c1") { $workgubbins = "

c   =   b
SinC   SinB
c x SinB = b x SinC
c = b x SinC
             SinB

"; }elsif ($whatfound eq "c2") { $workgubbins = "

c   =   a
SinC   SinA
c x SinA = a x SinC
c = a x SinC
             SinA

"; }else{ &sub_haiku; print "$haiku\n";} } # A subroutine to print the answers to a file..... sub to_file { my ($file_gubbins,$work) = @_; open(FILE, ">answerfile.txt"); $file_gubbins = "

Triangle number $tridone


For this triangle I used $whatrule



triangle pic


    A = $realA
    B = $realB
    C = $realC
    a = $reala
    b = $realb
    c = $realc

$workgubbins



So the answer is $answer

"; write ($file_gubbins); close (FILE); } # A subroutine to do error message generation sub sub_haiku { my ($h1,$h2,$h3,$h4,$h5,$h6,$h7,$h8,$h9,$h10,$h11,$h12,$h13,$h14,$h15,$h16,@haikus) = @_; $h1 = "A file that big?\nIt must be very useful.\nBut now it is gone.\n"; $h2 = "You seek a Website.\nIt cannot be located.\nCountless more exist.\n"; $h3 = "Chaos reigns within.\nStop, reflect, and reboot.\nOrder shall return.\n"; $h4 = "ABORTED effort.\nClose all that you have worked on.\nYou ask way too much.\n"; $h5 = "Yesterday it worked.\nToday it is not working.\nWindows is like that.\n"; $h6 = "First snow, then silence.\nThis thousand dollar screen dies\nSo beautifully\n"; $h7 = "With searching comes loss.\nThe presence of absence.\nJuneSales.doc not found\n"; $h8 = "The Tao that is seen\nIs not the true Tao.\nUntil you bring fresh toner.\n"; $h9 = "Windows NT crashed.\nThe Blue Screen of Death.\nNo one hears your screams.\n"; $h10 = "Stay the patient course.\nOf little worth is your ire.\nThe network is down.\n"; $h11 = "A crash reduces\nYour expensive computer\nTo a simple stone.\n"; $h12 = "Three things are certain:\nDeath, Taxes and Lost Data.\nGuess which has ocurred.\n"; $h13 = "You step in the stream.\nBut the water has moved on.\nPage Not Found.\n"; $h14 = "Out of memory.\nWe wish to hold the whole sky\nBut we never will.\n"; $h15 = "Having been erased,\nThe document you are seeking\nMust now be re-typed.\n"; $h16 = "Serious error.\nAll shortcuts have disappeared.\nScreen. Mind. Both are blank.\n"; @haikus = ($h1, $h2, $h3, $h4, $h5, $h6, $h7, $h8, $h9, $h10, $h11, $h12, $h13, $h14, $h15, $h16); $haiku = $haikus[rand @haikus]; } # sub_haiku is not mine # copyright 2001 azatoth # haikus courtesy of salon.com - thanks dws for source!