diff --git a/Home_Task1.cpp b/Home_Task1.cpp new file mode 100644 index 0000000..44947c4 --- /dev/null +++ b/Home_Task1.cpp @@ -0,0 +1,151 @@ +//#include +//#include +//#define N 7 +//using namespace std; +//const int sz = 25; +//struct Marsh { +// char nomer[7] +// char marshBegin[sz];//Имя початкової зупинки +// char marshEnd[sz];//Имя останняй зупинки +// int count;//кількість зупинок +// int tm;//час між зупінками +// void init(); +// void show(); +//}; +// +//int main() +//{ +// Marsh marsh; +// int vUser; +// ofstream fout; +// fout.open(".\\Data\\info.dat", ios::binary); +// if (!fout.is_open()) { +// cerr << "Error: open file(out)\n"; +// system("pause"); +// return 1; +// } +// +// do { +// marsh.init(); +// fout.write(reinterpret_cast(&marsh), sizeof(Marsh)); +// } while (vUser != 0); +// fout.close(); +// ifstream fin; +// fin.open(".\\Data\\info.dat", ios::binary); +// if (!fin.is_open()) { +// cerr << "Error: open file(in)\n"; +// system("pause"); +// return 1; +// } +// fin.seekg(0, ios::end); +// int size = (int)fin.tellg(); +// int n = size/sizeof(M) +//} +//void Marsh::init() { +// cout << "Input nomer: "; +// cin.getline(nomer, N); +// cout << "Begin: "; +// cin.get(marshBegin, sz); +// cout << "End: "; +// cin.get(marshEnd, sz); +// cout << " count: "; +// cin >> tm; +// cin.ignore(); +//} +//void Marsh::show() { +// cout << "Nomer: " << nomer +// << "\nBegin: " << marshBegin +// << "\nEnd: " << marshEnd +// << "\n count: " << count + 2 +// << "\n time: " << fm << endl; +//} +// + +#include +#include +#define N 7 +using namespace std; +const int sz = 25; + +struct Marsh { + char nomer[7]; + char marshBegin[sz]; + char marshEnd[sz]; + int count; + int tm;//time + void init(); + void show(); +}; + +void show(Marsh* p, int n) { + for (int i = 0; i < n; ++i) + p[i].show(); +} + +int main() +{ + //".\\resFile\\infoMars.dat" + // Marsh marsh; + Marsh* pMarsh = new Marsh; + int vUser; + ofstream fout; + fout.open(".\\Data\\info.dat", ios::binary);//ios::out + if (!fout.is_open()) { + cerr << "Error: open file(out)\n"; + system("pause"); + return 1; + } + + do { + /*marsh.init(); + fout.write(reinterpret_cast(&marsh), sizeof(Marsh));*/ + pMarsh->init(); + fout.write(reinterpret_cast(pMarsh), sizeof(Marsh)); + cout << "Create Marsh?(1(Yes)/0(No) "; + cin >> vUser; + cin.ignore(); + } while (vUser != 0); + delete pMarsh; + fout.close(); + ifstream fIn; + fIn.open(".\\Data\\info.dat", ios::binary);//ios::out + if (!fIn.is_open()) { + cerr << "Error: open file(out)\n"; + system("pause"); + return 1; + } + fIn.seekg(0, ios::end); + int size = (int)fIn.tellg(); + int n = size / sizeof(Marsh);//n!=0 + pMarsh = new Marsh[n]; + fIn.seekg(0); + for (int i = 0; i < n; ++i) { + fIn.read(reinterpret_cast(pMarsh + i), sizeof(Marsh)); + } + fIn.close(); + show(pMarsh, n); + delete[] pMarsh; + system("pause"); +} +void Marsh::init() { + cout << "Input nomer: "; + cin.getline(nomer, N); + cout << "Begin: "; + cin.getline(marshBegin, sz); + cout << "End: "; + cin.getline(marshEnd, sz); + cout << " count: "; + cin >> count; + cout << "midle time: "; + cin >> tm; + cin.ignore(); +} +void Marsh::show() { + cout << "Nomer: " << nomer + << "\nBegin: " << marshBegin + << "\n End: " << marshEnd + << "\n count: " << count + 2 + << "\n time: " << tm << endl; +} + +