Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// So here is what you need to do to finish this:
        ///
        /// - loop through the student master and get all the student id's to create all the student data files
        /// - open the student data files
        /// - read and store each line of the data file into an array, using split on a comma
        /// - average the scores
        /// - write out results to the file
        ///
        /// Here is the grading scale stuff so you don't waste time on typing this out
        /// </summary>


        public static void Main(string[] args)
        {
            // TEMPORARY line to get oriented to the file system:
            //Console.WriteLine("Current directory: " + Directory.GetCurrentDirectory());

            //course abbrv. for step 2
            string courseName = GetCourseName(args);

            string categoriesPath = FIO.GetPath("categories_" + courseName + ".txt");             // get full paths to files
            //Console.WriteLine ("categoriesPath = " + categoriesPath);
            string studentsPath = FIO.GetPath("students" + courseName + ".txt");

            //Console.WriteLine ("studentsPath = " + studentsPath);
            //Console.WriteLine ();

            // the following lines read the contents of the categories and students files into string arrays:
            string[] categoriesMaster = File.ReadAllLines(categoriesPath);             // File function like reader.ReadToEnd()
            // categoriesMaster now holds the 3 lines of the Master Category file
            string[] studentsMaster = File.ReadAllLines(studentsPath);
            // read all lines of the Student Master file into a string array, one line per element

            string[] cats = MakeCatArray(categoriesMaster);
            // creates a string array of the category names
            //Console.WriteLine("cats array: " + string.Join(", ", cats));


            // containing the weights contained in the second line of the categories file, now in categoriesMaster[1]
            int[] catWeights = MakeWeightArray(categoriesMaster);
            // creates an int array of weights used for the final grade calculation
            //Console.WriteLine("catWeights array: " + string.Join(", ", catWeights));


            // containing the numbers of items contained in the third line of the categories file, now in categoriesMaster[2]
            int[] numItems = MakeNumItemsArray(categoriesMaster);
            // creates an int array of the maximum number of grades per category
            //Console.WriteLine("numItems array: " + string.Join(", ", numItems));
            //Console.WriteLine ();

            string [] sID   = studentDFile(studentsMaster);
            string[]  files = new string[sID.Length];

            for (int x = 0; x < sID.Length; x++)
            {
                files [x] = FIO.GetPath(sID [x] + courseName + ".data");
            }

            int[] finNum = MakeNumItemsArray(categoriesMaster);
            int   ex0, lb0, hw0, pr0, ca0;

            ex0 = finNum [0];
            lb0 = finNum [1];
            hw0 = finNum [2];
            pr0 = finNum [3];
            ca0 = finNum [4];

            string output_file = courseName + "_summary.txt";

            StreamWriter writer = FIO.OpenWriter(FIO.GetLocation(categoriesPath), output_file);

            string[] finalOrder = new string[3];

            for (int x = 0; x < files.Length; x++)
            {
                double[] ex = new double[ex0];
                for (int i = 0; i < ex.Length; i++)
                {
                    ex [i] = 0;
                }

                double[] lb = new double[lb0];
                for (int i = 0; i < lb.Length; i++)
                {
                    lb [i] = 0;
                }

                double[] hw = new double[hw0];
                for (int i = 0; i < hw.Length; i++)
                {
                    hw [i] = 0;
                }

                double[] pr = new double[pr0];
                for (int i = 0; i < pr.Length; i++)
                {
                    pr [i] = 0;
                }

                double[] ca = new double[ca0];
                for (int i = 0; i < ca.Length; i++)
                {
                    ca [i] = 0;
                }

                string [] student_files = File.ReadAllLines(files[x]);

                string[] line0 = LineReader(student_files, x);

                int[] line1 = new int[line0.Length];
                for (int y = 0; y < line0.Length; y++)
                {
                    line1 [y] = int.Parse(line0 [y]);
                }

                double[] line2 = new double[line1.Length];
                for (int z = 0; z < line1.Length; z++)
                {
                    line2 [z] = line1 [z];
                }


                //E, L, H, P, and C.
                if (line0 [0] == "e")
                {
                    ex [line1 [1]] = line2 [2];
                }
                else if (line0 [0] == "l")
                {
                    lb [line1 [1]] = line2 [2];
                }
                else if (line0 [0] == "h")
                {
                    hw [line1 [1]] = line2 [2];
                }
                else if (line0 [0] == "p")
                {
                    pr [line1 [1]] = line2 [2];
                }
                else
                {
                    ca [line1 [1]] = line2 [2];
                }

                double finE, finL, finH, finP, finC;

                finE = Math(ex);
                finL = Math(lb);
                finH = Math(hw);
                finP = Math(pr);
                finC = Math(ca);

                finE = (finE * catWeights [0]) / totalCatW(catWeights);
                finL = (finL * catWeights [1]) / totalCatW(catWeights);
                finH = (finH * catWeights [2]) / totalCatW(catWeights);
                finP = (finP * catWeights [3]) / totalCatW(catWeights);
                finC = (finC * catWeights [4]) / totalCatW(catWeights);

                double finalGrade = finE + finL + finH + finP + finC;

                finalOrder [x] = studentsMaster [x].Split(',');
                writer.Write(finalOrder [1] + ", " + finalOrder[2] + finalGrade + finGradeLet(finalGrade));
            }
        }
Ejemplo n.º 8
0
        public static void Main(string[] args)
        {
            // for GradeFiles Lab only: set courseName to a constant value for testing
            string courseName = "comp170";             // this will either become "comp150" or "comp170" for Grade Files

            /* for the Grade Files homework, Section 18.7, use this instead:
             * string courseName = GetCourseName(args); // returns the course name from the args array or from the user
             */

            // Assignment 1: use FIO.GetPath to find the path names where these two files reside:
            // 1) categories_<courseName>.txt and 2) students_<courseName>.txt
            // these are the values of the input strings that you pass to FIO.GetPath
            // in the line above, plug the contents of variable courseName into the input strings
            // set the variables categoriesPath and studentsPath to the strings returned by FIO.GetPath

            string categoriesPath = FIO.GetPath("categories_" + courseName + ".txt");             // get full paths to files

            Console.WriteLine("categoriesPath = " + categoriesPath);
            string studentsPath = FIO.GetPath("students" + courseName + ".txt");

            Console.WriteLine("studentsPath = " + studentsPath);
            Console.WriteLine();

            // end of Assignment 1

            // the following lines read the contents of the categories and students files into string arrays:
            string[] categoriesMaster = File.ReadAllLines(categoriesPath);             // File function like reader.ReadToEnd()
            // categoriesMaster now holds the 3 lines of the Master Category file
            string[] studentsMaster = File.ReadAllLines(studentsPath);
            // read all lines of the Student Master file into a string array, one line per element

            // Assignment 2: later in this file, create a function called MakeCatArray that returns a string array
            // containing the categories contained in the first line of the categories file, now in categoriesMaster[0]
            string[] cats = MakeCatArray(categoriesMaster);
            // creates a string array of the category names
            Console.WriteLine("cats array: " + string.Join(", ", cats));

            // Assignment 3: later in this file, create a function called MakeWeightArray that returns an int array
            // containing the weights contained in the second line of the categories file, now in categoriesMaster[1]
            int[] catWeights = MakeWeightArray(categoriesMaster);
            // creates an int array of weights used for the final grade calculation
            Console.WriteLine("catWeights array: " + string.Join(", ", catWeights));

            // Assignment 4: later in this file, create a function called MakeNumItemsArray that returns an int array
            // containing the numbers of items contained in the third line of the categories file, now in categoriesMaster[2]
            int[] numItems = MakeNumItemsArray(categoriesMaster);
            // creates an int array of the maximum number of grades per category
            Console.WriteLine("numItems array: " + string.Join(", ", numItems));
            Console.WriteLine();

            string[] finalOrder = new string[3];
            for (int j = 0; j < studentsMaster.Length; j++)             // process each student data line

            // Assignment 5 and 6:

            {
                finalOrder [j] = studentsMaster [j].Split(',');
                Console.Write(finalOrder [0]);
                Console.Write(finalOrder [2]);
                Console.Write(finalOrder [1]);
                Console.WriteLine();

                Console.Write(finalOrder [0] + courseName + ".txt");

                Console.WriteLine();
            }
        }