I all ready completed and ran a program that works fine in Python but now I'm looking to convert that code to C++ in Eclipse. I thought I would be able to import this code than have some miracle conversion take place. Is this possible or does the whole code need to be transfered in C++ language? keep in mind I'm just a rookie at all this. Here is my code:

from datetime import date
import exceptions
import string
now = date.today
 
 
class Negative( exceptions.Exception ):
     '''A user-defined exception class.'''
     def __init__( self, val ):
         self.val = val
         return
     def __str__( self ):
         print "Bad amount. You typed '%s' Number has to be positive." %\
               self.val
 
class Overdrawn( exceptions.Exception ):
     def __init__( self, val ):
         self.val = val
         return
     def __str__( self ):
         print "You are attempting to create a balance overdrawn by %s" % self.val
     
class Account:
     def __init__( self, initial ):
         '''Initializes the account data.'''
         self.balance = initial
         print ' (Initializing; balance is %s) ' % self.balance
     def deposit( self, amt ):
         '''Deposit amt into account'''
         if amt < 0:
              raise Negative( amt )
         self.balance = self.balance + amt
         print " (Depositing %s; new balance is %s) " % ( amt, self.balance )
         # When this deposit is created, it
         # adds to the balance
     def withdraw( self, amt ):
         '''Withraw amt from account'''
         if amt < 0:
              raise Negative( amt )
         if amt >= self.balance:
              raise Overdrawn( self.balance - amt )
         self.balance = self.balance - amt
         print " (Withdrawing %s; new balance is %s) " % ( amt, self.balance )
         # When this deposit is created, it
         # subtracts from the balance
     def getbalance( self ):
         '''Return the current balance of this account.'''
         return self.balance
 
def printmenu():
    print "please select a number"
    print "1 Deposit"
    print "2 Withdraw"
    print '3 Balance'
    print '4 Done'

I can see that C++ and python have a few similarities in syntax, but apart from that they're two very different languages,

I've never used eclipse (or python for that matter), but I don't imagine that there is any easy way to magically translate your program into C++.

Just by reading, I can guess what most of it does, and some lines will be fairly easy to convert with straight subsitution, while other parts of the program would be done quite differently in C++, and I imagine the conversion process being somewhat trickier.

This article has been dead for over six months. Start a new discussion instead.