c#课程学分累计

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

namespace InteractionObject
{
    class Program
    {
        class Student
        {
            string id;
            string name;
            int scredits;
            Course course;
            
            public Student(string id, string name, int scredits, Course course)
            {
                this.id = id;
                this.name = name;
                this.scredits = scredits;
                this.course = course;
            }

            public void UpdateCredit()
            {
                scredits += course.Credits; 
            }

            public void display()
            {
                Console.WriteLine("该生的学号是{0},姓名是{1},已选择了《{2}》课,这门课的课程号是{3},{4}学分,由{5}讲授,现在该生的总学分数是{6}"
                    ,id,name,course.Name,course.Cid,course.Credits,course.Teacher,scredits);

            }
        }

        class Course
        {
            string cid;
            string cname;
            int credits;
            string teacher;
            
            public Course(string cid,string cname,int credits,string teacher)
            {
                this.cid = cid;
                this.cname = cname;
                this.credits = credits;
                this.teacher = teacher;

            }

            public string Cid
            {
                get { return cid; }
            }
            public string Name
            {
                get { return cname; }
            }
            public int Credits
            {
                get { return credits; }
            } 
            public string Teacher
            {
                get { return teacher; }
            }
        }
        static void Main(string[] args)
        {
            Course c = new Course("Scl178","高阶英语",4,"Marry");
            Student s = new Student("101","王明",30,c);
            s.UpdateCredit();
            s.display();
        }
    }
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值