using System;
using System.Collections.Generic;
using System.Text;
namespace WebSites1
{
class Program
{
//Program entry
static int Main(string[] args)
{
string[] siteName = new string[6];
string phrase = "What is your pleasure";
string choice;
int count = 0;
//If there was a cmd line arg,use it;
if (args.Length == 0)
{
Console.WriteLine("{0},Master?",phrase);
}
else
{
Console.WriteLine("{0},{1}?",phrase,args[0]);
}
do
{
//Print menu.
Console.WriteLine("");
Console.WriteLine("A - Add Site");
Console.WriteLine("S - Sort List");
Console.WriteLine("R - Show Report /n");
Console.WriteLine("Q - Quit/n");
Console.WriteLine("Please Choose(A/S/R/Q): ");
choice = Console.ReadLine();
//Figure out what user wanted.
switch(choice)
{
//Add a site
case "a":
case "A":
Console.WriteLine("/nAdding Site/n");
string doAgain = "Y";
//Keep it up as long as user wants
while(doAgain.ToUpper() == "Y")
{
Console.Write(
"Please Enter Site Name: ");
siteName[count++]=Console.ReadLine();
Console.Write("Add Another?:");
doAgain=Console.ReadLine();
//There can only by 5 items
if(count>=5)
{
break;
}
}
break;
//Sort the site list
case "s":
case "S":
Console.WriteLine("Sorting List....");
int n = siteName.Length - 2;
int j,k;
string save;
//Insertion sort,start at end & move up
for (k = n - 1; k >= 0; k--)
{
j = k + 1;
save = siteName[k];
//Sentinel makes inner
//loop more efficient
siteName[n + 1] = save;
//Insert siteName[k] into its sorted position
while (string.Compare(save, siteName[j]) > 0)
{
siteName[j - 1] = siteName[j];
j++;
}
siteName[j - 1] = save;
}
//clean out sentinel so it's not printed
siteName[siteName.Length-1] = null;
Console.WriteLine("Done sorting");
break;
//Print a report
case "r":
case "R":
string filter = "";
string response = "";
//If user wants to filter,get filter string
Console.Write("Would you like a Filter?");
response=Console.ReadLine();
if(response.ToUpper() =="Y")
{
Console.Write("/nPlease enter a filter:");
filter = Console.ReadLine();
}
Console.WriteLine("");
Console.WriteLine("Site Report");
Console.WriteLine("");
//Process every entry in siteName
foreach(string site in siteName)
{
//Execute filter
if(response.ToUpper() == "Y" && site != null & site.IndexOf(filter) == -1)
{
continue;
}
//Print non-filtered items
Console.WriteLine("/t {0}",site);
}
break;
//Exit Program
case "q":
case "Q":
Console.WriteLine("GoodBye");
break;
//User entered bad data
default:
Console.WriteLine("Huh??");
break;
}//end swith
//keep going until user wants to quit
}while((choice = choice.ToUpper()) != "Q");
return 0;
}
}
}