class date:
dat = 0
month = 0
year = 0
class person:
name = ''
lastnam = ''
birthday = date()
salary = 0.0
emprec = person()
birth = emprec.birthday
emprec.name = "Tejaswi.V."
emprec.lastnam = "Rajuk"
emprec.birthday.day = 24
emprec.birthday.month = 7
emprec.birthday.year = 90
x = 6500.00
emprec.salary = x
print "Employee Details: "
print "Name: ", emprec.name, " ", emprec.lastnam
print "Birthdate: ", emprec.birthday.day, ":", emprec.birthday.month, ":", emprec.birthday.year
print "Salary: ", emprec.salary
CURRENT_YEAR = 96
def increment(sal, year, inc):
if CURRENT_YEAR - year > 30:
sal += inc
return sal
class date:
day = 0
month = 0
year = 0
class person:
name = ''
birthday = date()
salary = 0.0
n = 500
emprec = person()
emprec.name = 'Arun R.'
emprec.birthday.day = 10
emprec.birthday.month = 8
emprec.birthday.year = 64
emprec.salary = 4000.00
print "Employee Details: "
print "Name: ", emprec.name
print "Birthdate: ", emprec.birthday.day, ":", emprec.birthday.month, ":", emprec.birthday.year
print "Salary: ", emprec.salary
emprec.salary = increment(emprec.salary, emprec.birthday.year, n)
print "Employee Details: "
print "Name: ", emprec.name
print "Birthdate: ", emprec.birthday.day, ":", emprec.birthday.month, ":", emprec.birthday.year
print "Salary: ", emprec.salary
CURRENT_YEAR = 96
def increment(emprec):
if CURRENT_YEAR - emprec.birthday.year > 30:
emprec.salary += 500
return emprec
class date:
day = 0
month = 0
year = 0
class person:
name = ''
birthday = date()
salary = 0.0
emprec = person()
emprec.name = 'Arun R.'
emprec.birthday.day = 10
emprec.birthday.month = 8
emprec.birthday.year = 64
emprec.salary = 4000.00
print "Employee Details: "
print "Name: ", emprec.name
print "Birthdate: ", emprec.birthday.day, ":", emprec.birthday.month, ":", emprec.birthday.year
print "Salary: ", emprec.salary
emprec = increment(emprec)
print "Employee Details: "
print "Name: ", emprec.name
print "Birthdate: ", emprec.birthday.day, ":", emprec.birthday.month, ":", emprec.birthday.year
print "Salary: ", emprec.salary
class date:
day = 0
month = 0
year = 0
class person:
name = ''
birthday = date()
salary = 0.0
def printout(per):
print "Employee Details: "
print "Name: ", per.name
print "Birthdate: %3d:%3d:%3d" %(per.birthday.day, per.birthday.month, per.birthday.year)
print "Salary: %6.2f" %(per.salary)
def readin(record):
record.name = raw_input("Enter the name: ")
print "Enter Birthdate"
record.birthday.day = int(raw_input("Day: "))
record.birthday.month = int(raw_input("Month: "))
record.birthday.year = int(raw_input("Year: "))
record.salary = float(raw_input("Enter the salary: "))
test = person()
test.name = "Arun"
test.birthday.day = 10
test.birthday.month = 8
test.birthday.year = 75
test.salary = 4500.00
temp = person()
readin(temp)
printout(test)
class date:
day = 0
month = 0
year = 0
class person:
name = ''
birthday = date()
salary = 0.0
def printout(per):
print "Employee Details: "
print "Name: ", per.name
print "Birthdate: %3d:%3d:%3d" %(per.birthday.day, per.birthday.month, per.birthday.year)
print "Salary: %6.2f" %(per.salary)
def readin(record):
record.name = raw_input("Enter the name: ")
print "Enter Birthdate"
record.birthday.day = int(raw_input("Day: "))
record.birthday.month = int(raw_input("Month: "))
record.birthday.year = int(raw_input("Year: "))
record.salary = float(raw_input("Enter the salary: "))
test = person()
test.name = "Arun"
test.birthday.day = 10
test.birthday.month = 8
test.birthday.year = 75
test.salary = 4500.00
temp = person()
readin(temp)
printout(temp)
class date:
day = 0
month = 0
year = 0
class person:
name = ''
birthday = date()
salary = 0.0
def __init__(self, n, dt, sal):
self.name = n
self.birthday.day = dt[0]
self.birthday.month = dt[1]
self.birthday.year = dt[2]
self.salary = sal
def printout(per):
print "Employee Details: "
print "Name: ", per.name
print "Birthdate: %3d:%3d:%3d" %(per.birthday.day, per.birthday.month, per.birthday.year)
print "Salary: %6.2f" %(per.salary)
def highest(sals):
return max(sals)
record = [["Arun R.", 10, 8, 75, 4000.00],
["vinod S.", 3, 10, 74, 3000.00],
["Tanuj M.", 21, 1, 73, 5500.00]]
emp1 = person(record[0][0], (record[0][1], record[0][2], record[0][3]), record[0][4])
emp2 = person(record[1][0], (record[1][1], record[1][2], record[1][3]), record[1][4])
emp3 = person(record[2][0], (record[2][1], record[2][2], record[2][3]), record[2][4])
sals = [emp1.salary, emp2.salary, emp3.salary]
highest = highest(sals)
print "The highest salary being paid is %6.2f" %highest
printout(emp3)
class date:
day = 0
month = 0
year = 0
class person:
name = ''
birthday = date()
salary = 0.0
def readin(rec, list1):
rec.name = list1[0]
rec.birthday.day = list1[1]
rec.birthday.month = list1[2]
rec.birthday.year = list1[3]
rec.salary = list1[4]
def printout(per):
print "Employee Details: "
print "Name: ", per.name
print "Birthdate: %3d:%3d:%3d" %(per.birthday.day, per.birthday.month, per.birthday.year)
print "Salary: %6.2f" %(per.salary)
def highest(sals):
return max(sals)
record = [["Tejaswi", 24, 7, 70, 7000.00],
["vinod S.", 3, 10, 74, 3000.00],
["Tanuj M.", 21, 1, 73, 5500.00]]
emp1 = person()
readin(emp1, record[0])
print emp1.birthday.day
emp2 = person()
readin(emp2, record[1])
emp3 = person()
readin(emp3, record[2])
highest = highest([emp1.salary, emp2.salary, emp3.salary])
temp = emp1
print "Highest salary being paid is ", highest
printout(temp)
class date:
day = 0
month = 0
year = 0
class person:
name = ''
birthday = date()
salary = 0.0
def readin():
record = []
for i in range(3):
print "Employee no. ", i+1
temp = person()
temp.name = raw_input("Enter the name: ")
print "Enter Birthdate"
temp.birthday.day = int(raw_input("Day: "))
temp.birthday.month = int(raw_input("Month: "))
temp.birthday.year = int(raw_input("Year: "))
temp.salary = float(raw_input("Enter the salary: "))
record.append(temp)
return record
def printout(per):
print "Employee Details: "
print "Name: ", per.name
print "Birthdate: %3d:%3d:%3d" %(per.birthday.day, per.birthday.month, per.birthday.year)
print "Salary: %6.2f" %(per.salary)
record = readin()
for i in range(3):
printout(record[i])
print "hit enter to continue..."
raw_input()
#there is a printing mistake in the book
class date:
day = 0
month = 0
year = 0
class person:
name = ''
birthday = date()
salary = 0.0
def readin(n):
record = []
for i in range(n):
print "Employee no. ", i+1
temp = person()
temp.name = raw_input("Enter the name: ")
print "Enter Birthdate"
temp.birthday.day = int(raw_input("Day: "))
temp.birthday.month = int(raw_input("Month: "))
temp.birthday.year = int(raw_input("Year: "))
temp.salary = float(raw_input("Enter the salary: "))
record.append(temp)
return record
def printout(record):
for i in range(n):
print "Employee Details: "
print "Name: ", record[i].name
print "Birthdate: %3d:%3d:%3d" %(record[i].birthday.day, record[i].birthday.month, record[i].birthday.year)
print "Salary: %6.2f" %(record[i].salary)
def sortalpha(rec):
for i in range(n-1):
for j in range(n-i-1):
if rec[j].name > rec[j+1].name:
rec[j], rec[j+1] = rec[j+1], rec[j]
return rec
def sortage(rec):
for i in range(n-1):
for j in range(n-i-1):
if (rec[j].birthday.year > rec[j+1].birthday.year or rec[j].birthday.year == rec[j+1].birthday.year and
rec[j].birthday.month > rec[j+1].birthday.month or rec[j].birthday.month == rec[j+1].birthday.month and
rec[j].birthday.day > rec[j+1].birthday.day or rec[j].birthday.day == rec[j+1].birthday.day):
rec[j], rec[j+1] = rec[j+1], rec[j]
return rec
def sortsal(rec):
for i in range(n-1):
for j in range(n-i-1):
if rec[j].salary > rec[j+1].salary:
rec[j], rec[j+1] = rec[j+1], rec[j]
return rec
n = int(raw_input("Enter the number of records: "))
record = readin(n)
flag = True
while(flag):
print "1: SORT BY NAME"
print "2: SORT BY AGE"
print "3: SORT BY SALARY"
print "4: QUIT "
i = int(raw_input("Enter your choice: "))
if i == 1:
sorted_rec = sortalpha(record)
printout(sorted_rec)
elif i == 2:
sorted_rec = sortage(record)
printout(sorted_rec)
elif i == 3:
sorted_rec = sortsal(record)
printout(sorted_rec)
elif i == 4:
flag = False
break
else:
print "invalid choice..."
#Note: There is no concept of unions in Python. We will implment using classes
import sys
class emp:
name = ''
idno = 0
salary = 0.0
class desc:
name = ''
idno = 0
salary = 0.0
e = emp()
d = desc()
print "The size of the structure is ", sys.getsizeof(e)
print "The size of the union is ", sys.getsizeof(d)
class desc:
name = ''
idno = 0
salary = 0.0
des = desc()
des.name = 'Vinod'
print "Employee Details: "
print "The name is ", des.name
print "The idno is ", des.idno
print "The salary is ", des.salary
des.idno = 10
print "Employee Details: "
print "The name is ", des.name
print "The idno is ", des.idno
print "The salary is ", des.salary
des.salary = 6500.00
print "Employee Details: "
print "The name is ", des.name
print "The idno is ", des.idno
print "The salary is ", des.salary