Question: Write a program that continuously prompts the user for a number of Dollars until the user enters 0. Pass each entered amount to a conversion
Write a program that continuously prompts the user for a number of Dollars until the user enters 0. Pass each entered amount to a conversion function that displays a breakdown of the passed amount into the fewest bills; in other words, the function calculates and prints the number of 20s, 10s, 5s, and 1s needed.
2. a. Write a program that calculates and displays the amount of money you would have if you invested $5000 at 2 percent simple interest for one year. Create a separate function to do the calculation and return the result to be displayed.
b. Modify the program to allow the main program prompts the user for the amount of money and passes it to the interest-calculating function.
c. Modify the program so that the main program also prompts the user for the interest rate and passes both the amount of money and the interest rate to the interest-calculating function.
Write a program that accepts an annual salary as input. Pass the salary to a function that calculates and prints the highest monthly housing payment the user can afford, assuming that the year's total payment is no more than 25 percent of the annual salary.
4. Write a program that performs arithmetic functions:
a. Program should prompt the user for two values for the variables. Pass both values to functions named sum() and difference(). The functions should compute the sum of and difference between the values of two arguments, respectively. Each function should perform the appropriate computation and display the results.
b. Modify the program so that the two entered values are passed to a function named getChoice(). The getChoice() function asks the user whether addition or subtraction should be performed and then passes the two values to the appropriate function, where the result is displayed.
5. Write a program that calls a function that computes the final price for a sales transaction. The program contains variables that hold the price of an item, the salesperson's commission expressed as a percentage, and the customer discount expressed as a percentage. Create a calculatePrice() function that determines the final price and returns the value to the calling function. The calculatePrice() function requires three arguments: product price, salesperson commission rate, and customer discount rate. A product's final price is the original price plus the commission amount minus the discount amount. The customer discount is taken as a percentage of the total price after the salesperson commission has been added to the original price.
6. Write a program that continuously prompts the user for two numeric values that represent the dimensions of a room in feet. Include two overloaded functions that compute the room's area. One function takes two numeric parameters and calculates the area by multiplying the parameters. The other takes a single numeric parameter, which is squared to calculate area. Each function displays its calculated result. Accept input and respond as follows:
When the user enters zero for the first value, end the program.
If the user enters a negative number for either value, continue to prompt the user until the value is not negative.
If both numbers entered are greater than 0, call the function version that accepts two parameters and pass it both values.
If the second value is zero, call the version of the function that accepts just one parameter and pass it the nonzero value.
7. a. Write a program for an insurance company to determine policy premiums. The program continuously prompts the user for an insurance policy number. When the user enters an appropriate sentinel value, end the program. The program calls a function that prompts each user for the type of policy neededhealth or auto. While the user's response does not indicate health or auto; continue to prompt the user. When the value is valid, return it from the function. Pass the user's response to a new function where the premium is set and returned$550 for a health policy or $225 for an auto policy. Display the results for each policy.
b. Modify the program so that the premium-setting function calls one of two additional functionsone that determines the health premium or one that determines the auto premium. The health insurance function asks users whether they smoke; the premium is $550 for smokers and $345 for nonsmokers. The auto insurance function asks users to enter the number of traffic tickets they have received in the last three years. The premium is $225 for drivers with three or more tickets, $190 for those with one or two tickets, and $110 for those with no tickets. Each of these two functions returns the premium amount to the calling function, which returns the amount to be displayed.
8. Write a program that prompts the user for numeric values for a month, day, and year. Then pass the three variables to the following functions:
a. A function that displays the date with dashes in month-day-year order, as it is often represented in the United Statesfor example, 6-24-2015
b. A function that displays the date with dashes in day-month-year order, as it is often represented in the United Kingdomfor example, 24-6-2015
c. A function that displays the date with dashes in year-month-day order, as it is represented in the International Standardfor example, 2015-6-24
d. A function that prompts the user for the desired format ("US", "UK", or "IS") and then passes the three values to one of the functions described in parts a, b, and c of this exercise.
9. Write a program that computes hotel guest rates at a hotel. Include two overloaded functions named computeRate(). One version accepts a number of days and calculates the rate at $99.99 per day. The other accepts a number of days and a code for a meal plan. If the code is A, three meals per day are included, and the price is $169.00 per day. If the code is C, breakfast is included, and the price is $112.00 per day. All other codes are invalid. Each function returns the rate to the calling program where it is displayed. The main program asks the user for the number of days in a stay and whether meals should be included; then, based on the user's response, the program either calls the first function or prompts for a meal plan code and calls the second function.
10. Write a program that calculates the mileage you get on your car. Theprogram should ask the user the number of miles travelled and number of gallon consumed. Use a function mileage() to calculate the mileage. mileage() should take two arguments: The number of miles travelled and the number of gallon consumed. The function should return the mileage and main program prints with description (a message).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
