Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.47 KB | None | 0 0
  1. // Билеты.cpp: определяет точку входа для консольного приложения.
  2. //
  3. #include "stdafx.h"
  4. #include <iostream>
  5. #include <stdio.h>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. class Ticket_System
  11. {
  12. protected:
  13.     int uid; // уникальный номер
  14.     char* departure; // место отправления
  15.     char* arrival; // место прибытия
  16.     char* departure_time; // время отправления
  17.     char* arrival_time; // время прибытия
  18.     char* type; // класс билета
  19.     int price; // цена
  20. public:
  21.     Ticket_System(int = 0);
  22.     Ticket_System(int, const char*, const char*, const char*, const char*, const char*, int); //создание билета
  23.     void Show_Ticket(void); // показывает полную информацию о билете
  24.     int get_uid(void);
  25.     char* get_departure(void);
  26.     char* get_arrival(void);
  27.     char* get_departure_time(void);
  28.     char* get_arrival_time(void);
  29.     char* get_type(void);
  30.     int get_price(void);
  31. };
  32.  
  33. Ticket_System::Ticket_System(int a) : uid(0), departure(new char[1]), arrival(new char[1]), departure_time(new char[1]), arrival_time(new char[1]), type(new char[1]), price(0)
  34. {
  35.     departure = "\0";
  36.     arrival = "\0";
  37.     departure_time = "\0";
  38.     arrival_time = "\0";
  39.     type = "\0";
  40. }
  41.  
  42. Ticket_System::Ticket_System(int a1, const char* s1, const char* s2, const char* s3, const char* s4, const char* s5, int a2) : uid(a1), departure(new char[20]), arrival(new char[20]), departure_time(new char[10]), arrival_time(new char[10]), type(new char[3]), price(a2)
  43. {
  44.     strcpy_s(departure, strlen(s1) + 1, s1);
  45.     strcpy_s(arrival, strlen(s2) + 1, s2);
  46.     strcpy_s(departure_time, strlen(s3) + 1, s3);
  47.     strcpy_s(arrival_time, strlen(s4) + 1, s4);
  48.     strcpy_s(type, strlen(s5) + 1, s5);
  49. }
  50.  
  51. int Ticket_System::get_uid(void)
  52. {
  53.     return uid;
  54. }
  55.  
  56. char* Ticket_System::get_departure(void)
  57. {
  58.     return departure;
  59. }
  60.  
  61. char* Ticket_System::get_arrival(void)
  62. {
  63.     return arrival;
  64. }
  65.  
  66. char* Ticket_System::get_departure_time(void)
  67. {
  68.     return departure_time;
  69. }
  70.  
  71. char* Ticket_System::get_arrival_time(void)
  72. {
  73.     return arrival_time;
  74. }
  75.  
  76. char* Ticket_System::get_type(void)
  77. {
  78.     return type;
  79. }
  80.  
  81. int Ticket_System::get_price(void)
  82. {
  83.     return price;
  84. }
  85.  
  86. void Ticket_System::Show_Ticket(void)
  87. {
  88.     cout << "uid = " << uid << endl;
  89.     cout << "place1 = " << departure << endl;
  90.     cout << "place2 = " << arrival << endl;
  91.     cout << "date1 = " << departure_time << endl;
  92.     cout << "date2 = " << arrival_time << endl;
  93.     cout << "type = " << type << endl;
  94.     cout << "price = " << price << endl;
  95. }
  96.  
  97.  
  98. class User_account : public Ticket_System {
  99. protected:
  100.     vector <int> user_ticket_count;
  101. public:
  102.     int find_new_ticket(vector <Ticket_System>, int, const char*, const char*, const char*, const char*, const char*, int);
  103.     void buy_ticket(int, int);
  104.     void show_ticket_list(vector <Ticket_System> a);
  105. };
  106.  
  107. void User_account::buy_ticket(int, int uid) {
  108.     user_ticket_count.push_back(uid);
  109.     cout << "Thank's for your purchase!" << endl;
  110.     system("pause");
  111. }
  112.  
  113. int User_account::find_new_ticket(vector <Ticket_System> all_tickets, int uid, const char *departure,
  114.                                   const char * arrival, const char *deparure_time, const char *arrival_time,
  115.                                   const char *type, int price) {
  116.     for (int i = 0; i < all_tickets.size(); i++) {
  117.         if (all_tickets[i].get_arrival() == arrival and all_tickets[i].get_arrival_time() == arrival_time and
  118.                 all_tickets[i].get_departure() == departure and all_tickets[i].get_departure_time() == deparure_time and
  119.                 all_tickets[i].get_price() == price and all_tickets[i].get_type() == type) {
  120.             all_tickets[i].Show_Ticket();
  121.             cout << "/n" << endl;
  122.         }
  123.     }
  124.     cout << "End of the list of tickets" << endl;
  125.     return 0;
  126. }
  127.  
  128. void User_account::show_ticket_list(vector <Ticket_System> a) {
  129.     int c = 0;
  130.     for (int i = 0; i < user_ticket_count.size(); i++) {
  131.         if (a[i].get_uid() == user_ticket_count[c]) {
  132.             a[i].Show_Ticket();
  133.             c++;
  134.         }
  135.     }
  136. }
  137.  
  138.  
  139. int main()
  140. {
  141.     Ticket_System a[100]; // массив билетов
  142.     Ticket_System obj(1, "Moscow", "SPB", "23.04.2018", "25.04.2018", "bis", 2700);
  143.     a[0] = obj;
  144.     a[0].Show_Ticket();
  145.     system("pause");
  146.     return 0;
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement