energy.f95 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. PROGRAM energy
  2. ! ------------------------------------------------------------------------------
  3. ! Programmer: Jonathan Landrum
  4. !
  5. ! Purpose: This program calculates the total energy of an object that is
  6. ! on Earth by calculating and then adding its potential and
  7. ! kinetic energies.
  8. !
  9. ! Assumptions: 1.) Input is in metric units.
  10. !
  11. ! Revisions: Date Programmer Description of Change
  12. ! =========== ===================== ========================
  13. ! 01 Mar 2012 Jonathan Landrum Original code.
  14. ! ------------------------------------------------------------------------------
  15. IMPLICIT NONE
  16. ! DATA DICTIONARY: Declared constants
  17. REAL :: gravity = 9.8 ! Gravitational constant in m/s^2
  18. ! DATA DICTIONARY: Declared variables
  19. REAL :: mass ! Mass of the object
  20. REAL :: height ! Height of the object
  21. REAL :: velocity ! Velocity of the object
  22. REAL :: potentialEnergy ! Energy gained from altitude in Joules
  23. REAL :: kineticEnergy ! Energy gained from motion in Joules
  24. REAL :: totalEnergy ! Total energy in the object in Joules
  25. ! Introduce the program
  26. WRITE (*,*)
  27. WRITE (*,*) '* * * * * * * * * * * * * * * * * * * * * * * * * * * * *'
  28. WRITE (*,*) '* *'
  29. WRITE (*,*) '* Fortran Potential and Kinetic Energy Calculator *'
  30. WRITE (*,*) '* *'
  31. WRITE (*,*) '* * * * * * * * * * * * * * * * * * * * * * * * * * * * *'
  32. WRITE (*,*)
  33. WRITE (*,*) 'This program calculates and adds together the potential'
  34. WRITE (*,*) 'and kinetic energies of an object on Earth.'
  35. WRITE (*,*)
  36. WRITE (*,*) '---------------------------------------------------------'
  37. WRITE (*,*)
  38. ! Get data values from the user
  39. WRITE (*,*) 'What is the object''s mass in kilograms?'
  40. READ (*,*) mass
  41. WRITE (*,*)
  42. WRITE (*,*) 'What is the object''s altitude in meters?'
  43. READ (*,*) height
  44. WRITE (*,*)
  45. WRITE (*,*) 'What is the object''s initial velocity in meters/second?'
  46. READ (*,*) velocity
  47. WRITE (*,*)
  48. ! Perform the calculations
  49. potentialEnergy = mass * gravity * height
  50. kineticEnergy = 0.5 * mass * velocity ** 2
  51. totalEnergy = potentialEnergy + kineticEnergy
  52. ! Return the results
  53. WRITE (*,*) 'Potential energy: ', potentialEnergy, ' Joules'
  54. WRITE (*,*) 'Kinetic energy: ', kineticEnergy, ' Joules'
  55. WRITE (*,*) 'Total energy: ', totalEnergy, ' Joules'
  56. WRITE (*,*)
  57. WRITE (*,*) '\\//_ Live long and prosper.'
  58. END PROGRAM energy