日期:2014-05-17  浏览次数:21006 次

C#第四周 任务4.1 创建学生类
/* 
* 程序头部注释开始   
* 程序的版权和版本声明部分   
* Copyright (c) 2011, 烟台大学计算机学院学生   
* All rights reserved.   
* 文件名称:创建学生类                           
* 作    者:薛广晨                               
* 完成日期:2011  年 09 月  19  日   
* 版 本号:x1.0            
   
* 对任务及求解方法的描述部分   
* 输入描述:  
* 问题描述: 
* 程序输出:   
* 程序头部的注释结束 
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Student_Class
{
    class Program
    {
        static void Main(string[] args)
        {
            Student stu = new Student();
            Console.Write("请输入姓名:");
            string name = Console.ReadLine();
            Console.Write("请输入语文成绩:");
            double chinese_Score = double.Parse(Console.ReadLine());
            Console.Write("请输入数学成绩:");
            double math_Score = double.Parse(Console.ReadLine());
            Console.Write("请输入外语成绩:");
            double english_Score = double.Parse(Console.ReadLine());
            double all = stu.allScore(chinese_Score, math_Score, english_Score);
            double ave = stu.ave_Score(chinese_Score, math_Score, english_Score);
            stu.set_Name(name, chinese_Score, math_Score, english_Score, all, ave);
            stu.display();
            Console.ReadKey();
        }
    }

    class Student
    {
        string name;
        double chinese_Score;
        double math_Score;
        double english_Score;
        double all;
        double ave;

        public void display()
        {
            Console.WriteLine("姓名     语文      数学      外语    总分    平均分");
            Console.WriteLine("{0}     {1}     {2}     {3}    {4}    {5}", name, chinese_Score, math_Score, english_Score, all, ave);
        }
        public void set_Name(string name, double chinese_Score, double math_Score, double english_Score, double all, double ave)
        {
            this.name = name;
            this.chinese_Score = chinese_Score;
            this.math_Score = math_Score;
            this.english_Score = english_Score;
            this.all = all;
            this.ave = ave;
        }
        public double allScore(double chinese_Score, double math_Score, double english_Score)
        {
            return(chinese_Score + math_Score + english_Score);
        }

        public double ave_Score(double chinese_Score, double math_Score, double english_Score)
        {
            return(chinese_Score + math_Score + english_Score) / 3;
        }
    }
}

运行结果: