#Program to print details of person using structure and pointer
class account:
name=""
place=""
acctno=0
m4=account()
m4.name="Venkat"
m4.place="Arcot"
m4.acctno=24201
print "%s\t%s\t%d\n"%(m4.name,m4.place,m4.acctno)
contents=m4
print "%s\t%s\t%d\n"%(contents.name,contents.place,contents.acctno)
#Program to print name, place, and account number using structure and pointer
class account:
name=""
place=""
acctno=0
m4=account()
m4.name="Madhavan"
m4.place="Chennai"
m4.acctno=241
a=m4
print "%s\n%s\n%d\n"%(a.name,a.place,a.acctno)
#Program to show how the int_pointers structure can be handled.
class int_pointers:
p1=0
p2=0
pointers=int_pointers()
m1= 80
pointers.p1=m1
pointers.p2=-40
m2=pointers.p2
print "m1= %i, *pointers.p1 = %i\n"% (m1,pointers.p1)
print "m2= %i, *pointers.p2 = %i\n"% (m2,pointers.p2)
#Program to interchange the values stored in two variables using function with pointers.
def interchange(a,b):
t=a
a=b
b=t
return b,a
a=39
b=77
print "Before Interchange: a=%d, b=%d"%(a,b)
print "After Interchange : a=%d, b=%d"%(interchange(b,a))
#Program to demonstrate the use of structure pointers
class book:
bno=0
bname=''
cost=0.0
p=[book()for i in range(0,3)]
print "Enter the Book details... "
print "Enter Book number, Book Name, Book Costs... "
for i in range(0,3):
p[i].bno=input()
p[i].bname=raw_input()
p[i].cost=input()
for i in range(0,3):
print "\n%d\t%s\t\t%d"%(p[i].bno,p[i].bname,p[i].cost)
print "\nStructure Output\n"
ptr=p
for i in range(0,3):
print "%d\t%s\t\t%d"%(ptr[i].bno,ptr[i].bname,ptr[i].cost)
#Program to count number of vowels,consonants, digits,spaces and other characters in a line of text.
vowels='aeiou'
consonants='bcdfghjklmnpqrstvwxyz'
spaces =' '
digits='1234567890'
special_characters='!@#$%^&*()_'
text=raw_input("Enter the text in lower case: ")
print "\nNumber of vowels: ",dict((v, text.count(v)) for v in text if v in vowels)
print "Number of consonants: ",dict((c, text.count(c)) for c in text if c in consonants)
print "Number of Spaces: ",dict((s, text.count(s)) for s in text if s in spaces)
print "Number of digits: ",dict((d, text.count(d)) for d in text if d in digits)
print "Number of special_characters: ",dict((sc, text.count(sc)) for sc in text if sc in special_characters)
#Program to demonstrate malloc() function
NULL=0
string = ''
if string==NULL:
print "Not Enough memory to allocate buffer\n"
else:
def strcpy(cstring1):
import copy
cstring2=copy.copy(cstring1)
return cstring2
string="Hello"
print "String is %s" %string
#Program to demonstrate calloc() function
string=''
def strcpy(cstring1):
import copy
cstring2=copy.copy(cstring1)
return cstring2
stri="BHAVANA"
string=strcpy(stri)
print "String is %s" %string
#Program to demonstrate realloc() function
#Cannot do in python