class Point:
def __init__(self,x,y):
self.xM = x
self.yM = y
def x(self):
return self.xM
def y(self):
return self.yM
def x_(self,x):
self.xM = x
def y_(self,y):
self.yM = y
def __add__(self,p2):
return Point(self.x() + p2.x(), self.y() + p2.y())
def valueFunc(t):
pass
def pointerFunc(tp):
pass
def referenceFunc(tr):
pass
def func1(c):
pass
def func2(i):
pass
def func3(d):
pass
def func(c):
pass
class EmcMathVector:
def __init__(self,x,y):
self.xM = x
self.yM = y
def __mul__(self,i):
self.xM *= i
self.yM *= i
def x(self):
return self.xM
def y(self):
return self.yM
def x_(self,x):
self.xM = x
def y_(self,y):
yM = y
a = EmcMathVector(5,10)
print a.xM,a.yM
a * 5
print a.xM,a.yM
class vector:
def __init__(self,first,last):
pass
def begin(self):
pass
def push_back(self,x):
pass
def insert(self,x):
pass
class basic_ofstream:
def __init__(self,x,y):
self.x = x
self.y = y
def print_(self):
print self.x , ", " , self.y;
v = basic_ofstream(1.2, 5.5);
v.print_()
def uselessPrint(v):
# NO: Compile error
print v.x() , ", " , v.y();
array = ['','','']
# assign to first element
arrayPointer = 42 #*(arrayPointer = array) = 42
print arrayPointer
def arraySum(array,first,last):
s = 0
for i in array:
# It is possible to update first since
# it has not been declared const.
s += i
return s;
print arraySum([5,4,3,2],5,2)
class EmcStack:
def __init__(self):
self.repM = []
self.allocatedM = 0
self.topM = 0
def push(t):
if self.topM == allocatedM : # allocate more memory
pass #size_t newSize = 2 * allocatedM;
self.repM.append(t)
self.topM +=1
message1 = "Calling Orson";
message2 = "Ice Hockey";
message3 = "Terminator";
message4 = "I like candy"
print message1
print message2
print message3
print message4
class UselessString:
def __init__(self,c=None):
pass
def cStr(self):
pass
def length(self):
pass
def at(self,index):
pass
def print_(self):
print self.s
class Silly:
def __init__(self,val):
self.valM = val
def me(self,s):
pass
name = "John Bauer";
print name[0]
cosmonaut = "Juri Gagarin"
c = 'a';
cValue = c in cosmonaut # cValue == true
uri = "uri"
uriValue = uri in cosmonaut # uriValue == true
print cValue
print uriValue
def max_(x,y):
if (x > y): # could use: < instead
# We also expect that:
# y < x
return x;
else:
# We also expect that:
# x <= y
return y;
x = 42;
y = 0;
print max(x,y)
'''
Implementation of closely related operators
Python has inbuilt this facility. No need to write functions for that.
'''
class Base:
def f(char):
pass
def f(i):
pass
def v(char):
pass
class Derived(Base):
def __init__(self):
pass
def f(self,i):
pass
def v(self,c):
self.f(c)
class EmcCollection:
def isEqual(self):
pass
class EmcBoundedCollection(EmcCollection):
def isEqual(a):
pass
def f(x,y = 2):
print x
print y
f(1)
f(2,3)
class RanDraw:
def __init__(self, limit,seed, t = 'Good' ):
pass # Default argument for t in class definition
class Other:
def __init__(self,a): #No implicit conversion from Any
pass
def foo(self,o):
pass
class EmcString:
def cStr(): # conversion to const char*
pass
def log(cp):
pass
magicPlace ="Ngoro-Ngoro crater at dusk"
print magicPlace # Explicit conversion from String to const char*