using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _17道练习题
{
#region 第一题
// 1、类型转换
// 让用户输入他的语文和数学成绩 计算他的总成绩并显示出来?
//注意:Convert.ToInt32(待转字符串)
// 每一种类型都可以转换为string类型 .ToString()方法
//class Program
//{
// static void Main(string[] args)
// {
// Console.WriteLine("您的语文成绩是?");
// float yuwen = float.Parse(Console.ReadLine());
// Console.WriteLine("您的数学成绩是?");
// float shuxue = float.Parse(Console.ReadLine());
// float sum = yuwen + shuxue;
// Console.WriteLine("您的总成绩="+sum);
// Console.ReadKey();
// }
//}
#endregion
#region 第二题
//2、让用户输入张三的语文和英语成绩 输出以下判断是否正确 正确输出True 错误输出False
// 1)张三的语文和英语成绩都大于80分
// 2)张三的语文和英语至少一门大于80分
//class Program
//{
// static void Main(string[] args)
// {
// Console.WriteLine("请出入张三的语文成绩");
// float yuwen = float.Parse(Console.ReadLine());
// Console.WriteLine("请输入张三的英语成绩");
// float english = float.Parse(Console.ReadLine());
// if (yuwen > 80 && english > 80)
// {
// Console.WriteLine("True");
// }
// else
// {
// Console.WriteLine("False");
// }
// if (yuwen > 80 || english > 80)
// {
// Console.WriteLine("True");
// }
// else
// {
// Console.WriteLine("False");
// }
// Console.ReadKey();
// }
//}
#endregion
#region 第三题
//3、让用户输入一个年份,如果是闰年 则输出true 如果不是则输出false
// 判断闰年(符合下面两个条件之一)
//class Program
//{
// static void Main(string[] args)
// {
// Console.WriteLine("请您出入一个年份,看看是平年还是闰年");
// int year = int.Parse(Console.ReadLine());
// if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0)
// {
// Console.WriteLine("闰年True");
// }
// else
// {
// Console.WriteLine("平年False");
// }
// Console.ReadKey();
// }
//}
#endregion
#region 第四题
//4、说出学过的数据类型有那些 运算符有那些
//class Program
//{
// static void Main(string[] args)
// {
// //值类型 引用类型 浮点类型
// //+ - * / += -= *= /= > < >= <= == != ++ -- && || ! {?:}(三目运算符)
// }
//}
#endregion
#region 第五题
//5、输入一个月份判断是在那个季节(用switch判断)
//class Program
//{
// static void Main(string[] args)
// {
// Console.WriteLine("请您输入一个月份");
// int month = int.Parse(Console.ReadLine());
// switch(month)
// {
// case 3:
// case 4:
// case 5:
// Console.WriteLine("春季");
// break;
// case 6:
// case 7:
// case 8:
// Console.WriteLine("夏季");
// break;
// case 9:
// case 10:
// case 11:
// Console.WriteLine("秋季");
// break;
// case 12:
// case 1:
// case 2:
// Console.WriteLine("冬季");
// break;
// default:
// Console.WriteLine("亲,傻了吧");
// break;
// }
// Console.ReadKey();
// }
//}
#endregion
#region 第六题
//6、计算1到100之间整数的和
//class Program
//{
// static void Main(string[] args)
// {
// int sum = 0;
// for (int i = 1; i <= 100; i++)
// {
// sum += i;
// }
// Console.WriteLine(sum);
// Console.ReadKey();
// }
//}
#endregion
#region 第七题
//7、要求用户输入用户名和密码 用户名只要不是wyzc 密码不是666666就一直提示用户名或密码错误 请重新输入
//class Program
//{
// static void Main(string[] args)
// {
// bool num = true;
// bool num1 = false;
// while (num == true&&num1==false)
// {
// try
// {
// Console.WriteLine("请输入账号");
// string zhanghao = Console.ReadLine();
// Console.WriteLine("请输入密码");
// int mima = Convert.ToInt32(Console.ReadLine());
// if (zhanghao == "wyzc" && mima == 666666)
// {
// Console.WriteLine("登录成功");
// num = false;
// }
// else
// {
// Console.WriteLine("请重新输入");
// num = true;
// }
// }
// catch
// {
// Console.WriteLine("输入错误");
// num1 = false;
// }
// finally
// {
// Console.WriteLine("恭喜你");
// }
// }
// Console.WriteLine("输入正确");
// Console.ReadKey();
// }
//}
#endregion
#region 第八题
//8、输出100之内所有的偶数
//class Program
//{
// static void Main(string[] args)
// {
// for (int i = 0; i <= 100; i++)
// {
// if (i % 2 == 0)
// {
// Console.WriteLine(i);
// }
// }
// Console.ReadKey();
// }
//}
#endregion
#region 第九题
//9、从一个整数数组中取出最大的整数
//class Program
//{
// static void Main(string[] args)
// {
// int[] num={1,2,3,4,5,6,7,8,9};
// for (int i = 0; i < num.Length-1; i++)
// {
// for (int j = 0; j < num.Length - i - 1; j++)
// {
// if (num[j] < num[j + 1])
// {
// int temp = num[j];
// num[j] = num[j+1];
// num[j+1] = temp;
// }
// }
// }
// int max = num[0];
// Console.WriteLine(max);
// Console.ReadKey();
// }
//}
#endregion
#region 第十题
//10、计算一个整数数组的所有元素的和
//class Program
//{
// static void Main(string[] args)
// {
// int[] num = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
// int sum=0;
// for (int i = 0; i < num.Length; i++)
// {
// sum += num[i];
// }
// Console.WriteLine(sum);
// Console.ReadKey();
// }
//}
#endregion
#region 第十一题
//11、任意写个整数数组进行排序
//class Program
//{
// static void Main(string[] args)
// {
// int[] num = { 12, 46, 852, 652, 65, 526, 541, 123 };
// for (int i = 0; i < num.Length; i++)
// {
// for (int j = 0; j < num.Length - i - 1; j++)
// {
// if (num[j] > num[j + 1])
// {
// int temp = num[j];
// num[j] = num[j + 1];
// num[j + 1] = temp;
// }
// }
// }
// for (int i = 0; i < num.Length; i++)
// {
// Console.WriteLine(num[i]);
// }
// Console.ReadKey();
// }
//}
#endregion
#region 第十二题
//定义一个叫Gender的枚举类型 他的值只有两个 男和女
//enum Gender
//{
// Man=1,
// Woman,
//}
//class Program
//{
// static void Main(string[] args)
// {
// int num = int.Parse(Console.ReadLine());
// switch (num)
// {
// case (int)Gender.Man:
// Console.WriteLine("男的");
// break;
// case (int)Gender.Woman:
// Console.WriteLine("女的");
// break;
// default:
// Console.WriteLine("0妖0");
// break;
// }
// Console.ReadKey();
// }
//}
#endregion
#region 第十三题
//13、定义一个结构类型Person 有三个成员 分别为姓名 性别 年龄
// 声明两个Person类型的变量 分别表示 jack 男 18 lucy 女 19
//class Program
//{
// static void Main(string[] args)
// {
// Person[] person=new Person[3];
// person[0].name1="jack";
// person[0].name2 = "男";
// person[0].age = 18;
// person[1].name1 = "lucy";
// person[1].name2 = "女";
// person[1].age = 19;
// Console.WriteLine(person[0].name1+" "+person[0].name2+" "+person[0].age);
// Console.WriteLine(person[1].name1+" "+person[1].name2+" "+person[1].age);
// Console.ReadKey();
// }
// struct Person
// {
// public string name1;
// public string name2;
// public int age;
// }
//}
#endregion
#region 第十四题
//14、自己写一个方法查找两个整数中的最大值
//class Program
//{
// static void Main(string[] args)
// {
// Console.WriteLine("请输入两个数");
// int num1 = int.Parse(Console.ReadLine());
// int num2 = int.Parse(Console.ReadLine());
// if (num1 > num2)
// {
// Console.WriteLine("最大值是=" + num1);
// }
// else
// {
// Console.WriteLine("最大值是=" + num2);
// }
// Console.ReadKey();
// }
//}
#endregion
#region 第十五题
// 15、自己写一个方法计算整数数组的平均值
//class Program
//{
// static void Main(string[] args)
// {
// int[] num = { 12, 5, 96, 45, 54, 2, 3, 5 };
// float sum = 0;
// for (int i = 0; i < num.Length; i++)
// {
// sum += num[i];
// }
// float ave = sum / num.Length;
// Console.WriteLine(ave);
// Console.ReadKey();
// }
//}
#endregion
#region 第十六题
//16、用方法实现找出一个int类型数组中的最大值和最小值 在另外的方法输出(out关键字
//class Program
//{
// static void Main(string[] args)
// {
// int numOne=1;
// int numTwo=2;
// int numMax;
// int numMin;
// ShuZU(numOne, numTwo, out numMax, out numMin);
// Console.WriteLine(numMax);
// Console.WriteLine(numMin);
// Console.ReadKey();
// }
// public static void ShuZU(int a,int b,out int max,out int min)
// {
// if (a > b)
// {
// max = a;
// min = b;
// }
// else
// {
// max = b;
// min = a;
// }
// }
//}
#endregion
#region 第十七题
// 17、定义一个学生类,
//有六个属性,分别为姓名、性别、年龄、语文、数学、英语成绩。
//有2个方法:
//一个打招呼的方法:介绍自己叫XX,今年几岁了。是男同学还是女同学。
//两个计算自己总分数和平均分的方法。{显示:我叫XX,这次考试总成绩为X分,平均成绩为X分}
//实化两个对象并测试:
//张三 男 18 三科成绩为:90 95 80
//小兰 女 16 三科成绩为:95 85 100
// public class Student
// {
// private string name;
// public string Name
// {
// get { return name; }
// set { name = value; }
// }
// private char sex;
// public char Sex
// {
// get { return sex; }
// set { sex = value; }
// }
// private int age;
// public int Age
// {
// get { return age; }
// set { age = value; }
// }
// private float chineseScore;
// public float ChineseScore
// {
// get { return chineseScore; }
// set { chineseScore = value; }
// }
// private float mathScore;
// public float MathScore
// {
// get { return mathScore; }
// set { mathScore = value; }
// }
// private float englishScore;
// public float EnglishScore
// {
// get { return englishScore; }
// set { englishScore = value; }
// }
// public void Say()
// {
// Console.WriteLine("我叫{0},今年{1}岁了,是{2}同学",name,age,sex);
// }
// public void Ave()
// {
// float tatol=mathScore+chineseScore+englishScore;
// float ave = tatol / 3;
// Console.WriteLine("我叫{0} 这次考试总成绩{1}分,这次考试的平均分{2}分",name,tatol,ave);
// }
// }
// class Program
// {
// static void Main(string[] args)
// {
// Student zhangsan = new Student();
// Student xiaolan = new Student();
// zhangsan.Age = 18;
// zhangsan.Sex = '男';
// zhangsan.Name = "张三";
// zhangsan.ChineseScore = 90;
// zhangsan.EnglishScore = 95;
// zhangsan.MathScore = 80;
// zhangsan.Say();
// zhangsan.Ave();
// xiaolan.Age = 16;
// xiaolan.Sex = '女';
// xiaolan.Name = "小兰";
// xiaolan.ChineseScore = 90;
// xiaolan.EnglishScore = 95;
// xiaolan.MathScore = 100;
// xiaolan.Say();
// xiaolan.Ave();
// Console.ReadKey();
// }
// }
//给前面写的学生类添加构造方法.使在实例化学生类的时候可以通过构造方法对姓名性别年龄语数英等属性赋值,也可以只对姓名和性别赋值.年龄默认为18岁,语数英成绩默认为0分.
//张三 男 18 三科成绩为:90 95 80
//小兰 女 16 三科成绩为:95 85 100
public class Student
{
private string _name;
private char _sex;
private int _age;
private float _chineseScore;
private float _mathScore;
private float _englishScore;
#region 构造函数 可以重载 可以对属性赋值
public Student(string name, char sex, int age, float chineseScore, float mathScore, float englishScore)
{
_name = name;
_sex = sex;
_age = age;
_chineseScore = chineseScore;
_mathScore = mathScore;
_englishScore = englishScore;
}
public Student(string name, char sex)
{
_name = name;
_sex = sex;
}
#endregion
public void Say()
{
Console.WriteLine("我叫{0},今年{1}岁了,是{2}同学", _name, _age, _sex); ;
}
public void Ave()
{
float tatol = _mathScore + _chineseScore + _englishScore;
float ave = tatol / 3;
Console.WriteLine("我叫{0} 这次考试总成绩{1}分,这次考试的平均分{2}分", _name, tatol, ave);
}
}
class Program
{
static void Main(string[] args)
{
Student stu = new Student("张三", '男');
Student stu1 = new Student("小兰", '女', 16, 90, 95, 80);
stu.Say();
stu1.Say();
stu1.Ave();
Console.ReadKey();
}
}
#endregion
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _17道练习题
{
#region 第一题
// 1、类型转换
// 让用户输入他的语文和数学成绩 计算他的总成绩并显示出来?
//注意:Convert.ToInt32(待转字符串)
// 每一种类型都可以转换为string类型 .ToString()方法
//class Program
//{
// static void Main(string[] args)
// {
// Console.WriteLine("您的语文成绩是?");
// float yuwen = float.Parse(Console.ReadLine());
// Console.WriteLine("您的数学成绩是?");
// float shuxue = float.Parse(Console.ReadLine());
// float sum = yuwen + shuxue;
// Console.WriteLine("您的总成绩="+sum);
// Console.ReadKey();
// }
//}
#endregion
#region 第二题
//2、让用户输入张三的语文和英语成绩 输出以下判断是否正确 正确输出True 错误输出False
// 1)张三的语文和英语成绩都大于80分
// 2)张三的语文和英语至少一门大于80分
//class Program
//{
// static void Main(string[] args)
// {
// Console.WriteLine("请出入张三的语文成绩");
// float yuwen = float.Parse(Console.ReadLine());
// Console.WriteLine("请输入张三的英语成绩");
// float english = float.Parse(Console.ReadLine());
// if (yuwen > 80 && english > 80)
// {
// Console.WriteLine("True");
// }
// else
// {
// Console.WriteLine("False");
// }
// if (yuwen > 80 || english > 80)
// {
// Console.WriteLine("True");
// }
// else
// {
// Console.WriteLine("False");
// }
// Console.ReadKey();
// }
//}
#endregion
#region 第三题
//3、让用户输入一个年份,如果是闰年 则输出true 如果不是则输出false
// 判断闰年(符合下面两个条件之一)
//class Program
//{
// static void Main(string[] args)
// {
// Console.WriteLine("请您出入一个年份,看看是平年还是闰年");
// int year = int.Parse(Console.ReadLine());
// if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0)
// {
// Console.WriteLine("闰年True");
// }
// else
// {
// Console.WriteLine("平年False");
// }
// Console.ReadKey();
// }
//}
#endregion
#region 第四题
//4、说出学过的数据类型有那些 运算符有那些
//class Program
//{
// static void Main(string[] args)
// {
// //值类型 引用类型 浮点类型
// //+ - * / += -= *= /= > < >= <= == != ++ -- && || ! {?:}(三目运算符)
// }
//}
#endregion
#region 第五题
//5、输入一个月份判断是在那个季节(用switch判断)
//class Program
//{
// static void Main(string[] args)
// {
// Console.WriteLine("请您输入一个月份");
// int month = int.Parse(Console.ReadLine());
// switch(month)
// {
// case 3:
// case 4:
// case 5:
// Console.WriteLine("春季");
// break;
// case 6:
// case 7:
// case 8:
// Console.WriteLine("夏季");
// break;
// case 9:
// case 10:
// case 11:
// Console.WriteLine("秋季");
// break;
// case 12:
// case 1:
// case 2:
// Console.WriteLine("冬季");
// break;
// default:
// Console.WriteLine("亲,傻了吧");
// break;
// }
// Console.ReadKey();
// }
//}
#endregion
#region 第六题
//6、计算1到100之间整数的和
//class Program
//{
// static void Main(string[] args)
// {
// int sum = 0;
// for (int i = 1; i <= 100; i++)
// {
// sum += i;
// }
// Console.WriteLine(sum);
// Console.ReadKey();
// }
//}
#endregion
#region 第七题
//7、要求用户输入用户名和密码 用户名只要不是wyzc 密码不是666666就一直提示用户名或密码错误 请重新输入
//class Program
//{
// static void Main(string[] args)
// {
// bool num = true;
// bool num1 = false;
// while (num == true&&num1==false)
// {
// try
// {
// Console.WriteLine("请输入账号");
// string zhanghao = Console.ReadLine();
// Console.WriteLine("请输入密码");
// int mima = Convert.ToInt32(Console.ReadLine());
// if (zhanghao == "wyzc" && mima == 666666)
// {
// Console.WriteLine("登录成功");
// num = false;
// }
// else
// {
// Console.WriteLine("请重新输入");
// num = true;
// }
// }
// catch
// {
// Console.WriteLine("输入错误");
// num1 = false;
// }
// finally
// {
// Console.WriteLine("恭喜你");
// }
// }
// Console.WriteLine("输入正确");
// Console.ReadKey();
// }
//}
#endregion
#region 第八题
//8、输出100之内所有的偶数
//class Program
//{
// static void Main(string[] args)
// {
// for (int i = 0; i <= 100; i++)
// {
// if (i % 2 == 0)
// {
// Console.WriteLine(i);
// }
// }
// Console.ReadKey();
// }
//}
#endregion
#region 第九题
//9、从一个整数数组中取出最大的整数
//class Program
//{
// static void Main(string[] args)
// {
// int[] num={1,2,3,4,5,6,7,8,9};
// for (int i = 0; i < num.Length-1; i++)
// {
// for (int j = 0; j < num.Length - i - 1; j++)
// {
// if (num[j] < num[j + 1])
// {
// int temp = num[j];
// num[j] = num[j+1];
// num[j+1] = temp;
// }
// }
// }
// int max = num[0];
// Console.WriteLine(max);
// Console.ReadKey();
// }
//}
#endregion
#region 第十题
//10、计算一个整数数组的所有元素的和
//class Program
//{
// static void Main(string[] args)
// {
// int[] num = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
// int sum=0;
// for (int i = 0; i < num.Length; i++)
// {
// sum += num[i];
// }
// Console.WriteLine(sum);
// Console.ReadKey();
// }
//}
#endregion
#region 第十一题
//11、任意写个整数数组进行排序
//class Program
//{
// static void Main(string[] args)
// {
// int[] num = { 12, 46, 852, 652, 65, 526, 541, 123 };
// for (int i = 0; i < num.Length; i++)
// {
// for (int j = 0; j < num.Length - i - 1; j++)
// {
// if (num[j] > num[j + 1])
// {
// int temp = num[j];
// num[j] = num[j + 1];
// num[j + 1] = temp;
// }
// }
// }
// for (int i = 0; i < num.Length; i++)
// {
// Console.WriteLine(num[i]);
// }
// Console.ReadKey();
// }
//}
#endregion
#region 第十二题
//定义一个叫Gender的枚举类型 他的值只有两个 男和女
//enum Gender
//{
// Man=1,
// Woman,
//}
//class Program
//{
// static void Main(string[] args)
// {
// int num = int.Parse(Console.ReadLine());
// switch (num)
// {
// case (int)Gender.Man:
// Console.WriteLine("男的");
// break;
// case (int)Gender.Woman:
// Console.WriteLine("女的");
// break;
// default:
// Console.WriteLine("0妖0");
// break;
// }
// Console.ReadKey();
// }
//}
#endregion
#region 第十三题
//13、定义一个结构类型Person 有三个成员 分别为姓名 性别 年龄
// 声明两个Person类型的变量 分别表示 jack 男 18 lucy 女 19
//class Program
//{
// static void Main(string[] args)
// {
// Person[] person=new Person[3];
// person[0].name1="jack";
// person[0].name2 = "男";
// person[0].age = 18;
// person[1].name1 = "lucy";
// person[1].name2 = "女";
// person[1].age = 19;
// Console.WriteLine(person[0].name1+" "+person[0].name2+" "+person[0].age);
// Console.WriteLine(person[1].name1+" "+person[1].name2+" "+person[1].age);
// Console.ReadKey();
// }
// struct Person
// {
// public string name1;
// public string name2;
// public int age;
// }
//}
#endregion
#region 第十四题
//14、自己写一个方法查找两个整数中的最大值
//class Program
//{
// static void Main(string[] args)
// {
// Console.WriteLine("请输入两个数");
// int num1 = int.Parse(Console.ReadLine());
// int num2 = int.Parse(Console.ReadLine());
// if (num1 > num2)
// {
// Console.WriteLine("最大值是=" + num1);
// }
// else
// {
// Console.WriteLine("最大值是=" + num2);
// }
// Console.ReadKey();
// }
//}
#endregion
#region 第十五题
// 15、自己写一个方法计算整数数组的平均值
//class Program
//{
// static void Main(string[] args)
// {
// int[] num = { 12, 5, 96, 45, 54, 2, 3, 5 };
// float sum = 0;
// for (int i = 0; i < num.Length; i++)
// {
// sum += num[i];
// }
// float ave = sum / num.Length;
// Console.WriteLine(ave);
// Console.ReadKey();
// }
//}
#endregion
#region 第十六题
//16、用方法实现找出一个int类型数组中的最大值和最小值 在另外的方法输出(out关键字
//class Program
//{
// static void Main(string[] args)
// {
// int numOne=1;
// int numTwo=2;
// int numMax;
// int numMin;
// ShuZU(numOne, numTwo, out numMax, out numMin);
// Console.WriteLine(numMax);
// Console.WriteLine(numMin);
// Console.ReadKey();
// }
// public static void ShuZU(int a,int b,out int max,out int min)
// {
// if (a > b)
// {
// max = a;
// min = b;
// }
// else
// {
// max = b;
// min = a;
// }
// }
//}
#endregion
#region 第十七题
// 17、定义一个学生类,
//有六个属性,分别为姓名、性别、年龄、语文、数学、英语成绩。
//有2个方法:
//一个打招呼的方法:介绍自己叫XX,今年几岁了。是男同学还是女同学。
//两个计算自己总分数和平均分的方法。{显示:我叫XX,这次考试总成绩为X分,平均成绩为X分}
//实化两个对象并测试:
//张三 男 18 三科成绩为:90 95 80
//小兰 女 16 三科成绩为:95 85 100
// public class Student
// {
// private string name;
// public string Name
// {
// get { return name; }
// set { name = value; }
// }
// private char sex;
// public char Sex
// {
// get { return sex; }
// set { sex = value; }
// }
// private int age;
// public int Age
// {
// get { return age; }
// set { age = value; }
// }
// private float chineseScore;
// public float ChineseScore
// {
// get { return chineseScore; }
// set { chineseScore = value; }
// }
// private float mathScore;
// public float MathScore
// {
// get { return mathScore; }
// set { mathScore = value; }
// }
// private float englishScore;
// public float EnglishScore
// {
// get { return englishScore; }
// set { englishScore = value; }
// }
// public void Say()
// {
// Console.WriteLine("我叫{0},今年{1}岁了,是{2}同学",name,age,sex);
// }
// public void Ave()
// {
// float tatol=mathScore+chineseScore+englishScore;
// float ave = tatol / 3;
// Console.WriteLine("我叫{0} 这次考试总成绩{1}分,这次考试的平均分{2}分",name,tatol,ave);
// }
// }
// class Program
// {
// static void Main(string[] args)
// {
// Student zhangsan = new Student();
// Student xiaolan = new Student();
// zhangsan.Age = 18;
// zhangsan.Sex = '男';
// zhangsan.Name = "张三";
// zhangsan.ChineseScore = 90;
// zhangsan.EnglishScore = 95;
// zhangsan.MathScore = 80;
// zhangsan.Say();
// zhangsan.Ave();
// xiaolan.Age = 16;
// xiaolan.Sex = '女';
// xiaolan.Name = "小兰";
// xiaolan.ChineseScore = 90;
// xiaolan.EnglishScore = 95;
// xiaolan.MathScore = 100;
// xiaolan.Say();
// xiaolan.Ave();
// Console.ReadKey();
// }
// }
//给前面写的学生类添加构造方法.使在实例化学生类的时候可以通过构造方法对姓名性别年龄语数英等属性赋值,也可以只对姓名和性别赋值.年龄默认为18岁,语数英成绩默认为0分.
//张三 男 18 三科成绩为:90 95 80
//小兰 女 16 三科成绩为:95 85 100
public class Student
{
private string _name;
private char _sex;
private int _age;
private float _chineseScore;
private float _mathScore;
private float _englishScore;
#region 构造函数 可以重载 可以对属性赋值
public Student(string name, char sex, int age, float chineseScore, float mathScore, float englishScore)
{
_name = name;
_sex = sex;
_age = age;
_chineseScore = chineseScore;
_mathScore = mathScore;
_englishScore = englishScore;
}
public Student(string name, char sex)
{
_name = name;
_sex = sex;
}
#endregion
public void Say()
{
Console.WriteLine("我叫{0},今年{1}岁了,是{2}同学", _name, _age, _sex); ;
}
public void Ave()
{
float tatol = _mathScore + _chineseScore + _englishScore;
float ave = tatol / 3;
Console.WriteLine("我叫{0} 这次考试总成绩{1}分,这次考试的平均分{2}分", _name, tatol, ave);
}
}
class Program
{
static void Main(string[] args)
{
Student stu = new Student("张三", '男');
Student stu1 = new Student("小兰", '女', 16, 90, 95, 80);
stu.Say();
stu1.Say();
stu1.Ave();
Console.ReadKey();
}
}
#endregion
}