コード例 #1
0
        // ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
        // ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

        static void MainAttempt2(string[] args)
        {
            // 1. Create a array or collection for student (declare)
            // 2. Read values from the file
            // 3. Process what you input
            // 4. Write info to the screen
            // All done!

            // 1 - Declare what is needed
            clsStudent[] MyStudents = new clsStudent[2];
            int          Idx;
            string       line;

            string[]     theParts;
            StreamReader sr;

            // 2 - Open and read the data file
            sr   = new StreamReader("G:\\AllMyStudents.txt");
            line = sr.ReadLine();
            Idx  = 0;
            while (line != null)
            {
                theParts        = line.Split(',');
                MyStudents[Idx] = new clsStudent(theParts[0],
                                                 theParts[1],
                                                 theParts[2],
                                                 int.Parse(theParts[3]),
                                                 int.Parse(theParts[4]),
                                                 int.Parse(theParts[5]),
                                                 int.Parse(theParts[6]),
                                                 int.Parse(theParts[7]));



                line = sr.ReadLine();
                Idx++;
            }
            sr.Close();

            // 3 - Process the data
            //   *** Nothing to do - just sending it to the screen ***

            // 4 - Output the results
            for (int xx = 0; xx < MyStudents.Length; xx++)
            {
                Console.WriteLine(MyStudents[xx].ToString());
            }

            Console.WriteLine("\n\nPress a key to output using a different format...");
            Console.ReadKey();

            Console.Clear();
            for (int xx = 0; xx < MyStudents.Length; xx++)
            {
                Console.WriteLine(MyStudents[xx].ToMultiLineString());
            }

            Console.WriteLine("\n\nPress a key to terminate...");
            Console.ReadKey();
        }
コード例 #2
0
        // ────────────────────────────────────────────────────────────────────────────────────────
        /// <summary>
        /// Manage readinbg data from the text file.
        /// </summary>
        static void ReadStudentDataFromFile()
        {
            int    Idx;
            string line;

            string[]     theParts;
            StreamReader sr;

            // Initialize the first index/student to be read
            Idx = 0;

            // Open a stream reader to a specific data file and begin reading data
            sr   = new StreamReader("G:\\AllMyStudents.txt");
            line = sr.ReadLine();

            // While data exists, keep on trucking!
            while (line != null)
            {
                theParts        = line.Split(',');
                MyStudents[Idx] = new clsStudent(theParts[0],
                                                 theParts[1],
                                                 theParts[2],
                                                 int.Parse(theParts[3]),
                                                 int.Parse(theParts[4]),
                                                 int.Parse(theParts[5]),
                                                 int.Parse(theParts[6]),
                                                 int.Parse(theParts[7]));

                line = sr.ReadLine();
                Idx++;
            }
            sr.Close();
            sr.Dispose();
        }
コード例 #3
0
        static void MainFirst(string[] args)
        {
            clsStudent AStudent = new clsStudent();
            clsStudent BStudent = new clsStudent("00111", "J.K.", "Rawling");
            clsStudent CStudent = new clsStudent("00222", "Yogi", "Bear", 90, 83, 97, 92, 100);

            // Create a student object container to store the student information
            AStudent.StudentID = "12310";
            AStudent.FName     = "Steve";
            AStudent.LName     = "Jobs";
            AStudent.Scores[0] = 96;
            AStudent.Scores[1] = 84;
            AStudent.Scores[2] = 88;
            AStudent.Scores[3] = 83;
            AStudent.Scores[4] = 91;

            BStudent.Scores[0] = 87;
            BStudent.Scores[1] = 91;
            BStudent.Scores[2] = 77;
            BStudent.Scores[3] = 100;
            BStudent.Scores[4] = 96;

            // Output the student information, including assigned scores
            Console.WriteLine("══════════════════");
            Console.WriteLine("  Student Ledger");
            Console.WriteLine("══════════════════\n");
            Console.WriteLine("Student ID       : " + AStudent.StudentID);
            Console.WriteLine("First Int or Name: " + AStudent.FName);
            Console.WriteLine("Last Name        : " + AStudent.LName);
            Console.Write("Scores           : ");
            for (int xx = 0; xx < 5; xx++)
            {
                Console.Write(AStudent.Scores[xx].ToString("D3") + "  ");
            }

            Console.WriteLine("\n\nStudent ID       : " + BStudent.StudentID);
            Console.WriteLine("First Int or Name: " + BStudent.FName);
            Console.WriteLine("Last Name        : " + BStudent.LName);
            Console.Write("Scores           : ");
            for (int xx = 0; xx < 5; xx++)
            {
                Console.Write(BStudent.Scores[xx].ToString("D3") + "  ");
            }

            Console.WriteLine("\n\nStudent ID       : " + CStudent.StudentID);
            Console.WriteLine("First Int or Name: " + CStudent.FName);
            Console.WriteLine("Last Name        : " + CStudent.LName);
            Console.Write("Scores           : ");
            for (int xx = 0; xx < 5; xx++)
            {
                Console.Write(CStudent.Scores[xx].ToString("D3") + "  ");
            }

            // Output the average of the scores
            Console.WriteLine("\n\nA-Student Average " + AStudent.AverageScores.ToString("0.000"));
            Console.WriteLine("B-Student Average " + BStudent.AverageScores.ToString("0.000"));
            Console.WriteLine("C-Student Average " + CStudent.AverageScores.ToString("0.000"));

            // We're done, wait for user to press key then quit
            Console.WriteLine("\n\nPress a key to exit application...");
            Console.ReadKey();
        }