Gistrec

mpiaa_lab1_v1

Oct 12th, 2017
266
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.97 KB | None | 0 0
  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.  
  39.     def loadFromFile(self, path):
  40.         if Path.exists(path) == False:
  41.             print ("Файл не найден")
  42.             return
  43.         count = 0;
  44.         with io.open(path, encoding='utf-8') as file:
  45.             for line in file:
  46.                 house = line.replace("\n", "").split("|")
  47.                 newHouse = House(house[0], house[1], house[2], house[3])
  48.                 self.addHouse(newHouse)
  49.                 count += 1
  50.         print ("Добавлено " + str(count) + " записей")
  51.         self.count += count
  52.  
  53.     def printPage(self, numPage):
  54.         maxPage = Ceil(self.count / self.housesInPage);
  55.         print ("Выведена страница " + str(numPage) + " из " + str(maxPage))
  56.         for page in range(int(self.housesInPage) * int(numPage), int(self.housesInPage) * (int(numPage) + 1)):
  57.             if page < self.count:
  58.                 print (str(self.listHouse[page]))
  59.  
  60.     def setHousesInPage(self, count):
  61.         self.housesInPage = int(count)
  62.  
  63. System('cls')
  64. houses = Houses()
  65. houses.loadFromFile("result.txt")
  66.  
  67.  
  68. while True:
  69.     print ("1 - Загрузить данные из файла")
  70.     print ("2 - Ввести данные вручную")
  71.     print ("3 - Постраничный вывод записей")
  72.     print ("4 - Установить кол-во записей на странице")
  73.     answer = input()
  74.     System('cls')
  75.     if answer == "1":
  76.         print ("Введите название файла")
  77.         houses.loadFromFile(input())
  78.     if answer == "2":
  79.         print ("Введите адрес, тип, дату постройки и кол-во этажей у здания")
  80.         print ("Разделитель |")
  81.         answer = input().split("|")
  82.         if len(answer) != 4:
  83.             print ("Введены некорректные данные")
  84.         else:
  85.             newHouse = House(answer[0], answer[1], answer[2], answer[3])
  86.             houses.addHouse(newHouse)
  87.     elif answer == "3":
  88.         maxPage = Ceil(houses.count / houses.housesInPage);
  89.         print ("Введите номер страницы от 0 до " + str(maxPage))
  90.         houses.printPage(input())
  91.     elif answer == "4":
  92.         print ("Введите кол-во записей, которые будут отображаться на странице");
  93.         houses.setHousesInPage(input())
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment