(面向对象实验报告二)投票选举管理程序的实现.doc_第1页
(面向对象实验报告二)投票选举管理程序的实现.doc_第2页
(面向对象实验报告二)投票选举管理程序的实现.doc_第3页
(面向对象实验报告二)投票选举管理程序的实现.doc_第4页
(面向对象实验报告二)投票选举管理程序的实现.doc_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

投票选举管理程序的实现姓名:尹鹏飞学号:S2014070311题目描述1.1 系统的功能需求投票选举过程 预先指定若干名侯选人(最多12人) 预先指定当选标准(给定百分数) 提供投票记录功能(每张票可以选 0-12人) 支持选举结果的统计输出(当选人和票数)设计一个监控模块 作为选举系统的一部分 仅负责数据统计和结果计算分析:对每个候选人分配一个id,编号,进行投票的选举.1.2功能描述投票选举系统中有一些候选人和选票。每张选票可以选举多个候选人。当每张选票进行选举生效时,需要对选票中的信息进行合法性验证,判断是否存在对应的候选人。根据系统设置,对每一个候选人产生唯一的数字编号ID作为标识,为了避免候选人的姓名相同。经过分析,得出,选票应该设计成一个实体类,该类用于保存选票过程中,有哪些候选人被选入其中。候选人同样需要设计成一个实体类,包括候选人的ID,姓名和其他相应的信息。选票的选举过程和候选人票数的统计则需要在选票管理类中进行完成。1.3 流程图投票选举完成对候选人投票的录入重新录入信息否信息合法性验证输出统计结果对候选人信息进行票数增加是是在数据库中查找候选人否找到候选人信息继续下一张选票统计每一个候选人的票数并进行排序1.3 实现方案本程序采用c#的编程语言,面向对象的设计思想进行功能实现。开发环境:win7 开发工具;visual studio 2010编程语言:c#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;/统计候选人 private List ticList;/统计票数 方法: 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 = value; public Ticket(int id) this.id = id; public Ticket() using System;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 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; = name; this.age = age; this.phone = phone; this.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; 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;using 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+; 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.Add(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, 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 ); ticList.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() 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(); using System;u

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论