Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /
- //#define _CRT_SECURE_NO_WARNINGS
- #include "stdafx.h"
- #include "iostream"
- #include <string>
- #include <sstream>
- #include <limits>
- #include <locale.h>
- #include <limits>
- #include <iomanip>
- #include <fstream>
- #include <io.h>
- using namespace std;
- class Fio
- {
- private:
- char* familia_;
- char* imya_;
- char* otchestvo_;
- public:
- Fio()
- {
- familia_ = new char[512];
- imya_ = new char[512];
- otchestvo_ = new char[512];
- }
- void setFio(char *familia, char *imya, char *otchestvo)
- {
- familia_ = familia;
- imya_ = imya;
- otchestvo_ = otchestvo;
- }
- string getStringFio()
- {
- string familia = to_string(*familia_);
- string imya = to_string(*imya_);
- string otchestvo = to_string(*otchestvo_);
- return (familia + " " + imya + " " + otchestvo);
- }
- char* getCharFio()
- {
- char* fio = new char[1024];
- char c4[] = " ";
- memset(fio, 0, strlen(fio));
- strcat(fio, familia_);
- strcat(fio, c4);
- strcat(fio, imya_);
- strcat(fio, c4);
- strcat(fio, otchestvo_);
- return fio;
- }
- };
- class Train
- {
- private:
- Fio fio_; // пассажир
- char* point_from; // пункт отправления
- char* point_to; // пункт прибытия
- double price; // цена билета
- class Train *next;
- class Train *prev;
- friend void PriceCheck();
- friend void SortyByDepart();
- friend Train* Swap(Train* );
- friend void PrintDataTrain();
- public:
- Train()
- {
- point_to = new char[1024];
- point_from = new char[1024];
- prev = NULL;
- next = NULL;
- }
- ~Train()
- {
- delete[] point_to;
- delete[] point_from;
- delete[] &fio_;
- }
- Train* loadFromFile(const string filename)
- {
- Train *prevTrain = NULL;
- Train *nextTrain;
- string fio_line, departure_line, destination_line, price_line;
- ifstream dataFile(filename, ios::in);
- if (!dataFile.is_open()) {
- cout << "File cannot be open. Check is the file is there.\n";
- }
- else {
- string name, surname, patronyc;
- double price;
- char* name_ = new char[512]; char* surname_ = new char[512]; char* patronyc_ = new char[512];
- while (getline(dataFile, fio_line) &&
- getline(dataFile, departure_line) &&
- getline(dataFile, destination_line) &&
- getline(dataFile, price_line))
- {
- istringstream iss(fio_line);
- if (!(iss >> name >> surname >> patronyc))
- break;
- nextTrain = new Train();
- memset(name_, 0, strlen(name_));
- memcpy(name_, name.c_str(), name.size());
- memset(surname_, 0, strlen(surname_));
- memcpy(surname_, surname.c_str(), surname.size());
- memset(patronyc_, 0, strlen(patronyc_));
- memcpy(patronyc_, patronyc.c_str(), patronyc.size());
- Fio fio;
- fio.setFio(name_, surname_, patronyc_);
- price = atof(price_line.c_str());
- if (!price) {
- cout << "Error. Wrong type of variable. Check information in the file.\n";
- break;
- }
- nextTrain->fio_ = fio;
- nextTrain->price = price;
- memset(nextTrain->point_from, 0, strlen(nextTrain->point_from));
- memcpy(nextTrain->point_from, departure_line.c_str(), departure_line.size());
- memset(nextTrain->point_to, 0, strlen(nextTrain->point_to));
- memcpy(nextTrain->point_to, destination_line.c_str(), destination_line.size());
- if (prevTrain)
- prevTrain->next = nextTrain;
- nextTrain->prev = prevTrain;
- //nextTrain->next = NULL;
- prevTrain = nextTrain;
- }
- Train *start_of_list = NULL;
- start_of_list = prevTrain;
- while (start_of_list->prev)
- start_of_list = start_of_list->prev;
- return start_of_list;
- }
- }
- };
- void PrintDataTrain()
- {
- //trip = ReadingFile();
- Train *p = NULL;
- p = p->loadFromFile("File_1.txt");
- if (p != NULL) {
- int r = 0;
- cout << "\n\n";
- cout << setw(3) << right << r << " : ";
- cout << setw(30) << left << "Passenger";
- cout << setw(18) << "Departure point";
- cout << setw(14) << "Destination";
- cout << setw(7) << "Price";
- cout << endl;
- cout << ".............................................." << endl;
- while (p != NULL)
- {
- r++;
- cout << setw(3) << right << r << " : ";
- cout << setw(30) << left << p->fio_.getStringFio();
- cout << setw(18) << p->point_from;
- cout << setw(14) << p->point_to;
- cout << setw(7) << p->price;
- //cout << "\n";
- // p = p->next;
- cout << endl;
- p = p->next;
- }
- cout << "______________________________________________" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement