Tuesday, December 6, 2011

Finishing Projects

For projects 8 and 9, we need to get input for 6 employees and return a formatted list for a payroll sheet.

                In pseudo code (not actual code), this goes something like:
            Create a temp file containing the headings (number, name, rate, hours, etc)
                (echo "Number Name Rate...etc" > temp)
            Create a total variable to store overall total pay for all employees
            While loop for 6 passes
                read number name rate hours overtime
                regularpay=rate*hours
                overtimepay=rate*overtime
                totalweeklypay=regularpay+overtimepay
                total=total+totalweeklypay
                store variables as a new line in temp file
                    (number name rate hours overtime regularpay overtimepay totalweeklypay >> temp)
            done with while loop
            echo “Weekly Payroll”
            use awk to format each line from the temp file                                awk '{printf "%-6s%-13s%-10s%5s%8s%10s%9s%8s%8s\n", $1, $2, $3,"$"$4, $5, "$"$6, "$"$7, "$"$8, “$”9}'        (you may need to edit the %numbers)
            echo “Total: \$$total”

Also, to make this work for reading from a file for project A, try adding “< $1” after the “done” in the while loop.  This takes the first parameter passed at the command line and uses it as the file entry for the read command.

That gets you through project B, actually, since the AWK command is all that’s needed to complete it.  As for “discount”, that’s a new script, and can be found entirely in the student manual, under page 34 or 35 I believe.

Good luck, acolytes!

No comments:

Post a Comment