Dsa Assignment 1 (Code)

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

2.

IMPLEMENTING DATA STRUCTURES IN AN EXECUTABLE PROGRAMMING


LANGUAGE

The system code

using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Services_System
{
class Delivery
{
public string userName;
public string userID;
public string itemCode;
public string itemDesc;
public int itemQuant;
public string itemLocation;
} // class for storing data

class Program
{
static public ArrayList delivery_data = new ArrayList();

static void Main(string[] args)


{
int choice;
introduction();
Console.Clear();
while (true)
{
main_menu();
choice = int.Parse(Console.ReadLine());

if (choice == 4)
{
Console.WriteLine("| THANK YOU FOR USING THIS SYSTEM |");
Console.WriteLine("| \tPLEASE COME AGAIN! |");
break;
}

switch (choice)
{
case 1:
Console.Clear();
parcel_data_menu();
break;
case 2:
Console.Clear();
display_data_menu();
break;
default:
Console.WriteLine("| Sorry, but you've entered the wrong input!");
Console.WriteLine("| Press enter and please try again\n");
Console.ReadKey();
Console.Clear();
break;
}
}
}

static void introduction()


{
Console.WriteLine("-------------------------------
INTRODUCTION--------------------------------------");
Console.WriteLine("\t\t - Inter System Sdn Bhd | Delivery System - ");
Console.WriteLine("---------------------------------------------------------------------------------");
Console.WriteLine("| \t Welcome to the Inter Systems Sdn Bhd, Delivery System. \t\t|");
Console.WriteLine("| \t You can add parcel details, remove the inserted parcel details \t|");
Console.WriteLine("| \t search for any parcel data, display all the history of parcel details |");
Console.WriteLine("| \t and display data based on the sorted details. \t\t\t\t|");
Console.WriteLine("---------------------------------------------------------------------------------");
Console.WriteLine("|\t\t\t- Press enter to continue! -\t\t\t\t|");
Console.WriteLine("---------------------------------------------------------------------------------");
Console.ReadKey();
Console.Clear();
} // end of introduction menu

static void main_menu()


{
Console.WriteLine("------------------------------------------------------------------");
Console.WriteLine("\a\t - Inter Systems Sdn Bhd Presents -");
Console.WriteLine("\t - Services System | Delivery Service - ");
Console.WriteLine("------------------------------------------------------------------");
Console.WriteLine("|\t Welcome to the main menu of the system. \t\t |");
Console.WriteLine("|\t There will be a few options to choose from \t\t |");
Console.WriteLine("|\t Each options range from adding data to display data \t |");
Console.WriteLine("|\t Choose the option for the following choices: \t\t |");
Console.WriteLine("-------------------------MENU--------------------------------------");
Console.WriteLine("|\t 1. Parcel Information Data Menu \t\t\t |");
Console.WriteLine("|\t 2. Parcel Information Display Menu \t\t\t |");
Console.WriteLine("|\t 3. Help Menu \t\t\t\t\t\t |");
Console.WriteLine("|\t 4. Exit This Program \t\t\t\t\t |");
Console.WriteLine("------------------------------------------------------------------\n");
Console.Write("| Choice: ");
} // End of main menu

static void help_menu()


{
string choice;
while (true)
{
Console.WriteLine("-----------------------------------------------------------------");
Console.WriteLine("\t\t - Welcome to the Help Menu -");
Console.WriteLine("------------------------------------------------------------------");
Console.WriteLine("| In this section, you can seek for help by navigating through the menus");
Console.WriteLine("| and understanding on how this system works, for each of the menus");
Console.WriteLine("--------------------------------------------------------------------");
Console.WriteLine("----------------------------OPTION----------------------------------");
Console.WriteLine("| A. How to use the Parcel Informations Menu");
Console.WriteLine("| B. How to use the Display Parcel Information Menu");
Console.WriteLine("| E. Exit to main menu");
Console.WriteLine("--------------------------------------------------------------------");
Console.Write("| Choice: "); choice = Console.ReadLine().ToUpper();

if (choice == "E")
{
break;
}

switch (choice)
{
case "A":
Console.Clear();
Console.WriteLine("------------------------PARCEL INFORMATION
MENU---------------------");
Console.WriteLine("--------------------------------------------------------------------");
Console.WriteLine("| In this menu, the user can add or either remove parcel information");
Console.WriteLine("| from the system. There is a few options to choose from: ");
Console.WriteLine("--------------------------------------------------------------------");
Console.WriteLine("| 1. An option to add parcel data into the system");
Console.WriteLine("| 2. An option to remove a data from the the system");
Console.WriteLine("--------------------------------------------------------------------");
Console.WriteLine("| Press enter to continue |");
Console.ReadKey();
Console.Clear();
break;
case "B":
Console.Clear();
Console.WriteLine("--------------------DISPLAY PARCEL INFORMATION
MENU----------------");
Console.WriteLine("-------------------------------------------------------------------");
Console.WriteLine("| In this menu, the user can view the information of each parcels");
Console.WriteLine("| within the system, in either sorted or non sorted. The user can also");
Console.WriteLine("| search for the parcel to view the individual parcel details");
Console.WriteLine("| with much detailed information data");
Console.WriteLine("--------------------------------------------------------------------");
Console.WriteLine("| 1. An option to search for a parcel detail and view the details");
Console.WriteLine("| 2. An option to view all the data within the system");
Console.WriteLine("| 3. An option to view the data in such sorted manner");
Console.WriteLine("--------------------------------------------------------------------");
Console.WriteLine("| Press enter to continue |");
Console.ReadKey();
Console.Clear();
break;
default:
Console.WriteLine("| You've entered the wrong the input |");
Console.WriteLine("| Press enter and please try again |");
Console.ReadKey();
Console.Clear();
break;
}
}
} // end of help menu

static void parcel_data_menu()


{
string choice;

while (true)
{
Console.WriteLine("---------------------------------------------------------------");
Console.WriteLine("\t - Parcel Information Menu - ");
Console.WriteLine("\t - Configure The Parcel Informations - ");
Console.WriteLine("---------------------------------------------------------------");
Console.WriteLine("|\t In this section, parcel information \t|");
Console.WriteLine("|\t As well as remove any of the parcel information\t|");
Console.WriteLine("|\t For checking and ordering as such. If you need help, |");
Console.WriteLine("|\t Press the corresponding H key at the selection section |");
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("| Please select the options to continue: \t\t\t|");
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("|\t A. Add parcel information \t\t\t\t|");
Console.WriteLine("|\t B. Remove a parcel information \t\t\t|");
Console.WriteLine("|\t H. View the Help \t\t\t\t|");
Console.WriteLine("|\t E. Exit to Main Menu \t\t\t\t|");
Console.WriteLine("---------------------------------------------------------------");
Console.Write("| Choice: ");
choice = Console.ReadLine().ToUpper();
Console.Clear();
// Parcel Information Menu

if (choice == "E")
{
break;
}

switch (choice)
{
case "A":
Console.Clear();
add_data(); // Load to add data method
break;
case "B":
Console.Clear();
remove_data(); // load to remove data method
break;
case "H":
help_menu(); // load to help menu method
break;
default:
Console.WriteLine("You've entered the wrong input");
Console.WriteLine("Press enter and please try again");
Console.ReadKey();
Console.Clear();
break;
}
}
} // end of parcel data menu

static void add_data()


{
string option;

do
{
Console.WriteLine("----------------------------------------------------------------------------");
Console.WriteLine("\t\t\t - Add Parcel Informations Menu - ");
Console.WriteLine("\t\t - Entering Parcel Information In To The System - ");
Console.WriteLine("----------------------------------------------------------------------------");
Console.WriteLine("| Please follow the instruction in order to enter the parcel information");
Console.WriteLine("| for completing the delivery to the client");
Console.WriteLine("-------------------INSTRUCTIONS---------------------------------------------");
Console.WriteLine("| The format for inputing the data: ");
Console.WriteLine("| Receiver Name: Mohamad Imran bin Mohamad Yusri");
Console.WriteLine("| Receiver ID: BCS1000");
Console.WriteLine("| Parcel Code: P0303");
Console.WriteLine("| Parcel Description: Fish in a box");
Console.WriteLine("| Parcel Quantity: 3");
Console.WriteLine("| Parcel Destinations: No. 85, Jalan SM1D2/2, Fasa 1D2, Seri Manjung,
Perak");
Console.WriteLine("| Courier Type: 1");
Console.WriteLine("---------------------------------------------------------------------------");
Console.Write("| Press enter to continue: "); Console.ReadKey();
Console.WriteLine("---------------------------------------------------------------------------");
Console.Write("| How many parcels do you want to enter?: ");
int p = int.Parse(Console.ReadLine());
Console.WriteLine("---------------------------------------------------------------------------");
// Menu for showing adding tutorial menu

for (int i = 0; i < p; i++)


{
Delivery data = new Delivery();

// The user input add menu


Console.WriteLine("------------------------USER INPUT-----------------------------------------");
Console.Write("| Receiver Name: "); data.userName = Console.ReadLine();
Console.Write("| Receiver ID: "); data.userID = Console.ReadLine().ToUpper();
Console.Write("| Parcel Code: "); data.itemCode = Console.ReadLine().ToUpper();
Console.Write("| Parcel Description: "); data.itemDesc = Console.ReadLine();
Console.Write("| Parcel Quantity: "); data.itemQuant = int.Parse(Console.ReadLine());
Console.Write("| Parcel Destination: "); data.itemLocation = Console.ReadLine();
Console.WriteLine("---------------------------------------------------------------------------");

delivery_data.Add(data);
}

// Given the options for looping


Console.WriteLine("---------------------------------OPTIONS---------------------------------------");
Console.WriteLine("| Please choose the following option in order to continue!: ");
Console.WriteLine("| A. Return adding parcel informations");
Console.WriteLine("| B. Exit to the main menu");
Console.WriteLine("-------------------------------------------------------------------------------");
Console.Write("| Choice: ");
option = Console.ReadLine().ToUpper();
Console.Clear();

} while (option == "A");


Console.Clear();
} // end of add data

static void remove_data()


{
Delivery delivery = new Delivery();
int count = delivery_data.Count;
int status = 0;
string option, code;

Console.WriteLine("-----------------------------------------------------------------------");
Console.WriteLine("\t\t - Remove Parcel Informations Menu - ");
Console.WriteLine("\t - Removing any available parcel informations from the data - ");
Console.WriteLine("-----------------------------------------------------------------------");
Console.WriteLine("| In this section, users can search and remove any available parcel data");
Console.WriteLine("| From the system, by searching through thr parcel code");
Console.WriteLine("-----------------------INSTRUCTIONS-------------------------------------");
Console.WriteLine("| The format for searching data to be remove: ");
Console.WriteLine("| Parcel Code: BCS020");
Console.WriteLine("| Then the user will be given the options to either");
Console.WriteLine("| to view first the data or remove it immediately");
Console.WriteLine("------------------------------------------------------------------------");
Console.Write("| Parcel Code: ");
code = Console.ReadLine().ToUpper(); Console.Write("|");
Console.WriteLine("----------------------NOW SEARCHING FOR
CODE----------------------------");
// menu for inputing search code for searching

if (count == 0)
{
Console.WriteLine("\t - Parcel List Is Empty - ");
Console.WriteLine("\t - Press enter and please try again later - ");
Console.ReadKey();
Console.Clear();
} // notify the user if code not available

else
{
foreach (object d in delivery_data)
{
delivery = (Delivery)d;

if (code == delivery.itemCode)
{
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("|\t - Item has been found! - |");
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("------------------DATA INFORMATION------------------------------");
Console.WriteLine("| Parcel Code: {0}", delivery.itemCode);
Console.WriteLine("| Parcel Description: {0}", delivery.itemDesc);
Console.WriteLine("| Parcel Quantity: {0}", delivery.itemQuant);
Console.WriteLine("| Parcel Destination: {0}", delivery.itemLocation);
Console.WriteLine("---------------------------------------------------------------");
Console.Write("Do you want to remove the following data? (Y|N): ");
option = Console.ReadLine().ToUpper();
Console.WriteLine("---------------------------------------------------------------");
status = 1;
// menu for confirmation for removing data

switch (option)
{
case "Y":
Console.WriteLine("----------------------------------------------------");
Console.WriteLine("- Item has been removed from the system -");
delivery_data.Remove(delivery);
Console.WriteLine("- Press enter to continue -");
Console.ReadKey();
Console.Clear();
break; // notify the user that item has been removed
case "N":
Console.WriteLine(" - Item was not removed from the system - ");
Console.WriteLine(" - Press enter to continue - ");
Console.ReadKey();
Console.Clear();
break; // notify the user that the item was not removed
default:
Console.WriteLine(" - Wrong input has been entered -");
Console.WriteLine(" - Press enter and please try again - ");
Console.ReadKey();
Console.Clear();
break; // wrong input
}
}

if (status == 0)
{
Console.WriteLine("- Item was not found in the system - ");
Console.WriteLine("- Press enter and please try again - ");
Console.ReadKey();
Console.Clear();
} // Item not found
}
}
} // end of removing data menu
static void display_data_menu()
{
string choice;
while (true)
{
Console.WriteLine("----------------------------------------------------------------------");
Console.WriteLine("\t - The Parcel Information Display Menu - ");
Console.WriteLine("\t - Displaying the data of sending parcels");
Console.WriteLine("----------------------------------------------------------------------");
Console.WriteLine("| In this section, the user can input any of the available code");
Console.WriteLine("| to output the details of the certain parcel that has been searched");
Console.WriteLine("| Each of the displayed information can be determined from the");
Console.WriteLine("| Code, description, type, courier type and many more!");
Console.WriteLine("----------------------------------------------------------------------");
Console.WriteLine("| \tPlease choose an option below!: ");
Console.WriteLine("-----------------------------OPTIONS----------------------------------");
Console.WriteLine("| \tA. Search for a parcel information");
Console.WriteLine("| \tB. Display all available parcel");
Console.WriteLine("| \tC. Display the parcels informations by sorted");
Console.WriteLine("| \tH. View the help menu");
Console.WriteLine("| \tE. Exit to main menu");
Console.WriteLine("----------------------------------------------------------------------");
Console.Write("| Choice: ");
choice = Console.ReadLine().ToUpper();
// menu for the parcel display menu

if (choice == "E")
{
Console.Clear();
break;
}
switch (choice)
{
case "A":
Console.Clear();
search_parcel(); // load into search parcel method
break;
case "B":
Console.Clear();
display_all_parcel(); // load into display parcel method
break;
case "C":
Console.Clear();
display_parcel_sorted(); // load into sorted parcel method
break;
case "H":
Console.Clear();
help_menu(); // load into help menu method
break;
default:
Console.WriteLine("- You've entered the wrong input -");
Console.WriteLine("- Press enter to try again -");
Console.ReadKey();
Console.Clear();
break; // wrong input
}
}
} // end of display data menu

static void search_parcel()


{
int count = delivery_data.Count;
int status = 0;
string code;
Delivery data = new Delivery();

Console.WriteLine("------------------------------------------------------------------");
Console.WriteLine("\t\t - Search Parcel Information Menu - ");
Console.WriteLine("\t\t - Search for parcel details and display the details");
Console.WriteLine("------------------------------------------------------------------");
Console.WriteLine("| In this section, the user can search for any parcel code");
Console.WriteLine("| and display the parcel's detail for any inspection");
Console.WriteLine("| It can display the parcels receiver name, receiver code,");
Console.WriteLine("| parcel's code, description and many more!");
Console.WriteLine("------------------------------------------------------------------");
Console.WriteLine("| Please enter the parcel code to be search: ");
Console.WriteLine("--------------------------INPUT-----------------------------------");
Console.Write("| Parcel code to be search: ");
code = Console.ReadLine().ToUpper();
// Showing the menu for searching data

if (count == 0)
{
Console.WriteLine("- No data available in the system - ");
Console.WriteLine("- Press enter to continue -");
Console.ReadKey();
Console.Clear();
// notify the user that the list is empty
}

else
{
foreach (Delivery d in delivery_data)
{
data = d;

if (code == data.itemCode)
{
Console.WriteLine("---------------------------------------------------------");
Console.WriteLine("| \t- Item has been found in the system -");
Console.WriteLine("---------------------------------------------------------");
Console.WriteLine("--------------------- DISPLAY ---------------------------");
Console.WriteLine("| User Name: {0}", data.userName);
Console.WriteLine("| User ID: {0}", data.userID);
Console.WriteLine("| Parcel Code: {0}", data.itemCode);
Console.WriteLine("| Parcel Description: {0}", data.itemDesc);
Console.WriteLine("| Parcel Quantity: {0}", data.itemQuant);
Console.WriteLine("| Parcel Destination: {0}", data.itemLocation);
Console.WriteLine("----------------------------------------------------------");
Console.WriteLine("| Please press enter to continue");
Console.ReadKey();
Console.Clear();
status = 1;
// notify the user that the item has found
}
}

if (status == 0)
{
Console.WriteLine("\t - Item not found in the system -");
Console.WriteLine("\t - Press enter to continue and please try again -");
Console.ReadKey();
Console.Clear();
// notify the user that the item has not found
}
}
} // end of search menu

static void display_all_parcel()


{
int count = delivery_data.Count;
Delivery delivery = new Delivery();

Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("\t\t - Display All Parcel Informations -");
Console.WriteLine("\t - Displaying all available parcel details in the system -");
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("| In this section, parcel informations can be display");
Console.WriteLine("| From every inch of details within the system");
Console.WriteLine("| The details will be listed from the receiver");
Console.WriteLine("| To the parcel destination arrivals");
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("-------------------------DISPLAY PARCELS------------------------");
Console.WriteLine("| Receiver Name | Receiver ID | Parcel Code | Parcel Description | Parcel
Quantity" +
" | Parcel Location |");
Console.WriteLine("----------------------------------------------------------------");
// the menu for display data method

int index = 1;
foreach (object d in delivery_data)
{
delivery = (Delivery)d;
Console.WriteLine("| " + delivery.userName + " \t" + delivery.userID + "\t " +
delivery.itemCode
+ "\t " + delivery.itemDesc + "\t" + delivery.itemQuant + " \t" + delivery.itemLocation);
index++;
// looping for displaying the data
}
Console.WriteLine("-----------------------------END OF DISPLAY--------------------");
Console.WriteLine("| Press enter to continue |");
Console.ReadKey();
Console.Clear();
} // end of display data menu

static void display_parcel_sorted()


{
int index = 1;
int i = 0;
int[] quantity = new int[delivery_data.Count];

foreach (Delivery item in delivery_data)


{
quantity[i] = item.itemQuant;
i++;
}

Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("\t - Display Sorted Parcel Details Menu -");
Console.WriteLine("\t - Displaying the sorted parcel informations - ");
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("| In this section, the parcel informations will be");
Console.WriteLine("| displayed in such a sorted by quantity of the parcel");
Console.WriteLine("| Instead of non - arranged display, everything");
Console.WriteLine("| Everything will look organized and such");
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine("-------------------------DISPLAY PARCELS------------------------");
Console.WriteLine("| Receiver Name | Receiver ID | Parcel Code | Parcel Description | Parcel
Quantity" +
" | Parcel Location |");
Console.WriteLine("----------------------------------------------------------------");
// Display the sort display parcel menu

Quicksort_Recursive(quantity, 0, quantity.Length - 1);

for (i = 0; i < quantity.Length; i++)


{
foreach (Delivery item in delivery_data)
{
if (quantity[i] == item.itemQuant)
{
Console.WriteLine("| " + item.userName + " \t" + item.userID + "\t " + item.itemCode
+ "\t " + item.itemDesc + "\t" + item.itemQuant + " \t" + item.itemLocation);
index++;
}
}
}

} // Eend of sorted display menu

static public void Quicksort_Recursive(int[] quantity, int left, int right)


{
if (left < right)
{
int pivot = Partition(quantity, left, right);

if (pivot > 1)
{
Quicksort_Recursive(quantity, left, pivot - 1);
}

if (pivot + 1 < right)


{
Quicksort_Recursive(quantity, pivot + 1, right);
}
}
} // quick sort algorithm method

static public int Partition(int[] quantity, int left, int right)


{
int pivot = quantity[left];

while (true)
{
while(quantity[left] < pivot)
{
left++;
}

while(quantity[right] > pivot)


{
right--;
}

if (left < right)


{
int temp = quantity[right];
quantity[right] = quantity[left];
quantity[left] = temp;
}

else
{
return right;
}
}
}
}
}

You might also like