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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

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

1、面向对象实验报告二投票选举管理程序的实现投票选举管理程序的实现姓名:尹鹏飞学号:S2*11题目描述1.1 系统的功能需求投票选举过程预先指定若干名侯选人(最多12人)预先指定当选标准(给定百分数)提供投票记录功能(每张票可以选 0-12人)支持选举结果的统计输出(当选人和票数)设计一个监控模块作为选举系统的一部分仅负责数据统计和结果计算分析:对每个候选人分配一个id,编号,进行投票的选举.1.2功能描述投票选举系统中有一些候选人和选票。每张选票可以选举多个候选人。当每张选票进行选举生效时,需要对选票中的信息进行合法性验证,判断是否存在对应的候选人。根据系统设置,对每一个候选人产生唯一的数字编号

2、ID作为标识,为了避免候选人的姓名相同。经过分析,得出,选票应该设计成一个实体类,该类用于保存选票过程中,有哪些候选人被选入其中。候选人同样需要设计成一个实体类,包括候选人的ID,姓名和其他相应的信息。选票的选举过程和候选人票数的统计则需要在选票管理类中进行完成。1.3 流程图否是是否1.3 实现方案本程序采用c#的编程语言,面向对象的设计思想进行功能实现。开发环境:win7 开发工具;visual studio 2010编程语言:c#2 静态模型设计2.1 类设计(1)类“票数”Ticket属性: private int id;/投递的人(2) 类“候选人”Candidate 属性: pri

3、vate int age;/年龄 private string phone;/电话 private string position;/职位 private int count = 0;/票数 private string name;/姓名 private int id;/编号 ,唯一标识一个候选人 (3)类“投票控制类”TicketControl属性: private List canList;/统计候选人 private List ticList;/统计票数 方法: public TicketControl() /实例化初始数据 public void vote()/ 进行投票结果的统计 p

4、ublic 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 = value; public Ticket(int id) this.id = id; public Ticket() using Sy

5、stem;using System.Collections.Generic;using System.Linq;using System.Text;namespace voteDemo class Candidate : IComparable private string name;/姓名 public string Name get return name; set name = value; private int id;/编号 public int Id get return id; set id = value; private int age;/年龄 private string

6、phone;/电话 private string position;/职位 private int count = 0;/票数 public int Count get return count; set count = value; public void AddTicket() this.count+; public Candidate(int id,string name,int age ,string phone,string position) this.id = id; this.name = name; this.age = age; this.phone = phone; th

7、is.position = position; public Candidate(int id) this.id = id; public override string ToString() string str = 候选人姓名:+name+n年龄:+age+n电话:+phone +n职位是:+position+n最后总票数为:+count; return str; public override bool Equals(object obj) Candidate c = (Candidate)obj; if(c.id=this.id) return true; return false;

8、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 = this.count) return 0; if (c.count this.count) return -1; return 0; using System;using System.Collections.Generic;using System.Linq;u

9、sing System.Text;using System.Collections;namespace voteDemo class TicketControl private List canList;/统计候选人 private List ticList;/统计票数 private int index=1; public TicketControl() canList = new List(); /初始化6个候选人 Candidate c = new Candidate(index, 张三1, 12, 123456, 职位 + index); canList.Add(c);index+;

10、c = new Candidate(index, 张三2, 12, 123456, 职位+index); canList.Add(c); index+; c = new Candidate(index, 张三3, 12, 123456, 职位 + index); canList.Add(c); index+; c = new Candidate(index, 张三4, 12, 123456, 职位 + index); canList.Add(c); index+; c = new Candidate(index, 张三5, 12, 123456, 职位 + index); canList.Ad

11、d(c); index+; c = new Candidate(index, 张三6, 12, 123456, 职位 + index); canList.Add(c); index+; 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); ticList.Add(t); t = new Ticket(new int 1, 2); ticList.Add(t); t = new Ticket(new int 1

12、, 2, 6, 7); ticList.Add(t); t = new Ticket(new int 2, 3, 4 ); ticList.Add(t); t = new Ticket(new int 2,4 ,8); ticList.Add(t); t = new Ticket(new int 6,5, 4 ); ticList.Add(t); t = new Ticket(new int 5,6); ticList.Add(t); t = new Ticket(new int 2,3 ); ticList.Add(t); t = new Ticket(new int 4,7 ); ticL

13、ist.Add(t); /进行结果的显示 public void showResult() /对数据进行排序 canList.Sort(); Candidate c1 = canList0; Console.WriteLine(); Console.WriteLine(当选人是: + canList0.Name + ,票数为: + canList0.Count); foreach (Candidate c in canList) Console.WriteLine(); Console.WriteLine(c.ToString(); /进行投票选举过程 public void vote() f

14、oreach( Ticket t in ticList) int tArr = t.Id; foreach(int id in tArr) foreach(Candidate c in canList) if(c.Id=id) c.AddTicket(); using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace voteDemo class Program static void Main(string args) TicketControl t = new TicketControl(); t.vote(); t.showResult(); Console.ReadLine();

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

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