from ctypes import *
string=c_char*20
class account(Structure):
_fields_=[('acct_no',c_int),('acct_type',c_char),('name',string),('balance',c_int)]
customer=account(12632,'r','Joseph',1200)
from ctypes import *
string=c_char*20
class date(Structure):
_fields_=[('month',c_int),('day',c_int),('year',c_int)]
class account(Structure):
_fields_=[('acct_no',c_int),('acct_type',c_char),('name',string),('balance',c_float),('lastpayment',date)]
customer=account(12345,'r','John W. Smith',586.30,date(5,24,90))
from ctypes import *
string=c_char*20
class date(Structure):
_fields_=[('name',string),('month',c_int),('day',c_int),('year',c_int)]
birthday=[]
birthday.append(date('Amy',12,30,73))
birthday.append(date('Gail',5,13,66))
birthday.append(date('Marc',7,15,72))
birthday.append(date('Marla',11,29,70))
birthday.append(date('Megan',2,4,77))
birthday.append(date('Sharon',12,29,63))
birthday.append(date('Susan',4,12,69))
from ctypes import *
string=c_char*50
def writeoutput(obj):
print "Name : ",obj.name,
print "\t Account Number : ",obj.acct_no
print "Street : ",obj.street
print "City : ",obj.city
print "Old Balance : %7.2f" %(obj.oldbalance)
print "Payment : %7.2f" %(obj.payment)
print "New Balance : %7.2f" %(obj.newbalance)
print "Account Status : ",
if obj.acct_type=='C':
print "CURRENT\n\n"
elif obj.acct_type=='O':
print "OVERDUE\n\n"
else:
print "DELINQUENT\n\n"
return
class date(Structure):
_fields_=[('month',c_int),('day',c_int),('year',c_int)]
class account(Structure):
_fields_=[('name',string),('street',string),('city',string),('acct_no',c_int),('oldbalance',c_float),('payment',c_float),('lastpayment',date),('newbalance',c_float),('acct_type',c_char)]
print "CUSOMER BILLING SYSTEM\n\n"
customer=[]
name='Steve Johnson'
street='123 Mountainview Drive '
city='Denver . CO'
acct_no=4208
oldbalance=247.88
payment=25.00
lastpay=date(6,14,1998)
customer.append(account(name,street,city,acct_no,oldbalance,payment,lastpay))
name='Susan Richards'
street='4383 Aligator Blvd'
city='Fort Lauderdale. FL'
acct_no=2219
oldbalance=135.00
payment=135.00
lastpay=date(8,10,2000)
customer.append(account(name,street,city,acct_no,oldbalance,payment,lastpay))
name='Martin Peterson'
street='1787 Pacific Parkway'
city='San Diego. CA'
acct_no=8452
oldbalance=387.42
payment=35.00
lastpay=date(9,22,1999)
customer.append(account(name,street,city,acct_no,oldbalance,payment,lastpay))
name='Phyllis Smith'
street='1000 Great White Way'
city='New York. NY'
acct_no=711
oldbalance=260.00
payment=0.00
lastpay=date(11,27,2001)
customer.append(account(name,street,city,acct_no,oldbalance,payment,lastpay))
for i in range(0,4):
if customer[i].payment>0:
if customer[i].payment<0.1*customer[i].oldbalance:
customer[i].acct_type='O'
else:
customer[i].acct_type='C'
else:
if customer[i].oldbalance>0:
customer[i].acct_type='D'
else:
customer[i].acct_type='C'
customer[i].newbalance=customer[i].oldbalance-customer[i].payment
writeoutput(customer[i])
from ctypes import *
string=c_char*10
class record(Structure):
_fields_=[('name',string),('acct_no',c_int),('acct_type',c_char),('balance',c_float)]
def adjust(obj):
obj.name='Jones'
obj.acct_no=9999
obj.acct_type='R'
obj.balance=99.99
return
customer=record('Smith',3333,'C',33.33)
print customer.name,customer.acct_no,customer.acct_type,
print "%.2f" %customer.balance
adjust(customer)
print customer.name,customer.acct_no,customer.acct_type,
print "%.2f" %customer.balance
class node():
def __init__(self,data):
self.data=data
self.next=None
class list():
def __init__(self):
self.head=None
self.tail=None
def insert(self,x):
e=node(x)
if self.head==None:
self.head=e
self.tail=e
else:
self.tail.next=e
self.tail=e
def display(ptr):
nptr=ptr.head
while nptr!=None:
print nptr.data
nptr=nptr.next
return
def delete(ptr,element):
nptr=ptr.head
while nptr.next.data!=element:
nptr=nptr.next
if nptr.next==None:
return
dptr=nptr.next
nptr.next=dptr.next
del dptr
return
p=list()
p.insert('BOSTON')
p.insert('CHICAGO')
p.insert('DENVER')
p.insert('NEW YORK')
p.insert('PITTSBURG')
display(p)
print '\n\nAFTER DELETING DENVER\n\n'
delete(p,'DENVER')
display(p)
from ctypes import *
string=c_char*20
class id(Union):
_fields_=[('color',c_char),('size',c_int)]
class clothes(Structure):
_fields_=[('manufacturer',string),('cost',c_float),('description',id)]
shirt=clothes()
shirt.description.color='w'
print "%c %d\n" %(shirt.description.color,shirt.description.size)
shirt.description.size=12
print "%c %d" %(shirt.description.color,shirt.description.size)
from ctypes import *
import math
class nvals(Union):
_fields_=[('fexp',c_float),('nexp',c_int)]
class values(Structure):
_fields_=[('x',c_float),('flag',c_char),('exp',nvals)]
def power(a):
y=a.x
if a.flag=='i':
if a.exp.nexp==0:
y=1.0
else:
i=1
while i<abs(a.exp.nexp):
y*=a.x
i+=1
if a.exp.nexp<0:
y=1.0/y
else:
y=math.exp(a.exp.fexp*math.log(a.x))
return y
def main(in1,n):
a=values()
a.x=in1
i=int(n)
if i==n:
a.flag='i'
else:
a.flag='f'
if a.flag=='i':
a.exp.nexp=i
else:
a.exp.fexp=n
if a.flag=='f' and a.x<=0.0:
print "ERROR - Cannot raise a non-positive number to a floating point power"
else:
y=power(a)
print "y=%.4f" %y
return
print "\nx=2\nn=3"
main(2,3)
print "\nx=-2\nn=3"
main(-2,3)
print "\nx=2.2\nn=3.3"
main(2.2,3.3)
print "\nx=-2.2\nn=3.3"
main(-2.2,3.3)