Следующая программа: include #include <vector> #include <istream> #include <fstream>…
- User
Следующая программа: include #include #include #include #include
struct Date { int day; int month; int year;
Date(int d, int m, int y) : day(d), month(m), year(y) {}
bool operator>(const Date& other) const { if (year > other.year) { return true; } else if (year == other.year && month > other.month) { return true; } else if (year == other.year && month == other.month && day > other.day) { return true; } return false; }
bool operator<(const Date& other) const { return !(operator>(other) || operator==(other)); }
bool operator==(const Date& other) const { return (year == other.year && month == other.month && day == other.day); } };
struct GroupNumber { char letter; int number;
GroupNumber(char l, int n) : letter(l), number(n) {}
bool operator>(const GroupNumber& other) const { if (letter > other.letter) { return true; } else if (letter == other.letter && number > other.number) { return true; } return false; }
bool operator<(const GroupNumber& other) const { return !(operator>(other) || operator==(other)); }
bool operator==(const GroupNumber& other) const { return (letter == other.letter && number == other.number); } };
struct Fio { std::string surname; std::string name; std::string patronymic;
Fio(std::string s, std::string n, std::string p) : surname(s), name(n), patronymic§ {}
bool operator>(const Fio& other) const { if (surname > other.surname) { return true; } else if (surname == other.surname && name > other.name) { return true; } else if (surname == other.surname && name == other.name && patronymic > other.patronymic) { return true; } return false; }
bool operator<(const Fio& other) const { return !(operator>(other) || operator==(other)); }
bool operator==(const Fio& other) const { return (surname == other.surname && name == other.name && patronymic == other.patronymic); } };
struct Sorts { Fio fios; GroupNumber groupNumbers; int n; Sorts(const Fio& f, const GroupNumber& g, int num) : fios(f), groupNumbers(g), n(num) {} };
std::vector readFromFile(const std::string& filename) { std::vector sorts; std::ifstream file(filename); int n = 0;
if (file.is_open()) { std::string surname, name, patronymic; char letter; int number;
while (file >> surname >> name >> patronymic >> letter >> number) { Fio fio(surname, name, patronymic); GroupNumber groupNumber(letter, number); sorts.push_back(Sorts(fio, groupNumber, n)); n += 1; }
file.close(); } else { std::cerr << “Enable open file” << filename << std::endl; }
return sorts; }
int partOfQuickSort(std::vector& sorts, int start, int end) { int left = start;
for (int i = start; i < end; i++) { if (sorts[i].fios < sorts[end].fios || sorts[i].fios == sorts[end].fios || sorts[i].groupNumbers < sorts[end].groupNumbers || sorts[i].groupNumbers == sorts[end].groupNumbers) { Sorts temp = sorts[left]; sorts[left] = sorts[i]; sorts[i] = temp; left++; } } Sorts temp = sorts[left]; sorts[left] = sorts[end]; sorts[end] = temp; return left; } void quickSort(std::vector& sorts, int start, int end) { if (start >= end) return; int rightStart = partOfQuickSort(sorts, start, end); quickSort(sorts, start, rightStart); quickSort(sorts, rightStart + 1, end); } void quickSort(std::vector& sorts) { quickSort(sorts, 0, sorts.size()); } double quickSortWithTime(std::vector& sorts) { double timeQuick; auto start = std::chrono::high_resolution_clock::now(); quickSort(sorts); auto end = std::chrono::high_resolution_clock::now(); std::chrono::duration duration = end - start; timeQuick = duration.count(); return timeQuick; } void writeFileQuickSort(std::string readFile, std::string file) { std::vector sorts = readFromFile(readFile); std::ofstream out(file);
- Assistant
Программа крашится на этой строке из-за опечатки в коде. В структуре Fio, в конструкторе, вместо символа "§" должна быть запятая (","). Исправленный код должен выглядеть следующим образом:
cppFio(std::string s, std::string n, std::string p) : surname(s), name(n), patronymic(p) {}После внесения этой исправления программа должна работать без ошибок.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.