예제 #1
0
        public static void Main()
        {
            StreamReader reader = FIO.OpenReader("help_not_defaults.txt");
            // special data is in the first two paragraphs
            string        welcome   = FileUtil.ReadParagraph(reader);
            string        goodbye   = FileUtil.ReadParagraph(reader);
            List <string> guessList =                                 // rest of the file gives a
                                      FileUtil.GetParagraphs(reader); //  list of random responses

            reader.Close();

            reader = FIO.OpenReader("help_not_responses.txt");
            Dictionary <string, string> responses =
                FileUtil.GetDictionary(reader);

            reader.Close();

            Console.Write(welcome);
            string prompt = "\n> ";

            Console.WriteLine("Enter 'bye' to end our session.");
            string fromUser;

            do
            {
                fromUser = UI.PromptLine(prompt).ToLower().Trim();
                if (fromUser != "bye")
                {
                    string answer = Response(fromUser, guessList, responses);
                    Console.Write("\n" + answer);
                }
            } while (fromUser != "bye");
            Console.Write("\n" + goodbye);
        }
예제 #2
0
        public static void Main(string[] args)
        {
            string sample = "sample.dat";
            string output = "output.dat";

            Console.WriteLine(FIO.GetLocation(sample));
            Console.WriteLine(FIO.GetPath(sample));
            StreamReader reader1 = FIO.OpenReader(sample);

            if (reader1 != null)
            {
                Console.WriteLine("first reader test passed");
                reader1.Close();
            }

            StreamReader reader2 = FIO.OpenReader(FIO.GetLocation(sample),
                                                  sample);

            if (reader2 != null)
            {
                Console.WriteLine("second reader test passed");
                reader2.Close();
            }

            StreamWriter writer1 = FIO.OpenWriter(FIO.GetLocation(sample),
                                                  output);

            writer1.Close();
            Console.WriteLine("writer test passed; file written at {0}",
                              FIO.GetPath(output));
        }
예제 #3
0
        public static void Main(string[] args)
        {
            string sample = "sample.txt";
            string output = "output.txt";

            Console.WriteLine("Directory of {0}: {1}",
                              sample, FIO.GetLocation(sample));
            Console.WriteLine("Path to  {0}: {1}",
                              sample, FIO.GetPath(sample));
            StreamReader reader1 = FIO.OpenReader(sample);

            if (reader1 != null)
            {
                Console.Write(reader1.ReadToEnd());
                Console.WriteLine("First reader test passed.");
                reader1.Close();
            }

            StreamReader reader2 = FIO.OpenReader(FIO.GetLocation(sample),
                                                  sample);

            if (reader2 != null)
            {
                Console.WriteLine("Second reader test passed.");
                reader2.Close();
            }

            StreamWriter writer1 = FIO.OpenWriter(FIO.GetLocation(sample),
                                                  output);

            writer1.WriteLine("File in the same directory as {0}.", sample);
            writer1.Close();
            Console.WriteLine("Writer test passed; file written at \n {0}",
                              FIO.GetPath(output));
        }
예제 #4
0
        /// Create places and their interconnections by taking place names, exit
        /// data and descriptions from a text file.
        /// Return a map of place names to places.  File format for each place:
        ///   First line:  place name (one word)
        ///   Second line: pairs of exit direction and neighbor place name
        ///   Remaining paragraph: place description, blank line terminated
        public static Dictionary <string, Place> createPlaces(string fileName)
        {
            StreamReader reader = FIO.OpenReader(fileName);
            // Map to return
            Dictionary <string, Place> places = new Dictionary <string, Place> ();

            // temporary Map to delay recording exits until all places exist
            Dictionary <string, string> exitStrings =
                new Dictionary <string, string> ();

            while (!reader.EndOfStream)
            {
                string name      = reader.ReadLine();
                string exitPairs = reader.ReadLine();
                // You could also substitute your lab's ReadParagraph for the two
                //   lines below if you want to format each paragraph line yourself.
                string description = TextUtil.LineWrap(reader);
                reader.ReadLine(); // assume empty line after description
                places [name]      = new Place(description);
                exitStrings [name] = exitPairs;
            }
            reader.Close();
            // need places before you can map exits
            // go back and use exitPairs to map exits:
            foreach (string name in places.Keys)
            {
                Place    place = places [name];
                string[] parts = TextUtil.SplitWhite(exitStrings[name]);
                for (int i = 0; i < parts.Length; i += 2)
                {
                    place.setExit(parts [i], places [parts [i + 1]]);
                }
            }
            return(places);
        }
예제 #5
0
        static double[] RunningTotal(string studentID, string course, string[] categories)
        {
            StreamReader reader3 = FIO.OpenReader(studentID + course + ".data");

            double [] runningTotals = new double[categories.Length];
            while (!reader3.EndOfStream)
            {
                string   data = reader3.ReadLine().Trim();
                string[] info = data.Split(',');
                runningTotals[codeIndex(info[0], categories)] += int.Parse(info[2]);
            }
            return(runningTotals);
        }
예제 #6
0
        public static void Main(string[] args)
        {
            string       course = UIF.PromptLine("Enter course abbreviation: ");
            StreamReader reader = FIO.OpenReader("categories_" + course + ".txt");

            string category = reader.ReadLine();

            string[] categories = category.Split(',');
            for (int i = 0; i < categories.Length; i++)
            {
                categories[i] = categories[i].Trim();
            }

            string weights = reader.ReadLine().Trim();

            string[] weightAmount  = weights.Split(',');
            double[] WeightNumbers = new double[weightAmount.Length];
            double[] weightTotal   = { 0 };
            for (int i = 0; i < WeightNumbers.Length; i++)
            {
                WeightNumbers[i] = double.Parse(weightAmount[i]);
            }
            for (int i = 0; i < WeightNumbers.Length; i++)
            {
                weightTotal[0] += WeightNumbers[i];
            }

            string items = reader.ReadLine().Trim();

            string[] itemAmount  = items.Split(',');
            double[] itemNumbers = new double[itemAmount.Length];
            for (int i = 0; i < itemNumbers.Length; i++)
            {
                itemNumbers[i] = int.Parse(itemAmount[i]);
            }

            StreamWriter writer  = new StreamWriter("report_" + course + ".txt");
            StreamReader reader2 = FIO.OpenReader("students_" + course + ".txt");

            while (!reader2.EndOfStream)
            {
                string   StudentData = reader2.ReadLine().Trim();
                string[] StudentInfo = StudentData.Split(',');
                double   percentage  = Final(FinalCategory(CategoryAverage(RunningTotal(StudentInfo[0], course, categories), itemNumbers), WeightNumbers, weightTotal));
                string   letter      = LetterGrade(Final(FinalCategory(CategoryAverage(RunningTotal(StudentInfo[0], course, categories), itemNumbers), WeightNumbers, weightTotal)));
                writer.WriteLine("{0},{1} {2:F1} {3}", StudentInfo[1], StudentInfo[2], percentage, letter);
            }
            writer.Close();
            reader.Close();
        }