Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cstdlib> // для использования функции exit()
- #define M 30
- #define N 3
- using namespace std;
- struct AEROFLOT {
- char punkt[M];
- char numb[M];
- char type[M];
- };
- int reed() {
- using namespace std;
- // ifstream используется для чтения содержимого файлов.
- // Мы попытаемся прочитать содержимое файла SetText.txt
- ifstream inf("SetText.txt");
- // Если мы не можем открыть файл для чтения его содержимого,
- if (!inf)
- {
- // то выводим следующее сообщение об ошибке и выполняем функцию exit()
- cerr << "SetText.txt could not be opened for reading!" << endl;
- exit(1);
- }
- // Пока есть, что читать,
- while (inf)
- {
- // то перемещаем то, что можем прочитать, в строку, а затем выводим эту строку на экран
- string strInput;
- getline(inf, strInput);
- cout << strInput << endl;
- }
- return 0;
- }
- int main()
- {
- AEROFLOT fly[N];
- int i;
- int key = 0;
- tryAgain:
- cout << "1 - zadat massiv" << endl;
- cout << "2 - vyvod massiva" << endl;
- cout << "3 - sohranenie v fail" << endl;
- cout << "4 - vyvod po typ plan" << endl;
- cout << "5 - vyvod massiva iz faila" << endl;
- cout << "6 - Exit" << endl;
- cin >> key;
- if (key == 1) {
- for (i = 0; i < N; i++) {
- cout << "\nSET N reis: "; cin >> fly[i].numb;
- cout << "\nSET TYPE plane: "; cin >> fly[i].type;
- cout << "\nSET destination "; cin >> fly[i].punkt;
- }
- char cur[M];
- for (i = 0; i < N - 1; i++)
- for (int j = i + 1; j < N; j++)
- if (strcmp(fly[i].punkt, fly[j].punkt) > 0)
- {
- strcpy_s(cur, fly[i].punkt);
- strcpy_s(fly[i].punkt, fly[j].punkt);
- strcpy_s(fly[j].punkt, cur);
- }
- }
- if (key == 2) {
- cout << "\n________________________________________________________\n";
- for (i = 0; i < N; i++) {
- cout << fly[i].punkt << " " << fly[i].numb << " " << fly[i].type << endl;
- }
- }
- char temp[M];
- int count;
- if (key == 3) {
- using namespace std;
- ofstream outf("SetText.txt");
- if (!outf)
- {
- cerr << "SetText.txt could not be opened for writing!" << endl;
- exit(1);
- }
- for (i = 0; i < N; i++) {
- outf << fly[i].punkt << " " << fly[i].numb << " " << fly[i].type << endl;
- }
- }
- if (key == 4) {
- while (strcmp(temp, "exit")) {
- cout << "\nDlay vyhoda set 'exit'";
- cout << "\nSpecify typ plan : "; cin >> temp;
- count = 0;
- for (i = 0; i < N; i++) {
- if (strcmp(fly[i].type, temp) == 0) {
- cout << endl << fly[i].punkt << " " << fly[i].numb << endl;
- count++;
- }
- }
- if (count == 0) cout << endl << " None the plan \n";
- }
- }
- if (key == 5) {
- reed();
- }
- if (key == 6) {
- return 0;
- }
- goto tryAgain;
- }
Advertisement
Add Comment
Please, Sign In to add comment