CMSC 160
Fall 2018
09/07/2018
Strings and Conditionals
Due:  #1 and 2:  Tue, Sept 11 at 8am
#3 , 4 and 5:  Th, Sept 13 at 8am

Assignment:    (13 points)

For each of these, be certain that there is a comment at the top of the file saying what the program does, who wrote the program, and anyone you received help from.    You may not be reminded of this in the future.

separator

0)
 Divisibility.   (0 points)
a)
 Write a program that asks the user for a number and then reports whether the number is odd or even.   (Hint, use modulus)
b)  Write a program that asks the user for a number and then reports whether the number is divisible by 3.

NOTHING TO HAND IN FOR THIS ONE!


separator
1)   Making change.  (3 points)

Write a program that reads in two numbers from the user.  The first should represent the amount of a purchase.   The second should be the amount that was tendered by the customer.  The program should display how much change is due to the customer.

If the customer does not give enough to cover the purchase, the program should inform the user that not enough money was tendered.

Extra credit:   Have the program display the number of dollar bills, quarters, dimes, nickels, and pennies which make up the change.  (Hint: convert the answer to cents, rather than dollars and cents.)

Handin:    handin  cmsc160 labchange   filename.cpp        < replacing filename.cpp with whatever you call your file>
separator
2)   Phone numbers.  (2 points)
Write a program that asks the user for a phone number, in the format 1234567890.      The program should then display the formatted equivalent as such:    (123) 456-7890  

Handin:    handin  cmsc160 labphone   filename.cpp        < replacing filename.cpp with whatever you call your file>

separator

3)  Country facts   (3 points)

Write a program which gives the user the option of seeing information on 5 different countries.  When the user picks a country, the program should display 4 pieces of information about that country:  the capital city, the currency, and two other pieces of information (your choice).

Handin:    handin  cmsc160 labcountry  filename.cpp        < replacing filename.cpp with whatever you call your file>

separator

4)  Playing Cards. (2 points)
 Problem  P3.11 in the book (page 119-120)

Handin:    handin  cmsc160 labcards   filename.cpp        < replacing filename.cpp with whatever you call your file>

separator

5)   Wind speeds. (3 points)
The Saffir-Simpson scale uses wind speed to classify hurricanes.     Write a program that asks the user for the sustained wind speed, and uses the Saffir-Simpson scale and other definitions to classify a storm as follows:
classificationwind speed (in mph)
Tropical Depression<= 38 
Tropical Storm39 .. 73
Hurricane Category I74 .. 95
Hurricane Category II96  .. 110
Hurricane Category III111 ..129
Hurricane Category IV130 .. 156
Hurricane Category V>=157
Handin:    handin  cmsc160 labwinds   filename.cpp        < replacing filename.cpp with whatever you call your file>

Practice Problems (nothing to hand in)


P0)  Car Pricing
Write a program that asks the user for the type of car they own and how much they paid for it.  EG:
Type of car:  Toyota
Paid: $  19000

The program should then report if the car was overpriced.    
Rules:
  • No Corvettes are overpriced
  • All Mercedes are overpriced
  • Volvos over $10K are overpriced
  • Nothing else is overpriced


P1)  NumDaysInMonth:
Write a program that asks the user to enter a month name and a year.   This can be entered on separate lines.
EG:  Enter month:  September
        Enter year:  2013

The program should then report the number of days in the given month.

 A “leap year” is sometimes  defined as a year that is divisible by 4.    However, more correctly, if the year is divisible by 4 AND divisible by 100, then it is not a leap year.

eg:   1996 -> leap year  (divisible by 4)
 1995 -> not leap   (not divisible by 4)
 1900 -> not leap   (divisible by 4 AND 100)
 

This formula is still not complete for the true computation of leap year.  Go find a more accurate specification and include it in your program.    Be sure to document where you found the more accurate specification.




P2)  Tax Calculations
In this day of economic and political uncertainty, there are many different proposals out there for how to tax income.  One such proposal is as follows:

The first $30K is tax-free.    After that, you can deduct $10K for each dependent.   What remains is taxed at the following rates:


Taxable income  (income - the deductions listed above)

rate
$0 - 10K

3 %
$11 - 20K

7%
$21 - 30K

10%
$31 K and up

25%


For instance,
  •  a person who makes  45K and has 1 dependent:   
    • taxable income is 45K-30K - 1*10K  = 5K
    • Tax is 3% of 5K.
  • a person who makes 60K and has 4 dependents
    • taxable income is 60K -30K - 4* 10K = -10K
    • no tax
  • Additionally, if a person owns a car, they must pay $100 a year.  If they own a Porsche, they must pay an extra $50 a year (totalling $150 tax on the car)..


Your task:

Write a program that asks the user for:
  • their income (in thousands is okay - the user should NOT enter the letter K)
  • the number of dependents
  • what kind or car they drive  (they should type in "none" as appropriate)

The program should report how much tax they owe this year.  (both for income and the car combined)

Notes:
  • Be certain to make the prompts clear so that the user knows what they are typing.