Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Matrix
- {
- class Program
- {
- const int SHOW_NAME = 0;
- const int SHOW_ARTIST = 1;
- const int SHOW_PRICE = 2;
- const int SHOW_TYPE = 3;
- const int SHOW_GENRE = 4;
- static void Main(string[] args)
- {
- string[,] liveShow = new string[0, 5];
- int totalSales = 0;
- int option = 0;
- do
- {
- Console.WriteLine("1. Show all concerts\n2. Show all concerts by Genre Name\n3. Add a new concert\n4. Buy concert ticket\n5. Show total sales\n6. Exit");
- option = int.Parse(Console.ReadLine());
- switch(option)
- {
- case 1:
- PrintConcerts(liveShow);
- break;
- case 2:
- Console.Write("Enter the name of the genre: ");
- string genre = Console.ReadLine();
- bool found = false;
- for(int i = 0; i < liveShow.GetLength(0); i++)
- {
- if (genre == liveShow[i, SHOW_GENRE])
- {
- Console.WriteLine($"[Concert {i + 1}] Name: {liveShow[i, SHOW_NAME]}, Artist: {liveShow[i, SHOW_ARTIST]}, Price: {liveShow[i, SHOW_PRICE]}, Ticket: {liveShow[i, SHOW_TYPE]}, Genre: {liveShow[i, SHOW_GENRE]}");
- found = true;
- }
- }
- if (found == false) Console.WriteLine($"No {genre} concerts were found!");
- break;
- case 3:
- if(liveShow.GetLength(0) >= 10)
- {
- Console.WriteLine("No more slots!");
- }
- else
- {
- string[] ConcertDetails = new string[5];
- Console.Write("Please enter the concert's name: ");
- ConcertDetails[SHOW_NAME] = Console.ReadLine();
- Console.Write("Please enter the artist's name: ");
- ConcertDetails[SHOW_ARTIST] = Console.ReadLine();
- Console.Write("Please enter the ticket's price: ");
- ConcertDetails[SHOW_PRICE] = Console.ReadLine();
- Console.Write("Please enter the ticket's type: ");
- ConcertDetails[SHOW_TYPE] = Console.ReadLine();
- Console.Write("Please enter the concert's genre: ");
- ConcertDetails[SHOW_GENRE] = Console.ReadLine();
- liveShow = ModifiedStringArray(liveShow, 1); // Add +1 slot at rank 0
- liveShow[liveShow.GetLength(0) - 1, SHOW_NAME] = ConcertDetails[SHOW_NAME];
- liveShow[liveShow.GetLength(0) - 1, SHOW_ARTIST] = ConcertDetails[SHOW_ARTIST];
- liveShow[liveShow.GetLength(0) - 1, SHOW_PRICE] = ConcertDetails[SHOW_PRICE];
- liveShow[liveShow.GetLength(0) - 1, SHOW_TYPE] = ConcertDetails[SHOW_TYPE];
- liveShow[liveShow.GetLength(0) - 1, SHOW_GENRE] = ConcertDetails[SHOW_GENRE];
- Console.WriteLine($"Concert #{liveShow.GetLength(0)} \"{ConcertDetails[SHOW_NAME]}\" was successfully added!");
- }
- break;
- case 4:
- PrintConcerts(liveShow);
- Console.Write("Purchase Ticket: Concert #");
- int buyTicket = int.Parse(Console.ReadLine());
- if (buyTicket < 1 || buyTicket > liveShow.GetLength(0))
- Console.WriteLine("Invalid Concert!");
- else
- {
- Console.WriteLine($"You have purchased the ticket to \"{liveShow[buyTicket-1, SHOW_NAME]}\" for ${liveShow[buyTicket - 1, SHOW_PRICE]}");
- totalSales += int.Parse(liveShow[buyTicket-1, SHOW_PRICE]);
- for (int i = 0; i < liveShow.GetLength(1); i++) // Delete show
- liveShow[buyTicket-1, i] = "";
- liveShow = ModifiedStringArray(liveShow, -1); // Sort & remove slot
- }
- break;
- case 5:
- Console.WriteLine($"Total sales: {totalSales}");
- break;
- case 6:
- Console.WriteLine("Exiting...");
- break;
- default:
- Console.WriteLine("Will ya stop causing troubles?");
- break;
- }
- Console.ReadKey();
- Console.Clear();
- }
- while (option != 6);
- }
- static void PrintConcerts(string[,] array)
- {
- if (array.GetLength(0) < 1) Console.WriteLine("No concerts available!");
- else
- {
- for (int i = 0; i < array.GetLength(0); i++)
- {
- Console.WriteLine($"[Concert {i + 1}] Name: {array[i, SHOW_NAME]}, Artist: {array[i, SHOW_ARTIST]}, Price: {array[i, SHOW_PRICE]}, Ticket: {array[i, SHOW_TYPE]}, Genre: {array[i, SHOW_GENRE]}");
- }
- }
- }
- static string[,] ModifiedStringArray(string[,] array, int size)
- {
- string[,] tmpstr = new string[array.GetLength(0) + size, array.GetLength(1)];
- int emptyCount = 0;
- for(int i = 0; i < array.GetLength(0); i++)
- {
- if(size < 1 && array[i, SHOW_NAME] == "") // empty show name = invalid concert
- {
- emptyCount++;
- continue;
- }
- tmpstr[i - emptyCount, SHOW_NAME] = array[i, SHOW_NAME];
- tmpstr[i - emptyCount, SHOW_ARTIST] = array[i, SHOW_ARTIST];
- tmpstr[i - emptyCount, SHOW_PRICE] = array[i, SHOW_PRICE];
- tmpstr[i - emptyCount, SHOW_TYPE] = array[i, SHOW_TYPE];
- tmpstr[i - emptyCount, SHOW_GENRE] = array[i, SHOW_GENRE];
- }
- return tmpstr;
- }
- }
- }
Add Comment
Please, Sign In to add comment