7.9 Exercises


7.9 Exercises

  1. Write a complete algorithm in flowchart and pseudo-code to compute the distance between two points. Each point, P, is defined by a pair of values (x, y). The algorithm must check that the point values are different than zero, and that the two points are not the same. The distance, d, between two points, P1(x1,y1) and P2(x2,y2) is given by the expression:

  2. Given four numbers, find the largest one. Write a complete algorithm in pseudo-code that reads the four numbers and prints the largest one.

  3. Given four numbers, find the smallest one. Write a complete algorithm in pseudo-code that reads the four numbers and prints the smallest one.

  4. A car rental agency charges $34.50 per day for a particular vehicle. This amount includes up to 75 miles free. For every additional mile, the customer must pay $0.25. Write an algorithm in pseudo-code to compute the total amount to pay. Use the numbers of days and the total miles driven by the customer as input values.

  5. Extend the salary problem to include an additional restriction, a salary increase of 5% can only be assigned to an employee if the salary is less than $45,000 and if the number of years of service is at least 5 years.

  6. Write a more complete algorithm to solve the quadratic equation that includes the possibility of complex roots. In other words, include the part of the solution when the discriminant is negative.

  7. Passengers with motor vehicles taken on the ferry pay an extra fare based on the vehicle's weight. Use the following data: vehicles with weight up to 800 lb pay $75.00, up to 1200 lb pay $115.55, and up to 2300 lb pay $190.25. From the data on the weight of the vehicle, calculate the fare for the vehicle.

  8. Develop an algorithm in pseudo-code that reads four letter grades and calculates the average grade. Use the case statement as explained previously.

  9. Expand the ferry problem to calculate the cost of the ticket per passenger. Use the following values: class A ticket costs $150.45, class B costs $110.00, class C costs 82.50, class D costs $64.00, and Class E costs $45.50. Write a complete algorithm in pseudo-code to calculate the cost of the passenger's ticket.




Object-Oriented Programming(c) From Problem Solving to Java
Object-Oriented Programming (From Problem Solving to JAVA) (Charles River Media Programming)
ISBN: 1584502878
EAN: 2147483647
Year: 2005
Pages: 184

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net