Gistrec

mpiaa_lab1_v2

Oct 12th, 2017
259
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import io
  2. from os import system as System
  3. from os import path as Path
  4. from math import ceil as Ceil
  5.  
  6. # Структура дома
  7. class House:
  8.  
  9.     address = "";
  10.     buildType = "";
  11.     buildDate = "";
  12.     floors = "";
  13.  
  14.     def __init__ (self, address, buildType, buildDate, floors):
  15.         self.address = address
  16.         self.buildType = buildType
  17.         self.buildDate = buildDate
  18.         self.floors = floors
  19.  
  20.     def __str__ (self):
  21.         return self.address + " " + self.buildType + " " + self.buildDate + " " + self.floors;
  22.  
  23.  
  24. class Houses:
  25.  
  26.     listHouse = []
  27.     count = 0
  28.  
  29.     housesInPage = 5
  30.  
  31.     def addHouse (self, house):
  32.         #if count(filter(lambda x: x.address == house.address, self.listHouse)) > 0:
  33.         for h in self.listHouse:
  34.             if house.address == h.address:
  35.                 print ("Дом по адреcу " + house.address + " уже есть в списке")
  36.                 return
  37.         self.listHouse.append(house)
  38.         self.count += 1
  39.  
  40.     def loadFromFile(self, path):
  41.         if Path.exists(path) == False:
  42.             print ("Файл не найден")
  43.             return
  44.         count = 0;
  45.         with io.open(path, encoding='utf-8') as file:
  46.             for line in file:
  47.                 house = line.replace("\n", "").split("|")
  48.                 newHouse = House(house[0], house[1], house[2], house[3])
  49.                 self.addHouse(newHouse)
  50.                 count += 1
  51.         print ("Добавлено " + str(count) + " записей")
  52.         self.count += count
  53.  
  54.     def printPage(self, numPage):
  55.         maxPage = Ceil(self.count / self.housesInPage);
  56.         print ("Выведена страница " + str(numPage) + " из " + str(maxPage - 1))
  57.         for row in range(int(self.housesInPage) * int(numPage), int(self.housesInPage) * (int(numPage) + 1)):
  58.             if row < self.count:
  59.                 print (str(row) + ": " + str(self.listHouse[row]))
  60.  
  61.     def setHousesInPage(self, count):
  62.         self.housesInPage = int(count)
  63.  
  64.  
  65.  
  66. System('cls')
  67. houses = Houses()
  68. #houses.loadFromFile("result.txt")
  69.  
  70.  
  71. while True:
  72.     print ("1 - Загрузить данные из файла")
  73.     print ("2 - Ввести данные вручную")
  74.     print ("3 - Постраничный вывод записей")
  75.     print ("4 - Установить кол-во записей на странице")
  76.     answer = input()
  77.     System('cls')
  78.     if answer == "1":
  79.         print ("Введите название файла")
  80.         houses.loadFromFile(input())
  81.     if answer == "2":
  82.         print ("Введите адрес, тип, дату постройки и кол-во этажей у здания")
  83.         print ("Разделитель |")
  84.         answer = input().split("|")
  85.         if len(answer) != 4:
  86.             print ("Введены некорректные данные")
  87.         else:
  88.             newHouse = House(answer[0], answer[1], answer[2], answer[3])
  89.             houses.addHouse(newHouse)
  90.             print ("Данные о доме добавлены")
  91.     elif answer == "3":
  92.         if houses.count == 0:
  93.             print ("Нет данных ни об одном доме")
  94.         else:
  95.             maxPage = Ceil(houses.count / houses.housesInPage);
  96.             print ("Введите номер страницы от 0 до " + str(maxPage - 1))
  97.             houses.printPage(input())
  98.     elif answer == "4":
  99.         print ("Введите кол-во записей, которые будут отображаться на странице");
  100.         houses.setHousesInPage(input())
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment