Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include<iostream>
- #include "Flight.h"
- using namespace std;
- const char* FILE_NAME = "Planes.db";
- const int NUM_OF_FLIGHTS = 1024;
- const int MAX_SIZE = 1024;
- bool saveFlights(const Flight& toAdd)
- {
- ofstream file(FILE_NAME, ios::app);
- if (!file.is_open())
- return false;
- file << toAdd.getId() << " " << toAdd.getPlane() << " " << toAdd.getType() << " " << toAdd.getFlights() << endl;
- file.close();
- return true;
- }
- int searchFlight(const Flight* collection, int planesCount, int id)
- {
- for (int i = 0; i < planesCount; i++)
- {
- if (collection[i].getId() == id)
- {
- return i;
- }
- }
- return -1;
- }
- int CountOfPlanes(const char* fileName)
- {
- ifstream file(FILE_NAME);
- if (!file.is_open())
- return -1;
- int planesCount = 0;
- while (!file.eof())
- {
- char buff[MAX_SIZE];
- file.getline(buff, MAX_SIZE);
- planesCount++;
- }
- file.close();
- return planesCount;
- }
- void create(Flight& init) {
- std::cout << "Enter id: ";
- int id;
- std::cin >> id;
- std::cout << "Enter flights: ";
- int flights;
- std::cin >> flights;
- std::cout << "Enter plane type: ";
- char planeType[1024];
- std::cin >> planeType;
- char planeName[1024];
- std::cout << "Enter plane name: ";
- std::cin >> planeName;
- Flight fl(id, planeName, planeType, flights); //creating object
- init = fl;
- }
- void readFlight(const char* input, Flight* collection, int num)
- {
- int index = 0;
- int id = 0;
- int flights = 0;
- char plane[MAX_SIZE];
- char type[20];
- while (input[index] != ' ')
- {
- id *= 10;
- id += input[index++] - '0';
- }
- index++;
- int newInd = 0;
- while (input[index] != ' ')
- plane[newInd++] = input[index++];
- plane[newInd] = '\0';
- index++;
- newInd = 0;
- while (input[index] != ' ')
- type[newInd++] = input[index++];
- type[newInd] = '\0';
- index++;
- while (input[index] != '\0')
- {
- flights *= 10;
- flights += input[index++] - '0';
- }
- collection[num].setId(id);
- collection[num].setPlane(plane);
- collection[num].setType(type);
- collection[num].setFlights(flights);
- }
- void Command(char command[], char input[], Flight* collection, int num, int planesCount, int id)
- {
- if (strcmp(command, "create") == 0)
- {
- Flight addMe;
- create(addMe);
- saveFlights(addMe);
- }
- else if (strcmp(command, "search") == 0)
- {
- cin >> id;
- cout << "Results:" << endl;
- searchFlight(collection, planesCount, id);
- }
- else if (strcmp(command, "exit") == 0)
- return;
- }
- int main()
- {
- }
- /*
- 1. работещ интерфейс
- 2. rething readFlight
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement