Lab 2

The logical operators && (and) and || (or) are used to join two simple Boolean expressions to form more complex Boolean expressions. For example, if you wanted to construct a Boolean expression which would be true if an integer variable num had a value in the range 0-10 (inclusive) you could write          (num >= 0) && (num <= 10)

A complex Boolean expression using && is true if and only if both simple Boolean expressions it joins are true, otherwise the expression is false.

As an example using the or operator ||, suppose you wanted to construct a Boolean expression that would be true if the value of an integer variable x is either 1 or 2. For this you could write      (x == 1) || (x == 2)

A complex Boolean expression using || is true if either or both simple Boolean expressions it joins are true. The expression is false only if both simple Boolean expressions are false.

The logical operator ! (not) is used to reverse the value of the Boolean expression it precedes. So, for example, if an integer variable num has the value 100, the expression   !(num > 0)   is false.

Complex Boolean expressions can be used in both if and while statements. The complete expression must be enclosed in parentheses as required by the syntax for either the if or while statements. For example,         
                        if ((x > 5) && (x % 2 == 0))
                                
cout << "x is greater than 5 and an even number";



Part 1:
 Practice with Decision Statements

Write a short program that asks the user for their GPA (a double) and outputs a message based on the following chart:

              3.7 <= GPA <= 4.0 message should be "Excellent!"
              3.0 <= GPA < 3.7 message should be "Pretty good"
              2.0 <= GPA < 3.0 message should be "Not too bad"
              GPA < 2.0 message should be "Needs work"

If their GPA falls outside this range, you should output "Invalid GPA"
Note: Complex Decision Statements will yield a more compact, clean solution. 

Part 2:
 Practice with looping

Write a short program that will read in a list of grades.  The program will continue to read in values until a sentinel value of -1 is inputted. 
From this list, your program should compute the mean (average) grade, as well as output the highest and lowest.

Test this program first by running it, inputting some numbers, and verifying you get the correct output. 

After you're certainly your program works, test it by using
this input file.  You can copy this to your current directory using the following command.

cp ~cfischer/public_html/data.txt .

Note this line carefully, especially the space and the dot at the end.  The cp command uses the form of 

cp <source> <target>

The ~cfischer part references my home directory, then uses gets a file called data.txt from the public_html directory.  The single dot 
basically says "copy to my current directory", which you can see using the 'pwd' command. 


Use the unix redirection operators to get the data from your file into the program.

Part 3:
  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 dependa nt, 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 neat looking as possible. So, some hints on how to do this

Submission:

Submit your work using the same procedure described in Lab 1. To make it easier, you may make seperate scripts for each part and hand them in to the TA stapled together.

Grading:

Part 1: 25%
Part 2: 25%
Part 3: 50%