2016年11月24日--面向对象、C#小复习
面对对象就是:把数据及对数据的操作方法放在一起,作为一个相互依存的整体——对象。对同类对象抽象出其共性,形成类。类中的大多数数据,只能用本类的方法进行处理。类通过一个简单的外部接口与外界发生关系,对象与对象之间通过消息进行通信。程序流程由用户在使用中决定。
多态:是将父对象设置成为和一个或更多的他的子对象相等的技术,赋值之后,父对象就可以根据当前赋值给它的子对象的特性以不同的方式运作。简单的说,就是一句话:允许将子类类型的指针赋值给父类类型的指针。
小练习
在控制台程序中使用结构体、集合,完成下列要求
项目要求:
一、连续输入5个学生的信息,每个学生都有以下4个内容:
1、序号 - 根据输入的顺序自动生成,不需要手动填写,如输入第一个学生的序号是1,第二个是2,以此类推
2、学号 - 必填,如:S001,S002... 以此类推
3、姓名 - 必填
4、成绩 - 大于等于0,小于等于100
以上内容必须按照要求填写,请写好相应的验证,如果没填写正确,则让用户重复填写到正确为止
二、5个学生信息都输入完毕后,按照分数从高到低的顺序将学生信息展示出来
显示格式如下:
==============学生成绩展示=================
序号 学号 姓名 成绩
3 S003 张三 100
1 S001 李四 99
2 S002 王五 98
ArrayList ar = new ArrayList();
string str = "";
//do{
// Console.Write("请输入学号:");
// stt.str=Console.ReadLine();
//} while (stt.str.StartsWith("s") != stt.str.EndsWith("s")&&stt.str.IndexOf("s")!=0);
; j < ; j++)
{
stu stt = new stu();
stt.num = j;
for (; ; )
{
Console.Write("请输入第" + j + "个学生的学号:s");
try
{
int i = Convert.ToInt32(Console.ReadLine());
)
i = Math.Abs(i);
)
{
stt.str = ");
}
)
{
stt.str = ");
}
break;
}
catch
{
Console.WriteLine("请输入数字");
}
}
for (; ; )
{
Console.Write("请输入第" + j + "个学生的姓名:");
stt.name = Console.ReadLine();
if (stt.name != "")
break;
else
Console.WriteLine("姓名不能为空");
}
for (; ; )
{
Console.Write("请输入第" + j + "个学生的成绩:");
try
{
stt.chengji = Convert.ToDouble(Console.ReadLine());
&& stt.chengji <= )
{
break;
}
)
{
Console.WriteLine("成绩不能大于100");
}
else
{
Console.WriteLine("成绩不能小于0");
}
}
catch
{
Console.WriteLine("请输入数字");
}
}
ar.Add(stt);
}
Console.WriteLine("┌───────────────────┐");
Console.WriteLine("│ 所有学生数据 │");
Console.WriteLine("│\t序号\t学号\t姓名\t成绩\t│");
; k <= ar.Count - ; k++)
{
stu stt = (stu)ar[k];
Console.WriteLine("│\t{0}\t{1}\t{2}\t{3}\t│", stt.num, stt.str, stt.name, stt.chengji);
}
Console.WriteLine("└───────────────────┘");
; j < ar.Count; j++)
{
for (int k = j; k < ar.Count; k++)
{
if (((stu)ar[j]).chengji < ((stu)ar[k]).chengji)
{
object zhon = ar[j];
ar[j] = ar[k];
ar[k] = zhon;
}
}
}
Console.WriteLine("┌───────────────────┐");
Console.WriteLine("│ 按成绩排序 │");
Console.WriteLine("│\t序号\t学号\t姓名\t成绩\t│");
; k <= ar.Count - ; k++)
{
stu stt = (stu)ar[k];
Console.WriteLine("│\t{0}\t{1}\t{2}\t{3}\t│", stt.num, stt.str, stt.name, stt.chengji);
}
Console.WriteLine("└───────────────────┘");
Console.ReadLine();
示例
2016年11月24日--面向对象、C#小复习的更多相关文章
- 2016年11月24日 星期四 --出埃及记 Exodus 20:15
2016年11月24日 星期四 --出埃及记 Exodus 20:15 "You shall not steal.不可偷盗.
- 2016年11月27日--面向对象:多态、类库、委托、is和as运算符、泛型集合
1.虚方法 virtual 重写 override 父类中的方法,在子类中并不适用,那么子类需要自主更改继承的方法或者是属性,那父类中加了virtual关键字的方法才可以被子类重写,子类重写父类的方法 ...
- 2016年11月8日 星期二 --出埃及记 Exodus 19:24
2016年11月8日 星期二 --出埃及记 Exodus 19:24 The LORD replied, "Go down and bring Aaron up with you. But ...
- 2016年12月24日 星期六 --出埃及记 Exodus 21:19
2016年12月24日 星期六 --出埃及记 Exodus 21:19 the one who struck the blow will not be held responsible if the ...
- 2016年11月30日 星期三 --出埃及记 Exodus 20:21
2016年11月30日 星期三 --出埃及记 Exodus 20:21 The people remained at a distance, while Moses approached the th ...
- 2016年11月29日 星期二 --出埃及记 Exodus 20:20
2016年11月29日 星期二 --出埃及记 Exodus 20:20 Moses said to the people, "Do not be afraid. God has come t ...
- 2016年11月28日 星期一 --出埃及记 Exodus 20:19
2016年11月28日 星期一 --出埃及记 Exodus 20:19 and said to Moses, "Speak to us yourself and we will listen ...
- 2016年11月27日 星期日 --出埃及记 Exodus 20:18
2016年11月27日 星期日 --出埃及记 Exodus 20:18 When the people saw the thunder and lightning and heard the trum ...
- 2016年11月26日 星期六 --出埃及记 Exodus 20:17
2016年11月26日 星期六 --出埃及记 Exodus 20:17 "You shall not covet your neighbor's house. You shall not c ...
随机推荐
- codevs 2928 你缺什么
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 继"你幸福吗"之后,央视又推出了"你缺什么 ...
- 错误"ORA-04091: table is mutating, trigger/function may not see it"的原因以及解决办法
错误的原因该错误是在编写trigger时常遇到的问题,其根本原因是由于对本表的操作造成的.对于使用了for each row 的触发器,做了DML操作(delete,update,insert),还没 ...
- 去除phpcms会员登录后头部登陆条的会员名称的括号
phpcms会员登录后显示会员名称是带括号的,现在把他修改成不带括号. 找到函数库libs/functions/global.func.php,修改如下即可: function get_nicknam ...
- 随便写一下看下效果。一个js问题
(function(a){ console.log(a); var a = 10; function a(){} }(100)); 问:执行这段代码会输出什么.
- linux基础知识与技能1
1.隐藏文件与非隐藏文件Linux中:linux中隐藏文件特点是文件名以.开头,跟文件属性无关.在linux中查看隐藏文件用ls -a命令(普通显示ls)2.相对路径与绝对路径什么是路径:路径是用来标 ...
- jQuery1.9之后使用on()绑定 动态生成元素的 事件无效
来自互联网: 需要绑定a的父级元素(此元素必须为静态元素,不是后来动态生成的),然后设定on()方法的selector参数才行: $('p').on('mouseenter', 'a', functi ...
- jsp项目部署
每新建一个项目都要发布到服务器,也就是项目部署,在tomcat中的 tomcat\Tomcat 6.0\webapps 路径下就会新建你的项目文件夹 webapps是tomcat的默认访问路径,很 ...
- 架构师养成记--3.synchronized细节问题
一.synchronized有锁重入的特点,某个线程得到对象的锁后,再次请求此对象可以再次得到改对象的锁.如下示例,在method1中调用method2,在method2中调用method3,而met ...
- Nginx简易配置文件(一)(静态页面及PHP页面解析)
user nobody nobody; worker_processes 4; error_log logs/error.log; pid logs/nginx.pid; events { use e ...
- python标准模块(三)
本文会涉及到的模块: subprocess logging 1. subprocess 可以执行shell命令的相关模块和函数有: os.system os.spawn os.popen --废弃 p ...