Programming Exercises

  • Personal Information

    Write a program that displays the following information

    • Your name

    • Your address, with city, state, and ZIP

    • Your telephone number

    • Your college major

  • Sales Prediction

    A company has determined that its annual profit is typically 23 percent of total sales. Write a program that asks the user to enter the projected amount of total sales, then displays the profit that will be made from that amount.

    • Hint: Use the value 0.23 to represent 23 percent.

  • Land Calculation

    One acre of land is equivalent to 43,560 square feet. Write a program that asks the user to enter the total square feet in a tract of land and calculates the number of acres in the tract.

    • Hint: Divide the amount entered by 43,560 to get the number of acres.

  • Total Purchase

    A customer in a store is purchasing five items. Write a program that asks for the price of each item, then displays the subtotal of the sale, the amount of sales tax, and the total. Assume the sales tax is 7 percent.

  • Distance Traveled

    Assuming there are no accidents or delays, the distance that a car travels down the interstate can be calculated with the following formula:

    • Distance = Speed x Time

    A car is traveling at 70 miles per hour. Write a program that displays the following:

    • The distance the car will travel in 6 hours

    • The distance the car will travel in 10 hours

    • The distance the care will travel in 15 hours

  • Sales Tax

    Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and country sales tax. Assume the state sales tax is 5 percent and the county sales tax is 2.5 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of the purchase plus the total sales tax).

    • Hint: Use the value 0.025 to represent 2.5 percent, and 0.05 to represent 5 percent.

  • Miles-per-Gallon

    A car’s miles-per-gallon (MPG) can be calculated with the following formula:

    • MPG = Miles driven / Gallons of gas used

    Write a program that asks the user for the number of miles driven and the gallons of gas used. It should calculate the car’s MPG and display the result.

  • Tip, Tax, and Total

    Write a program that calculates the total amount of a meal purchased at a restaurant. The program should ask the user to enter the charge for the food, then calculate the amounts of an 18 percent tip and 7 percent sales tax. Display each of these amounts and the total.

  • Celsius to Fahrenheit Temperature Converter

    Write a program that converts Celsius temperatures to Fahrenheit temperatures. The formula is as follows:

    • F = 9/5C + 32

    The program should ask the user to enter a temperature in Celsius, then display the temperature converted to Fahrenheit.

  • Ingredient Adjuster

    A cookie recipe calls for the following ingredients:

    • 1.5 cups of sugar

    • 1 cup of butter

    • 2.75 cups of flour

    The recipe produces 48 cookies with this amount of the ingredients. Write a program that asks the user how many cookies he or she wants to make, then displays the number of cups of each ingredient needed for the specified number of cookies.

  • Male and Female Percentages

    Write a program that asks the user for the number of males and the number of females registered in a class. The program should display the percentage of males and females in the class.

    Hint: Suppose there are 8 males and 12 females in a class. There are 20 students in the class. The percentage of males can be calculated as 8 / 20 = 0.4, or 40 %. The percentage of females can be calculated as 12 / 20 = 0.6 or 60%

  • Stock Transaction Program

    Last month, Joe purchased some stock in Acme Software, Inc. Here are the details of the purchase:

    • The number of shares that Joe purchased was 2,000.

    • When Joe purchased the stock, he paid $40.00 per share.

    • Joe paid his stockbroker a commission that amounted to 3 percent of the amount he paid for the stock.

    Two weeks later, Joe sold the stock. Here are the details of the sale:

    • The number of shares that Joe sold was 2,000.

    • He sold the stock for $42.75 per share.

    • He paid his stockbroker another commission that amounted to 3 percent of the amount he received for the stock.

    Write a program that displays the following information:

    • The amount of money Joe paid for the stock.

    • The amount of commission Joe paid his broker when he bought the stock.

    • The amount for which Joe sold the stock.

    • The amount of commission Joe paid his broker when he sold the stock.

    • Display the amount of money that Joe had left when he sold the stock and paid his broker (both times). If this amount is positive, then Joe made a profit. If the amount is negative, then Joe lost money.

  • Planting Grapevines

    A vineyard owner is planting several new rows of grapevines, and needs to know how many grapevines to plant in each row. She has determined that after measuring the length of a future row, she can use the following formula to calculate the number of vines that will fit in the row, along with the trellis end-post assemblies that will need to be constructed at the end of the row:

    • V = R-2E/S

    • V= number of grapevines that will fit in the row.

    • R= the length of the row, in feet.

    • E= the amount of space, in feet, used by an end-post assembly.

    • S= the space between vines, in feet.

    Write a program that makes the calculation for the vineyard owner. The program should ask the user to input the following:

    • The length of the row, in feet.

    • The amount of space used by an end-post assembly, in feet.

    • The amount of space between the vines, in feet.

    One the input data has been entered; the program should calculate and display the number of grapevines that will fit in the row.

  • Compound Interest

    When a bank account pays compound interest, it pays interest not only on the principal amount that was deposited into the account, but also on the interest that has accumulated over time. Suppose you want to deposit some money into a savings account, and let the account earn compound interest for a certain number of years. THe formula for calculating the balance of the account after a specified number of years is:

    • A = P (1+ r/n)** nt

      • A= amount of money in the account after the specified number of years.

      • P=the principal amount that was originally deposited into the account.

      • r is the annual interest rate.

      • n is the number of times per year that the interest is compounded.

      • t is the specified number of years.

    Write a program that makes the calculation for you. The program should ask the user to input the following:

    • The amount of principal originally deposited into the account.

    • The annual interest rate paid by the account.

    • The number of times per year that the interest is compounded (For example, if interest is compounded monthly, enter 12. If interest is compounded quarterly, enter 4.)

    • The number of years the account will be left to earn interest.

    Once the input data has been entered, the program should calculate and display the amount of money that will be in the account after the specified number of years.

    • *enter percent as 2, not 0.2.

  • Turtle Graphics Drawings

robot