| CSCI A201/A597Problem Set Five Second Summer 2000 |
| 1. |
Write a program that prints all real solutions
to the quadratic equation
ax2 + bx + c = 0Read in a, b, c and use the quadratic formula. If the discriminant b2 - 4ac is negative, display a message stating that there are no real solutions. |
| 2. |
Write a program that takes user input describing a playing card in the following shorthand notation:
Your program should print the full description of the card. For example: Enter the card notation: QS Queen of spades |
| 3. |
As in the Intersect program, compute and plot the intersection
of a line and a circle. However, if the line and the circle do not intersect,
do not plot the intersection points but display a message instead.
|
| 4. |
Write a program that reads in three floating-point numbers and prints the largest
of the three inputs. For example:
Please enter three numbers: 4 9 2.5 The largest number is 9 |
| 5. | Write a program that draws a circle with radius 100 and center (110, 120). Ask the user to specify the x- and y- coordinates of a point. If the point lies inside the circle, then show a message "Congratulations." Otherwise, show a message "You missed." |
| 6. | Write a graphics program that asks the user to specify the radii of two circles. The first circle has center (100, 200) and the second circle has center (200, 100). Draw the circles. If they intersect, then display a message "Circles intersect". Otherwise, display "Circles don't intersect". Hint: Compute the distance between the centers and compare it to the radii. Your program should draw nothing if the user enters a negative radius. |
| 7. | Write a program that prints the question "Do you want to continue?" and reads a user input. If the user input is "Y", "Yes", "OK", "Sure", or "Why not?", print out "OK". If the user input is "N" or "No" then print out "Terminating". Otherwise, print "Bad input." The case of the user input should not matter. For example, "y" or "yes" are also valid inputs. Hint: Convert the user input to lowercase and then compare. |
| 8. |
Write a program that translates a letter grade into a number grade. Letter grades are
A, B, C, D, F possibly
followed by + or -. Their numeric values are 4, 3, 2, 1, and 0.
There is no F+ or F-. A + increases the numeric
value by 0.3, a - decreases it by 0.3. However an A+ has a
value of 4.0.
Enter a letter grade: B+ The numeric value is 2.7. |
| 9. |
Write a number that translates a number between 0 and 4 into the closest letter grade. For
example, the number 2.8 (which might have been the average of several grades) would be converted to
B-. Break ties in favor of the better grade; for example 2.85 should be a B.
|
| 10. |
Write a program that reads in three strings and sorts them lexicographically.
Enter three strings: Charlie Able Baker Able Baker Charlie |
| 11. | A year with 366 days is called a leap year. A year is a leap year if it is divisible by 4 (for example, the year 1980), except it is not a leap year if it is divisible by 100 (for example, the year 1900); however, it is a leap year if it is divisible by 400 (for example, the year 2000). There were no exceptions before the introduction of the Gregorian calendar on October 15, 1582 (for example, the year 1500 was a leap year). Write a program that asks the user for a year and computes whether that year is a leap year or not. |
| 12. |
Write a program that asks the user to enter a month (1 = January, 2 = February, and so on)
and then prints the number of days of the month. For February, print "28 or 29 days."
Enter a month: 5 30 days |
| 13. |
Write a program that reads in two floating-point numbers and tests whether they are the same up
to two decimal places. Here are two sample runs.
Enter two floating-point numbers: 2.0 1.99998 They are the same up to two decimal places. Enter two floating-point numbers: 2.0 1.98999 They are different. |
| 14. |
Enhance the BankAccount class by
|
| 15. | Write a program that reads in the name and hourly wage of an employee. Then ask how many hours the employee worked in the past week. Be sure to accept fractional hours. Compute the pay. Any overtime work (over 40 hours per week) is paid at 150 percent of the regular wage. Print a paycheck for the employee. |