Homework #1


Part One:

Note: THIS IS DUE IN CLASS AND CAN NOT BE LATE!

  1. Write a function declaration (prototype) for a function that takes gross income and number of dependants, as an integer, and returns the tax due.
  2. Implement the function ComputeTax so that it computes the tax due. ComputeTax must first compute the net income, which is determined by subtracting, from the gross income, $4,850 for the standard deduction, then $3,200 for each dependant, and then computing the tax owed on the remaining totals using the following formula:
    So, if someone made 28050, and had 1 dependant, they would owe ( 28050 - 4850 - 3200 = 20000 after deductions, so 7150 * .10 + 12850 * .15 = $2642 )
  3. Write a main program that prompts for input of gross income, number of dependants, and tax already paid. It will then compute the tax bill, and print the difference between the tax bill and amount already paid, followed by the message "SEND CHECK" or "REFUND" depending on if the difference is positive or negative.
Hints: The goal here is to write a very clean, good looking program. You'll notice that even though this program doesn't do anything "hard" (just simple math), because the formula is slightly complicated, the program begins to look like a mess of numbers very quickly. Your goal, as a programmer, is to try to make this as friendly looking as possible. So, some hints on how to do this

Part Two:
  • Dijkstra's Algorithm for finding the GCD of a number states that, if m > n, then GCD(m,n) equals GCD(m-n,n). The reason for this is, if m/d and n/d both have no remainder, then (m-n)/d leaves no remainder (this is very clever. Dijkstra was a very smart man). This leads to the algorithm that
    For m,n > 0, gcd(m,n) = 
    
    m if m=n 
    gcd(m - n,n) if m > n
    gcd(m,n-m) if m < n

  • Write a recursive function that implements this algorithm, and a small program to test it.
    Submission: Create scripts for both parts just like Lab 1. Print both scripts out and hand them to me, stapled, in class. Also, email me both parts, with the files named <your last name>-part1.cc and <your last name> part 2.cc

    Submission: Print out and hand to me in class. NO LATE SUBMISSIONS FOR THIS ONE. Also, bring a seperate copy of Part 1 for a class exercise.

    Grading: