Programming Assignment 1


  1. (25 points) Problem 2.5 of the book. Calculate Tips. Write a program that reads the subtotal and the gratuity rate, then computes the gratuity and total. For example, if the user enters 10 for a subtotal and 15% for gratuity rate, the program displays $1.5 as gratuity and $11.5 as total.
  2. (25 points) Problem 2.7 of the book. Find the number of years and days. Write a program that prompts the user to enter the minutes (e.g., 1 billion) and displays the number of years and days for the minutes. For simplicity, assume a year has 365 days.
  3. (25 points) Problem 2.9 of the book. Science: wind-chill temperature. How cold is it outside? The temperature alone is not enough to provide the answer. Other factors including wind speed, relative humidity, and sunshine play important roles in determining coldness outside. In 2001, the National Weather Service (NWS) implemented the new wind-chill temperature to measure the coldness using temperature and wind speed. The formula is

    twc = 35.74 + 0.6215ta - 35.75v0.16 + 0.4275tav0.16

    where ta is the outside temperature in degrees Fahrenheit and v is the speed measured in miles per hour. twc is the wind-chill temperature. The formula cannot be used for wind speeds below 2 mph or temperatures below -58°F or above 41°F.
    Write a program that prompts the user to enter a temperature between -58°F and 41°F and a wind speed greater than or equal to 2 and displays the wind-chill temperature.
  4. (25 points) Find Light Intensity. Implement a program on the GoPiGo that finds the light color 1 meter away from the start of the robot. Report this RGBA reading in integer form (values between 0 and 255). After reading the color, return the robot back to its starting location. While the robot is moving and collecting the reading have both the right and left LEDs turned on. Upon completion, the robot should turn off its left and right LEDs. Note, that if one of the LEDs does not turn on, the robot itself may be broken, not your code.
  5. Bonus. (10 points) Problem 3.5 of the book. Geometry: area of a regular polygon. A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). The formula for computing the area of a regular polygon is

    Area = (n*s2)/(4*tan(π/n))

    Here s is the length of a side. Write a program that prompts the user to enter the number of sides and their length of a regular polygon and displays its area. Please format the output to be in scientific notation with six significant digits after the decimal place.