コード例 #1
0
        }                               //算平均

        public void Basic_information(Takming[] Std_list, string College, int i)
        {
            Console.Write("學號:");
            this.Std_id = Console.ReadLine();
            Console.Write("姓名:");
            this.Std_name = Console.ReadLine();
            //Console.Write("學院(財經、管理、資訊):");
            //this.College = Console.ReadLine();
            Console.Write("國文成績:");
            this.Std_Chin = double.Parse(Console.ReadLine());
            Console.Write("英文成績:");
            this.Std_Eng = double.Parse(Console.ReadLine());
            Console.Write("數學成績:");
            this.Std_Math   = double.Parse(Console.ReadLine());
            Std_list[i - 1] = new Takming {
                Std_id = this.Std_id, Std_name = this.Std_name, College_ = College
            };                                                                                                     // 將輸入的資料放入類別陣列裡
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Takming     Basic_takming     = new Takming();
            Finance     Basic_finance     = new Finance();
            Management  Basic_Management  = new Management();
            Information Basic_Information = new Information();

            int Fin_num = 0, Mana_num = 0, Infor_num = 0, Std_all = 0, c = 0;

            Console.Write("要建立幾位財經學生:");
            Fin_num = int.Parse(Console.ReadLine());
            Console.Write("要建立幾位管理學生:");
            Mana_num = int.Parse(Console.ReadLine());
            Console.Write("要建立幾位資訊學生:");
            Infor_num = int.Parse(Console.ReadLine());
            Std_all   = Fin_num + Mana_num + Infor_num;

            Takming [] Std_list = new Takming [Std_all];
            double []  Std_avg  = new double[Std_all];
            //   int [,] Std_list = new int [7,Fin_num];

            Console.Write("-----------------------------------\n");

            for (int i = 0; i < Fin_num; i++)
            {
                c += 1;
                Takming.Std_num_Fin();                                        //人數計數
                Basic_takming.Basic_information(Std_list, "財經", c);           //把學生存入陣列裡
                Basic_takming.sum();                                          //基本資料加總
                Basic_finance.Basic_Finance();                                //輸入財經的成績
                Basic_finance.sum();                                          //財經的成績加總
                Std_avg[c - 1] = (Basic_takming.Avg + Basic_finance.Avg) / 5; //算出學生的平均
            }

            for (int i = 0; i < Mana_num; i++)
            {
                c += 1;
                Takming.Std_num_Mana();                                          //人數計數
                Basic_takming.Basic_information(Std_list, "管理", c);              //把學生存入陣列裡
                Basic_takming.sum();                                             //基本資料加總
                Basic_Management.Basic_Management();                             //輸入管理的成績
                Basic_Management.sum();                                          //管理的成績加總
                Std_avg[c - 1] = (Basic_takming.Avg + Basic_Management.Avg) / 5; //算出學生的平均
            }

            for (int i = 0; i < Infor_num; i++)
            {
                c += 1;
                Takming.Std_num_Infor();                                          //人數計數
                Basic_takming.Basic_information(Std_list, "資訊", c);               //把學生存入陣列裡
                Basic_takming.sum();                                              //基本資料加總
                Basic_Information.Basic_Information();                            //輸入資訊的成績
                Basic_Information.sum();                                          //資訊的成績加總
                Std_avg[c - 1] = (Basic_takming.Avg + Basic_Information.Avg) / 5; //算出學生的平均
            }

            Console.Write("-------------------------\n");

            Array.Sort(Std_avg, Std_list); //由小到大排序
            Array.Reverse(Std_avg);        //變由大到小排序
            Array.Reverse(Std_list);

            for (int i = 0; i < Std_all; i++)//輸出名次和學生資料
            {
                Console.Write("第" + (i + 1) + "名\n");
                Console.Write("學號:" + Std_list[i].Std_id + "\n" + "姓名:" + Std_list [i].Std_name + "\n" + "學院:" + Std_list[i].College_ + "\n" + "平均:" + Std_avg[i] + "\n\n");
            }
            Console.ReadKey();
        }