Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma hdrstop
- #pragma argsused
- #ifdef _WIN32
- #include <tchar.h>
- #else
- typedef char _TCHAR;
- #define _tmain main
- #endif
- #include <iostream>
- #include <cstring>
- #include <conio.h>
- using namespace std;
- class Railway
- {
- char* destination = new char[15];
- char* time = new char[15];
- int numberOfFreeTickets;
- int ticketPrice;
- int profit;
- public:
- Railway()
- {
- inputInfo();
- }
- void inputInfo()
- {
- printf("\nDestination: ");
- scanf("%s", destination);
- printf("Time: ");
- scanf("%s", time);
- printf("Number of tickets: ");
- scanf("%d", &numberOfFreeTickets);
- printf("Ticket price: ");
- scanf("%d", &ticketPrice);
- profit = numberOfFreeTickets * ticketPrice;
- }
- void outputInfo()
- {
- printf("%15s|", destination);
- printf("%15s|", time);
- printf("%10d|", numberOfFreeTickets);
- printf("%10d|", ticketPrice);
- printf("%10d|", profit);
- printf("\n");
- }
- void setDestination(char *destination)
- {
- delete [] this->destination;
- this->destination = destination;
- }
- char* getDestination()
- {
- return destination;
- }
- void setTime(char *time)
- {
- delete [] this->time;
- this->time = time;
- }
- char* getTime()
- {
- return time;
- }
- void setNumberOfFreeTickets(int numberOfFreeTickets)
- {
- this->numberOfFreeTickets = numberOfFreeTickets;
- profit = numberOfFreeTickets * ticketPrice;
- }
- int getNumberOfFreeTickets()
- {
- return numberOfFreeTickets;
- }
- void setTicketPrice(int ticketPrice)
- {
- this->ticketPrice = ticketPrice;
- profit = numberOfFreeTickets * ticketPrice;
- }
- int getTicketPrice()
- {
- return ticketPrice;
- }
- int getProfit()
- {
- return profit;
- }
- ~Railway()
- {
- delete [] destination;
- delete [] time;
- }
- };
- class Admin
- {
- int count;
- Railway** Array;
- void outputHead()
- {
- printf(" Destination|");
- printf(" Time|");
- printf(" Count|");
- printf(" Price|");
- printf(" Profit|");
- printf("\n");
- }
- void outputLine()
- {
- printf("-----------------------------------------------------------------\n");
- }
- public:
- Admin()
- {
- count = 0;
- }
- void inputArray()
- {
- printf("Input number of tickets: ");
- scanf("%d", &count);
- Array = new Railway*[count];
- for(int i = 0; i < count; i++)
- Array[i] = new Railway();
- }
- void outputArray()
- {
- outputHead();
- outputLine();
- for(int i = 0; i < count; i++)
- {
- Array[i]->outputInfo();
- outputLine();
- }
- }
- void addElement()
- {
- count++;
- Railway** temp = new Railway*[count];
- for(int i = 0; i < count - 1; i++)
- temp[i] = Array[i];
- temp[count - 1] = new Railway();
- delete [] Array;
- Array = temp;
- }
- void findByDestination()
- {
- char destination[15];
- printf("\nDestination: ");
- scanf("%s", destination);
- outputHead();
- outputLine();
- for(int i = 0; i < count; i++)
- {
- if(strcmp(destination, Array[i]->getDestination()) == 0)
- {
- Array[i]->outputInfo();
- outputLine();
- }
- }
- }
- void deleteElement()
- {
- int i = 0;
- char destination[15];
- printf("\nDestination: ");
- scanf("%s", destination);
- while(i < count)
- {
- if(strcmp(destination, Array[i]->getDestination()) == 0)
- {
- for(int j = i + 1; j < count; j++)
- Array[j - 1] = Array[j];
- count--;
- }
- i++;
- }
- }
- void editElement()
- {
- char time[15];
- char* newTime = new char[15];
- printf("\nTime: ");
- scanf("%s", time);
- printf("\nNew Time: ");
- scanf("%s", newTime);
- for(int i = 0; i < count; i++)
- {
- if(strcmp(time, Array[i]->getTime()) == 0)
- {
- Array[i]->setTime(newTime);
- }
- }
- printf("Well done");
- }
- void sortArray()
- {
- for (int i = 0; i < count - 1; i++)
- {
- for (int j = i + 1; j < count; j++)
- {
- if (strcmp(Array[i]->getTime(), Array[j]->getTime()) < 0)
- {
- Railway* temp = Array[i];
- Array[i] = Array[j];
- Array[j] = temp;
- }
- }
- }
- printf("Well done");
- }
- void menu()
- {
- while(true)
- {
- system("cls");
- printf("1.Fill array\n2.Output array\n3.Add element\n4.Find by destination\n5.Delete element\n6.Edit element\n7.Sort array\n8.exit\n");
- int choose;
- scanf("%d", &choose);
- switch(choose)
- {
- case 1:
- {
- inputArray();
- break;
- }
- case 2:
- {
- outputArray();
- break;
- }
- case 3:
- {
- addElement();
- break;
- }
- case 4:
- {
- findByDestination();
- break;
- }
- case 5:
- {
- deleteElement();
- break;
- }
- case 6:
- {
- editElement();
- break;
- }
- case 7:
- {
- sortArray();
- break;
- }
- case 8:
- {
- return;
- }
- }
- getch();
- }
- }
- ~Admin()
- {
- delete [] Array;
- }
- };
- int main()
- {
- Admin a;
- a.menu();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement