CMSC 15200 - Summer 2016

Homework #1 Due: Friday July 29, 2016 @ 11:59pm

This homework will give you practice with variables, expressions, and selection statements.

Problem #1: Taxable Income (income.c)

In one state, single residents are subject to the following income tax:

Income Tax Amount
Less than or equal to $650 2% of income
($650 - $2,375] $23.36 plus 3% of the amount over $650
($2,375 - $3,239] $80.71 plus 2% of the amount over $2,375
($3,239 - $6,039] $154.12 plus 5% of the amount over $3,239
($6,039 - $8,412] $112.93 plus 8% of the amount over $6,039
Over $8,412 $353.36 plus 9% of the amount over $8,412

Write a program that asks the user to enter the amount of taxable income, then displays the tax due. Include the dollar sign in the tax due output and format the tax to two decimal places (e.g. Tax Due: $34.24). The values on the right are inclusive. This program is required to be written in a file called income.c

You may assume that the user inputs an integer value for the income. It is perfectly reasonable to handle floating point values, though!


Problem #2: Elapsed Time (elapsed.c)

Write a program that prompts the user for an integer number of minutes representing an elapsed time. The program then outputs a start time of 12:00pm (that's noon, not midnight) and a finish time based on the elapsed time since 12:00pm. Make sure the finish time has the correct period: "am" or "pm" appended.

For example:

% Enter in an elapse time in minutes: 50
Start time:  12:00pm
Finish time: 12:50pm

% Enter in an elapse time in minutes: 100
Start time:  12:00pm
Finish time:  1:40pm

% Enter in an elapse time in minutes: 720
Start time:  12:00pm
Finish time: 12:00am                   
                  
The prompts and output should look exactly like the example above but of course with the minutes and times being interchangeable. You need to make sure you output single digits with a "0" before the minutes part and not just the single digit. For example: "12:08" instead of "12:8". This is not required for the hour part of the time. This program is required to be written in a file called elapsed.c

Hint: Think about using the % operator


Problem #3: Calendar Dates (dates.c)

Write a program that asks the user to enter two dates and then indicates if the first date comes before, after, or is the same as second date on the calendar:

% Enter first date (mm/dd/yy): 03/06/08
% Enter second date (mm/dd/yy): 05/17/07

03/06/08 comes after 05/17/07                
                  
The prompts and output should look exactly like the example above but of course with the dates being interchangeable. This program is required to be written in a file called dates.c

You may assume that the years the user enters are from the same century (e.g. 2000-2099).


Style and Conventions

At the top of your C files, write a comment with your name, etc., in the following form:

                /* Jane Doe, jdoe */
                /* CS152, Summer 2016 */
                /* HW#1: Problem #(1 or 2, or 3) */
                
This information is not strictly necessary, since your files are already identified by their names and the repository they reside in. Nevertheless, the redundancy is a helpful convenience for us when we are browsing and/or grading your work.

Comments, where they occur, should be helpful and precise. Do not comment the obvious:

                int a = b + c; /* I'm adding b and c! */
                
It's poor style.

Your code should be no more than 80 columns wide.

Do not write more than one statement on a line.


Submitting Your Work

Save and commit your code (income.c, elapsed.c, dates.c) in YOUR-REPOSITORY/hw1. Recall that you will need to add your work before you commit it. (Also, notice that in the -m message you include at commit time, -m is simply a command-line option.) Do not commit a.out to your repository; we will recompile your code on our own machines (it's improper to add binaries to source control).

Commit your work early and often. We do not grade intermediate commits, only the work as it stands at the deadline. If you have any issues with subversion, ask for help (either from the instructors or your classmates). Most of the students in this class have at least one full quarter of experience running subversion.

If, for any reason, perhaps due to a late add, you do not have a CS repository, save your work somewhere you can easily get it and send mail to the lecturer. We'll get you set up with a repository in time to make the deadline.