#!/usr/bin/perl # # @(#)$Id: cs402calc.txt,v 1.1 2022/05/13 16:35:06 william Exp $ # # This is a kernel utility program. Do this first: # chmod 755 ./cs402calc.txt # # Usage: cs402calc.txt grade p1 p2 ... # # Please see the Grading for Group Projects section of the Projects web page about this program. $num_args = $#ARGV + 1; if ($num_args < 3) { print "usage: cs402calc.txt grade p1 p2 ...\n"; exit(-1); } $grade = $ARGV[0] * 1.0; $num_members = $num_args - 1; @percentages = ( ); $total = 0; $high = (-1); $low = (-1); for ($i = 0; $i < $num_members; $i++) { $percentages[$i] = $ARGV[$i+1]; $total = $total + $percentages[$i]; $frac = $percentages[$i] / 100.0; if ($high == (-1)) { $high = $percentages[$i]; $low = $percentages[$i]; } else { if ($percentages[$i] > $high) { $high = $percentages[$i]; } if ($percentages[$i] < $low) { $low = $percentages[$i]; } } } if ($total != 100) { print "ERROR: percentages do not add up to be 100.\n"; exit(-1); } $debug = 0; if ($debug) { print "grade = $grade\n"; for ($i = 0; $i < $num_members; $i++) { print "percentages[$i] = $percentages[$i]\n"; } print "high = $high\n"; print "low = $low\n"; } print "Assigned points ="; $spread = $high - $low; if (abs($spread) < 1e-8) { for ($i = 0; $i < $num_members; $i++) { print sprintf(" %.4g", $grade); } print " (equal shares)\n"; } else { $share = 50.0 / $high; for ($i = 0; $i < $num_members; $i++) { $f = 50.0 + $percentages[$i] * $share; $g = $grade * $f / 100.0; print sprintf(" %.4g", $g); } print "\n"; }