ImageVerifierCode 换一换
格式:DOCX , 页数:11 ,大小:108.79KB ,
资源ID:21044132      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/21044132.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(面向对象实验报告二投票选举管理程序的实现Word格式.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

面向对象实验报告二投票选举管理程序的实现Word格式.docx

1、每张选票可以选举多个候选人。当每张选票进行选举生效时,需要对选票中的信息进行合法性验证,判断是否存在对应的候选人。根据系统设置,对每一个候选人产生唯一的数字编号ID作为标识,为了避免候选人的姓名相同。经过分析,得出,选票应该设计成一个实体类,该类用于保存选票过程中,有哪些候选人被选入其中。候选人同样需要设计成一个实体类,包括候选人的ID,姓名和其他相应的信息。选票的选举过程和候选人票数的统计则需要在选票管理类中进行完成。1.3 流程图否是1.3 实现方案本程序采用c#的编程语言,面向对象的设计思想进行功能实现。开发环境:win7 开发工具;visual studio 2010编程语言:c#2

2、静态模型设计2.1 类设计(1)类“票数”Ticket属性: private int id;/投递的人(2) 类“候选人”Candidate 属性: private int age;/年龄 private string phone;/电话 private string position;/职位 private int count = 0;/票数 private string name;/姓名 private int id;/编号 ,唯一标识一个候选人 (3)类“投票控制类”TicketControl private List canList;/统计候选人Ticket ticList;/统计票数

3、 方法: public TicketControl() /实例化初始数据 public void vote()/ 进行投票结果的统计 public void showResult()/进行统计结果的显示2.2类图设计3 动态模型设计4 程序截图5 程序代码using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace voteDemo class Ticket private int id; public int Id get return id; set id = valu

4、e; public Ticket(int id) this.id = id; public Ticket() using System; class Candidate : IComparable private string name; public string Name get return name; set name = value; private int id;/编号 public int Id private int age; public int Count get return count; set count = value; public void AddTicket(

5、) this.count+; public Candidate(int id,string name,int age ,string phone,string position) this.name = name; this.age = age; this.phone = phone; this.position = position; public Candidate(int id) public override string ToString() string str = 候选人姓名:+name+n年龄:+age+n电话:+phone +n职位是:+position+n最后总票数为:+c

6、ount; return str; public override bool Equals(object obj) Candidate c = (Candidate)obj; if(c.id=this.id) return true; return false; public override int GetHashCode() return base.GetHashCode(); public int CompareTo(object obj) Candidate c=(Candidate)obj; if(c.countthis.count) return 1; if (c.count =

7、this.count) return 0; if (c.count this.count) return -1;using System.Collections; class TicketControl private int index=1; public TicketControl() canList = new List(); /初始化6个候选人 Candidate c = new Candidate(index, 张三1, 12, 123456, 职位 + index); canList.Add(c);index+; c = new Candidate(index, 张三2+index

8、); index+;张三3张三4张三5张三6 ticList = new List Ticket t = new Ticket(new int 1, 2, 3, 4 ); ticList.Add(t); t = new Ticket(new int 1, 2, 3, 4 ,5); t = new Ticket(new int 1, 2); t = new Ticket(new int 1, 2, 6, 7); t = new Ticket(new int 2, 3, 4 ); t = new Ticket(new int 2,4 ,8); t = new Ticket(new int 6,5,

9、 4 ); t = new Ticket(new int 5,6); t = new Ticket(new int 2,3 ); t = new Ticket(new int 4,7 ); /进行结果的显示 public void showResult() /对数据进行排序 canList.Sort(); Candidate c1 = canList0; Console.WriteLine(); Console.WriteLine(当选人是: + canList0.Name + ,票数为: + canList0.Count); foreach (Candidate c in canList)

10、Console.WriteLine(c.ToString(); /进行投票选举过程 public void vote() foreach( Ticket t in ticList) int tArr = t.Id; foreach(int id in tArr) foreach(Candidate c in canList) if(c.Id=id) c.AddTicket(); class Program static void Main(string args) TicketControl t = new TicketControl(); t.vote(); t.showResult(); Console.ReadLine();

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1