Beispiel #1
0
        /// <summary>
        /// Parameterized constructor
        /// </summary>
        /// <param name="txt">The Text object from which the paragraphs are retrieved</param>
        public ParagraphList(Text txt)
            : this()
        {
            int start = 0;
            while (start < txt.Tokens.Count)
            {
                Paragraph p = new Paragraph (txt.Tokens, start);
                if (p.WordCount > 0)
                {
                    Paragraphs.Add (p);
                    ParagraphCount++;
                    AverageLength += p.WordCount;
                }

                start = p.End + 1;
            }
            if (ParagraphCount > 0)
                AverageLength /= ParagraphCount;
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            //user input for name, email address, and phone number as well as validation
            Console.WriteLine("Hello! Welcome to my first project for my Data Structures Class.");
            Console.WriteLine("My name is Greer Goodman.");
            Console.WriteLine("What is your name?\n");
            User.Name = Console.ReadLine();
            Console.WriteLine("What is your email address?\n");
            User.Email = Console.ReadLine();
            Console.WriteLine("And last but not least, what is your phone number?\n");
            User.Phone = Console.ReadLine();
            bool check = false;//checks to see if the user input valid information

            while (check == false)
            {
                if (User.TestEmail() == true && User.TestPhone() == true)
                {
                    check = true;
                }//end if
                else if (User.TestEmail() == false || User.TestPhone() == false)
                {
                    Console.WriteLine("One of the fields you entered is incorrect. Please fix it.");
                    Console.WriteLine("What is your email address?\n");
                    User.Email = Console.ReadLine();
                    Console.WriteLine("And last but not least, what is your phone number?\n");
                    User.Phone = Console.ReadLine();
                }//end if
                Console.WriteLine("Press Enter to continue.");
                Console.ReadLine();
            }//end while

            //Menu creation and implementation
            UtilityNamespace.Menu NewMenu = new UtilityNamespace.Menu("Data Structures Project 1 Menu");
            NewMenu += "1. Open a file and tokenize it";
            NewMenu += "2. Get Distinct Words";
            NewMenu += "3. Get a list of Distinct Words";
            NewMenu += "4. Get a Sentence";
            NewMenu += "5. Get a list of Sentences";
            NewMenu += "6. Get a Paragraph";
            NewMenu += "7. Get a list of Paragraphs";
            NewMenu += "8. Exit";

            int  choice = 0;       //used for switch choosing.
            Text NewText;          //varibale created here so other switches can use it
            bool OneFirst = false; // checks to see if option one has been chosen yet

            while (choice != 8)
            {
                NewMenu.Display();
                choice = NewMenu.GetChoice();
                switch (choice)
                {
                case 1:
                    Console.WriteLine("Please select a text file to work with.");
                    OpenFileDialog OpenDlg = new OpenFileDialog();
                    OpenDlg.Filter           = "text files|*.txt;*.text|all files|*.*";
                    OpenDlg.InitialDirectory = "Project1/TextFiles";
                    OpenDlg.Title            = "Select a file with which you would like to work with.";
                    if (DialogResult.Cancel != OpenDlg.ShowDialog())
                    {
                        FileName = OpenDlg.FileName;
                    }
                    NewText  = new Text();
                    OneFirst = true;
                    break;

                case 2:
                    if (OneFirst != false)
                    {
                        DistinctWord dw = new DistinctWord();
                        Console.WriteLine(dw.ToString());
                        Console.ReadLine();
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 3:
                    if (OneFirst != false)
                    {
                        Words NewWord = new Words();
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 4:
                    if (OneFirst != false)
                    {
                        Sentence Sent = new Sentence();
                        Console.WriteLine(Sent.ToString());
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 5:
                    if (OneFirst != false)
                    {
                        SentenceList SentList = new SentenceList();
                        SentenceList.Display();
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 6:
                    if (OneFirst != false)
                    {
                        Paragraph Para = new Paragraph();
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 7:
                    if (OneFirst != false)
                    {
                        ParagraphList ParaList = new ParagraphList();
                        ParagraphList.Display();
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 8:
                    Console.WriteLine("Thank{0} ({1}, {2}) for using my program. I was completely unprepared to turn this project in. Have a nice day. ", User.Name, User.Email, User.Phone);
                    Console.ReadLine();
                    Environment.Exit(0);
                    break;
                } //end switch
            }     //end while
        }         //end main(string[])