tags:

views:

70

answers:

1

i would like someone to assist in converting this code to C++

c ----------------------------------------------------------------------
c Calculate pressure based on the generalized Peng-Robinson equation of state.
c for water.
c Variables Used ...
c   T ... temperature (K)
c   P ... vapor pressure (MPa)
c   V ... volume (m^3/kmol)
c ----------------------------------------------------------------------
c Instructor: Nam Sun Wang
c ----------------------------------------------------------------------
      common /cblock/T

c Program Header -------------------------------------------------------
      print *, 'This program calculates pressure based on the'
      print *, 'generalized Peng-Robinson equation of state for water.'
      print *, ' '

c Temperature ----------------------------------------------------------
      print *, 'Enter temperature (K): '
      read *, T

c Generate a table of P at different values of V in 0.5 increments.
      print *, ' '
      print *, '------------------------'
      print *, ' Volume       Pressure  '
      print *, '(m^3/kmol)      (MPa)   '
      print *, '------------------------'
c                 xx.x123456789012345678   --- ruler
      do i=1, 100
        V = 0.5*float(i)
        print 650, V, P(V)
      end do

c Some formats ---------------------------------------------------------
650   format(f7.1, 1p, e18.6)
      end



c ----------------------------------------------------------------------
      function P(V)
c ----------------------------------------------------------------------
c Calculate pressure based on the generalized Peng-Robinson equation of state.
c for water.
c ----------------------------------------------------------------------
      common /cblock/T

c Gas Constant ---------------------------------------------------------
      R = 8.314E-3      ! (in MPa m3/kmol K)

c Critical parameters for water ----------------------------------------
      Tc = 647.3        ! (critical temperature in K)
      Pc = 22.048       ! (critical pressure in MPa)
      w  = 0.344        ! (acentric factor, dimensionless)

c Peng-Robinson EOS parameters -----------------------------------------
      xk = 0.37464 + 1.54226*w - 0.26992*w*w
      alpha = ( 1. + xk*(1.-sqrt(T/Tc)) )**2
      a = 0.45724*R*R*Tc*Tc*alpha/Pc
      b = 0.07780*R*Tc/Pc

      P = R*T/(V-b) - a/(V*(V+b)+b*(V-b))

      end
+3  A: 

Here are Some conversions for you, have a go and then post your results. We can then help you complete it.

a message

print *, '...'

replace with cout << "..."

a counted loop

do i=1, 100
...
end do

replace with

for(int i = 1; i <= 100; ++i) {
   ....
}

a comment

.... ! A comment

replace with

....; // a comment

a variable

X = 99.879

replace with

float X = 99.879

a function

function P(V)
.
.
.
P = .... ! the result

replace with

double P(double V){
.
.
.
 return ....; // the result
} 
Preet Sangha