数据结构课程设计(舞会来宾相关统计问题)

上传人:lizhe****0001 文档编号:31282507 上传时间:2018-02-06 格式:DOCX 页数:10 大小:216.77KB
返回 下载 相关 举报
数据结构课程设计(舞会来宾相关统计问题)_第1页
第1页 / 共10页
数据结构课程设计(舞会来宾相关统计问题)_第2页
第2页 / 共10页
数据结构课程设计(舞会来宾相关统计问题)_第3页
第3页 / 共10页
数据结构课程设计(舞会来宾相关统计问题)_第4页
第4页 / 共10页
数据结构课程设计(舞会来宾相关统计问题)_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《数据结构课程设计(舞会来宾相关统计问题)》由会员分享,可在线阅读,更多相关《数据结构课程设计(舞会来宾相关统计问题)(10页珍藏版)》请在金锄头文库上搜索。

1、数据结构课程设计报告简单的舞会统计问题一、题目要求: 运用数据结构知识,编写代码,实现:1. 对一个舞会所有来宾性别录入,并输出参加舞会总人数以及对应编号的性别基信息。2. 实现在第几轮舞会结束,对来宾跳舞总次数的统计3. 查询某名男士和某名女士跳舞的总次数。二、实验设计代码如下: Hwuban.h #include#ifndef Hwuban_H#define Hwuban_Hconst bool TURE=1; const bool FAULT=0; class Node/链式堆栈的节点类public:Node();/构造函数重载 1Node(int , int , int ,Node *

2、);/构造函数重载 2 void const get_data(int /取节点数据 void put_data(int , int ,int );/置节点数据 bool put_next(Node *);/置节点的前驱节点域bool put_prior(Node *);/置结点的后继结点域 Node* const get_next()const;/取结点的前驱结点域Node* const get_prior()const;/取结点的后继结点域private: Node *next;Node *prior;int minute; int second; int num;class Queuep

3、ublic:Queue();/堆栈类的构造函数int get_length(void);/取堆栈的长度 bool push(int , int , int );/数据压栈bool pop(int /数据出栈void print(void); int const seach(int );/搜索堆栈数据 protected: Node base;/根节点 Node *top;/顶节点 int length;#endif hanshu1.cpp #include#include Hwuban.husing namespace std;Node:Node() minute=NULL; second=N

4、ULL;num=0; next=NULL;prior=NULL; Node:Node(int x, int y, int z ,Node *p) minute=x;second=y; num=z; next=NULL; prior=p; void const Node:get_data(int &x, int &y, int &z) x=minute;y=second; z=num;void Node:put_data(int x, int y, int z) minute=x; second=y;num=z; bool Node:put_next(Node *n) next=n; retur

5、n TURE; bool Node:put_prior(Node *p) prior=p; return TURE; Node* const Node:get_next() const return next; Node* const Node:get_prior() const return prior; hanshu2.cpp #include#include Hwuban.husing namespace std;Queue:Queue():base()/构造函数, 数据初始化 length=0;top= int Queue:get_length(void)/取长度 if(lengthp

6、ut_next(temp); top=temp; else return FAULT; return TURE; bool Queue:pop(int &minute, int &second, int &num) if(base.get_next()!=NULL) length-; Node *temp=base.get_next(); temp-get_data(minute,second,num); if(temp-get_next()!=NULL) Node *temp1=temp-get_next(); temp1-put_prior( base.put_next(temp1); e

7、lse top= base.put_next(NULL); delete temp; else return FAULT; return TURE; int const Queue:seach(int num)/搜索堆栈数据 Node *temp; int x,y,z;temp=while(temp!=NULL) temp-get_data(x,y,z);if(x=num) return 1;temp=temp-get_next(); return 0;void Queue:print()/打印堆栈 Node *temp;int x,y,z,n=1;temp=base.get_next();

8、if(temp=NULL)coutget_data(x,y,z);if(y=1) coutget_next(); n+; Mainwuban.cpp #include #include#include hanshu1.cpp#include hanshu2.cppusing namespace std; void ring_over(Queue main() int sex,n=0,man_num=0,woman_num=0,number=0,degree5050=0,time=0,lun; Queue man,buffer_man,woman,buffer_woman; do system(

9、cls); do coutsex; while(sex2); if(sex=1) man.push(n+1,sex,NULL); man_num+; n+; if(sex=2) woman.push(n+1,sex,NULL);woman_num+; n+; if(sex=0) system(cls); cout=0system(cls);do coutlun; while(lunman_num; while(man.seach(man_num)=0); do coutwoman_num; while(woman.seach(woman_num)=0); cout 第 man_num 号 男

10、士 和 第 woman_num 号 女 士 共 跳 了 degreeman_numwoman_num次舞endl; return 0; void ring_over(Queue &man, Queue &woman, Queue &buffer_man, Queue &buffer_woman) int n,sex,number;while(buffer_woman.pop(n,sex,number) woman.push(n,sex,number);while(buffer_man.pop(n,sex,number) man.push(n,sex,number);三、调试运行结果:Step1: 输入来宾性别信息;Step2: 统计输出来宾信息;Step3:输入第 3 轮舞会结束;Step4:1.统计输出当第 3 轮舞会结束每个人跳舞总次数;2.查询 5 号男士与 8 号女士合跳的次数。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 学术论文 > 毕业论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号