C#第五章作业5-8~5-12

 

蒟蒻os:my奇奇怪怪的码风。

摆烂了好久再写C#作业==难上加难! 

8

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

namespace S5_8
{
    public class Student//定义了一个学生类
    {
        //记录学生的姓名院系班级专业
        public string Name, Institute, Class, Major;//公共属性
        public Student(ref string a,ref string b,ref string c,ref string d)//参数引用
        {
            this.Name = a;
            this.Institute = b;
            this.Class = c;
            this.Major = d;
        }
        public void Alter_Major(ref string n)//运用了引用参数来实行修改专业的成员函数(方法)
        {
            this.Major = n;
        }
        public void Output_Major()//总结信息的输出操作
        {
            Console.WriteLine("该学生的姓名为:{0}\n院系为:{1}\n班级为:{2}\n专业为:{3}", Name,Institute,Class, Major);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入学生的姓名:");
            string a = Console.ReadLine();
            Console.WriteLine("请输入该学生的所在院系:");
            string b = Console.ReadLine();
            Console.WriteLine("请输入该学生的所在班级:"); 
            string c = Console.ReadLine();
            Console.WriteLine("请输入该学生的专业:");
            string d = Console.ReadLine();

            Student s = new Student(ref a,ref b,ref c,ref d);
            //进行修改操作 
            Console.WriteLine("请问是否需要修改该学生的专业?需要的话请输入“YES”,否则输入“NO”");
            string flag = Console.ReadLine();
            if (flag == "YES")
            {
                Console.WriteLine("请输入修改后的专业:");
                string n = Console.ReadLine();
                s.Alter_Major(ref n);
                s.Output_Major();//修改或保存完毕,输出最终信息
            }
            else s.Output_Major();//修改或保存完毕,输出最终信息
            Console.ReadKey();
        }
    }
}

9

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

namespace S5_9
{
    public class Student
    {
        public string Name,Number;
        public int SspScore, EngScore, MatScore;
        public Student(ref string a,ref string b,ref int c,ref int d,ref int e)
        {
            this.Name = a;
            this.Number = b;
            this.SspScore = c;
            this.EngScore = d;
            this.MatScore = e;
        }
        public void Identify()
        {
            Console.WriteLine("该学生的姓名为:{0} 学号为:{1} C#成绩为:{2},English成绩为:{3},数学成绩为:{4}\n", Name, Number, SspScore, EngScore, MatScore);
            Console.WriteLine("总成绩为:{0}", SspScore + EngScore + MatScore);
            Console.WriteLine("平均成绩为:{0}", (SspScore + EngScore + MatScore)/3);
        }
    }
    class Program
    {
        //应用程序的主入口点
        static void Main(string[] args)
        {
            Console.WriteLine("请输入学生的姓名:");
            string a=Console.ReadLine();
            Console.WriteLine("请输入学生的学号:");
            string b=Console.ReadLine();
            Console.WriteLine("请输入学生的C#成绩:");
            int c=int.Parse(Console.ReadLine());
            Console.WriteLine("请输入学生的English成绩:");
            int d = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入学生的数学成绩:");
            int e = int.Parse(Console.ReadLine());

            Student s = new Student(ref a,ref b,ref c,ref d,ref e);
            s.Identify();
        }
    }
}

10

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

namespace S5_10
{
    public class clsPerson//定义一个人员类
    {
        private string Name,Number,Sex;
        public void Person(string strName, string strNumber, string strSex)
        {
            Name = strName;
            Number = strNumber;
            Sex = strSex;
        }
        public void Output()//人员类的输出
        {
            Console.WriteLine("姓名为:" + Name + ":编号为:" + Number + ":性别为:" + Sex);
        }
    }
    //学生类:继承 人员类
    public class clsStudent:clsPerson
    {
        int Score;
        public void addScore(int strScore)
        {
            Score = strScore;
        }
        public void OutputScore()//学生类的输出
        {
            Console.WriteLine("成绩为:" + Score);
        }
    }
    //教师类:继承 人员类
    public class clsTeacher:clsPerson
    {
        int Age;
        public void addAge(int strAge)
        {
            Age = strAge;
        }
        public void OutputAge()//教师类的输出
        {
            Console.WriteLine("教龄为:" + Age);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            clsStudent stu = new clsStudent();//派生出学生类
            stu.Person("王一博", "987654321", "男");//先去人员类里面转一圈
            stu.addScore(100);//再去学生类里补一个成绩
            stu.Output();//输出人员类的已插入信息
            stu.OutputScore();//输出学生类的成绩信息

            clsTeacher Tea = new clsTeacher();
            Tea.Person("陈老师", "123456789", "男");
            Tea.addAge(15);
            Tea.Output();
            Tea.OutputAge();
            //一样的道理
        }
    }
}

11

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

namespace S5_11
{
    class clsPoint
    {
        private double X, Y;
        public clsPoint(double dblX,double dblY)//接收到默认值
        {
            X = dblX;
            Y = dblY;
        }
        public void display()
        {
            Console.WriteLine("坐标点的X为" + X + ": Y坐标为" + Y);
        }
        public void setPoint(double dblX, double dblY)//更改操作
        {
            X = dblX;
            Y = dblY;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            clsPoint point = new clsPoint(60.00, 75.00);//初始时默认坐标在这个点里面
            point.display();//先输出这个默认值
            point.setPoint(100.00, 120.00);//更改操作
            point.display();//输出更改之后的坐标位置
            Console.Read();
        }
    }
}

12

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

namespace S5_12
{
    public class clsPoint
    {
        public double dblX, dblY;
        public clsPoint()
        {

        }
        public clsPoint(double _dblX, double _dblY)
        {
            dblX = _dblX;
            dblY = _dblY;
        }
    }
    public class clsLine : clsPoint
    {
        clsPoint point1, point2;
        public clsLine()
        {

        }
        public clsLine(clsPoint _point1, clsPoint _point2)
        {
            point1 = _point1;
            point2 = _point2;
        }
        public double getDistance()
        {
            double dblDistance, dblDistance1, dblDistance2;
            dblDistance1 = Math.Pow(point1.dblX - point2.dblX, 2.0);
            dblDistance2 = Math.Pow(point1.dblY - point2.dblY, 2.0);
            dblDistance = Math.Sqrt(dblDistance1 + dblDistance2);
            return dblDistance;
        }
    }
    public class clsRect : clsLine
    {
        clsLine line1, line2, line3, line4;
        public clsRect(clsLine _line1, clsLine _line2, clsLine _line3, clsLine _line4)
        {
            line1 = _line1;
            line2 = _line2;
            line3 = _line3;
            line4 = _line4;
        }
        public double getPerimerter()
        {
            double dblPerimeter;
            dblPerimeter = 2 * (line1.getDistance() + line2.getDistance());
            return dblPerimeter;
        }
        public double getArea()
        {
            double dblArea;
            dblArea = line1.getDistance() * line2.getDistance();
            return dblArea;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            clsPoint point1 = new clsPoint(0.0, 10.0);
            clsPoint point2 = new clsPoint(20.0, 10.0);
            clsPoint point3 = new clsPoint(20.0, 0.0);
            clsPoint point4 = new clsPoint(0.0, 0.0);

            clsLine line1 = new clsLine(point2, point1);
            clsLine line2 = new clsLine(point3, point2);
            clsLine line3 = new clsLine(point4, point3);
            clsLine line4 = new clsLine(point1, point4);
            clsRect rect = new clsRect(line1, line2, line3, line4);
            double dblDistOfLine;
            dblDistOfLine = line1.getDistance();
            Console.WriteLine("两点之间的距离为:" + dblDistOfLine);
            double dblPermeterOfRect, dblAreaOfRect;
            dblPermeterOfRect = rect.getPerimerter();
            dblAreaOfRect = rect.getArea();
            Console.WriteLine("矩形的周长为:" + dblPermeterOfRect);
            Console.WriteLine("矩形的面积为:" + dblAreaOfRect);
        }
    }
}
using System;
namespace Example_Random
{
    class Random_12_sort
    {
        static void Main()
        {
            int[] a = new int[12];
            Random ran = new Random();
            for(int i=0;i<a.Length;i++)
            {
                one_num:
                a[i] = (int)ran.Next(50) + 1;
                for(int j=0;j<i;j++)
                {
                    if (a[i] == a[j]) goto one_num;
                }
                Console.WriteLine("\n排序前的12个数字是:\n");
                foreach(int n in a)
                {
                    Console.Write("{0}\0", n);
                }
                Array.Sort(a);
                Console.WriteLine("\n排序后的12个数字是:\n");
                foreach(int n in a)
                {
                    Console.Write("{0}\0",n);
                }
            }
        }
    }
}

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Vijurria

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值