วันจันทร์ที่ 26 ตุลาคม พ.ศ. 2558

Display student records, sorted by age, use insertion sort.

class Students:
   def __init__(self,name,ID,age,weight,height):
      self.name = name
      self.ID = ID
      self.age = age
      self.weight = weight
      self.height = height
   
   def display(self):
      print("Name:",self.name)
      print("ID:",self.ID)
      print("Age:",self.age)
      print("Weight:",self.weight)
      print("Height:",self.height)
      print()
     
   def get_name(self):
      return self.name
   def get_ID(self):
      return self.ID
   def get_age(self):
      return self.age
   def get_weight(self):
      return self.weight
   def get_height(self):
      return self.height
 
   def set_name(self,name):
      self.name = name
   def set_ID(self,ID):
      self.ID = ID
   def set_age(self,age):
      self.age = age
   def set_weight(self,weight):
      self.weight = weight
   def set_height(self,height):
      self.height = height
   
def setup():
   a = Students("Gun", 32075, 26, 90, 174)
   b = Students("Rit", 32078, 25, 80, 170)
   c = Students("Frame", 32080, 19, 48, 173)
   d = Students("Boat", 32057, 16, 70, 168)
   nukrean = [a, b, c, d]
   sort(nukrean)
   a.display()
   b.display()
   c.display()
   d.display()

def sort(nukrean):
   i = 1
   while(i < len(nukrean)):
      value_a = nukrean[i].get_age()
      value_n = nukrean[i].get_name()
      value_I = nukrean[i].get_ID()
      value_w = nukrean[i].get_weight()
      value_h = nukrean[i].get_height()
      j = i
      while(j>0 and nukrean[j-1].get_age() > value_a):
         nukrean[j].set_age(nukrean[j-1].get_age())
         nukrean[j].set_name(nukrean[j-1].get_name())
         nukrean[j].set_ID(nukrean[j-1].get_ID())
         nukrean[j].set_weight(nukrean[j-1].get_weight())
         nukrean[j].set_height(nukrean[j-1].get_height())
         j = j - 1
      nukrean[j].set_age(value_a)
      nukrean[j].set_name(value_n)
      nukrean[j].set_ID(value_I)
      nukrean[j].set_weight(value_w)
      nukrean[j].set_height(value_h)
      i += 1
 
setup()

ไม่มีความคิดเห็น:

แสดงความคิดเห็น

Link Video Presentation Resort Managemant System Project.

Video Presentation Resort Managemant System Project. จัดทำโดย พากษ์เสียง: คุณาสิน  ทองมณี  5801012620011 ลำดับภาพ: สุพิชชา  ศรีศิริ...