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));
        }
        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));
        }
Exemple #3
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));
            }
        }