Skip to content

First received version#1

Open
treplen wants to merge 1 commit intomasterfrom
SubwayLine
Open

First received version#1
treplen wants to merge 1 commit intomasterfrom
SubwayLine

Conversation

@treplen
Copy link
Owner

@treplen treplen commented Dec 22, 2018

No description provided.

Copy link
Owner Author

@treplen treplen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void setName(std::string name); //изменить имя линии (проверяет корректность всех пересадок)
std::string name() const { return m_name; } //получить имя линии
size_t length() const { return m_stations.size(); } //получить длину линии (количество станций)
void addStation(std::string name, size_t position); //добавить станцию (имя станции и позиция на линии)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавить какую именно из станций, только беспересадочную? Принято передавать включаемый элемент в методе добавления. То есть:
void addStation(const Station& station);
Где station копируется (нужен виртуальный метод копирования) в наш контейнер.

std::string name() const { return m_name; } //получить имя линии
size_t length() const { return m_stations.size(); } //получить длину линии (количество станций)
void addStation(std::string name, size_t position); //добавить станцию (имя станции и позиция на линии)
const Station* find(std::string name) const; //поиск станции по имени
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Возвращать константный указатель это хорошее решение, но во-первых лучше было бы вернуть по ссылке а не по указателю, а во-вторых - что если нужно найти станцию и изменить ее состояние? Обычно для этого делают 2 метода с абсолютно одинаковым кодом:
Station& find(std::string name);
const Station& find(std::string name) const;
Отличие только в том что второй константный а первый нет

size_t length() const { return m_stations.size(); } //получить длину линии (количество станций)
void addStation(std::string name, size_t position); //добавить станцию (имя станции и позиция на линии)
const Station* find(std::string name) const; //поиск станции по имени
const Station* findTransfer(std::string name) const; //поиск пересадки по имени станции, на котрую происходит пересадка
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Таких станций может быть несколько, а возвращается только одна
  • То же самое что в предыдущей строке
  • Этот метод вообще нужен не здесь а в приложении, нужно перенести в класс приложения и там печатать сразу все подходящие станции

void addStation(std::string name, size_t position); //добавить станцию (имя станции и позиция на линии)
const Station* find(std::string name) const; //поиск станции по имени
const Station* findTransfer(std::string name) const; //поиск пересадки по имени станции, на котрую происходит пересадка
void addTransfer(size_t position, std::string station, std::string line); //добавить пересадку
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь этот метод не нужен. Чтобы добавить станцию:
line.find(stationName)->AddTransfer(TransferStation, TransferLine);

void addTransfer(size_t position, std::string station, std::string line); //добавить пересадку
//со станции на position, на station на линии line
void deleteStation(std::string name); //удалить станцию по имени
std::string getType(std::string) const; //получить тип станции по её имени
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь этот метод не нужен. Чтобы получить тип:
line.find(stationName)->getType();

//добавить пересадку, возвращает указатель на новую станцию другого типа, которой нужно заменить старую
virtual Station* addTransfer(std::string station, std::string line) const;
virtual bool consistTransfer(std::string name) const; //проверяет наличии пересадки на станцию с заданным именем
virtual std::string getType() const; //возвращает строку типа станции
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Гораздо лучше завести enum и возвращать результат с его типом

virtual std::ostream& print(std::ostream&) const; //перегружаемая функция для вывода
public:
//StationUT() :Station("") , count (0) {} //пустой конструктор
StationUT(std::string name, size_t count, const std::string* lines); //конструктор по имени и массиву линий
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вместо количества и массива линий лучше сразу передавать std::vectorstd::string

namespace Library
{
//класс станций с пересадкой на одноимённую
class StationUT : public Station
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не хватает методов из задания:

  • Вернуть перечень названий линий перехода: std::vector<std::string> getTransfers() const
  • Добавить название линии перехода: void addTransfer(std::string lineName)


virtual std::ostream& print(std::ostream&) const; //перегружаемая функция для вывода
public:
StationNT(std::string name, size_t count, const std::string* lines, const std::string* stations); //конструктор с аргументами
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно использовать std::vector

namespace Library
{
//класс станций с пересадкой на станции с другим названием
class StationNT : public StationUT
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не хватает метода из задания получения перечня пересадок

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant