Advertisement
apl-mhd

SPL project

May 4th, 2024
684
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct show
  5. {
  6.    char name[255];
  7.    char date[255];
  8.    int total_ticket;
  9.    int ticket_available;
  10.    int price;
  11. };
  12.  
  13. void addShow(struct show *listings, int *numShows)
  14. {
  15.  
  16.    char name[255];
  17.    char date[255];
  18.    int total_ticket;
  19.    int ticket_available;
  20.    int price;
  21.  
  22.    // scanf("%s", &b);
  23.    char a;
  24.    printf("------------------------------------------------\n");
  25.  
  26.    printf("Name of the show : ");
  27.    getchar(); // consume new line
  28.    gets(listings[*numShows].name);
  29.  
  30.    printf("When will it go live : ");
  31.    gets(listings[*numShows].date);
  32.  
  33.    printf("Total tickets: ");
  34.    scanf("%d", &listings[*numShows].total_ticket);
  35.  
  36.    printf("Tickets currently available: ");
  37.    scanf("%d", &listings[*numShows].ticket_available);
  38.  
  39.    printf("Ticket price: ");
  40.    scanf("%d", &listings[*numShows].price);
  41.  
  42.    // printf("------------------------------------------------\n");
  43.    // printf("Name of the show: %s\n", listings[*numShows].name);
  44.    // printf("Shows at: %s\n", listings[*numShows].date);
  45.    // printf("Total tickets: %d\n", listings[*numShows].total_ticket);
  46.    // printf("Tickets currently available: %d\n", listings[*numShows].ticket_available);
  47.    // printf("Ticket price: %d\n", listings[*numShows].price);
  48.  
  49.    *numShows += 1;
  50. }
  51.  
  52. void displayShows(struct show *listings, int numShows)
  53. {
  54.    printf("------------------------------------------------\n");
  55.    for (int i = 0; i < numShows; i++)
  56.    {
  57.       printf("Show no %d\n", i + 1);
  58.       printf("Name of the show: %s\n", listings[i].name);
  59.       printf("Shows at: %s\n", listings[i].date);
  60.       printf("Total tickets: %d\n", listings[i].total_ticket);
  61.       printf("Tickets currently available: %d\n", listings[i].ticket_available);
  62.       printf("Ticket price: %d\n", listings[i].price);
  63.       printf("\n");
  64.    }
  65. }
  66.  
  67. void bookTicket(struct show *listing, int numShows, char *showName)
  68. {
  69.  
  70.    for (int i = 0; i < numShows; i++)
  71.    {
  72.  
  73.       int len = 0;
  74.       while (showName[len] != '\0')
  75.       {
  76.          len++;
  77.       }
  78.       printf("%d", len);
  79.    }
  80. };
  81.  
  82. int main()
  83. {
  84.  
  85.    struct show showsArray[500];
  86.  
  87.    int numShows = 0;
  88.    int menu = 1;
  89.  
  90.    while (menu != 6)
  91.    {
  92.  
  93.       printf("1. Add a show\n");
  94.       printf("2. Book a ticket\n");
  95.       printf("3. List out the shows\n");
  96.       printf("4. Save to file\n");
  97.       printf("5. Load from file\n");
  98.       printf("6. Exit\n");
  99.  
  100.       scanf("%d", &menu);
  101.       if (menu == 1)
  102.       {
  103.          addShow(showsArray, &numShows);
  104.       }
  105.       else if (menu == 3)
  106.       {
  107.          displayShows(showsArray, numShows);
  108.       }
  109.       printf("------------------------------------------------\n");
  110.    }
  111.  
  112.  
  113.  
  114.    return 0;
  115. }
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement