程序指教求助,求各路大侠指教一下,小弟没齿难忘!!!!

yaoxinchao 2011-04-27 01:29:09
小弟大一,做课程设计时遇到一些困难,苦思之后不知道如何改进,希望各路大神给点帮助,在此谢过啦!!
**********************************************************************************************
第五点要求需改进::::
/*功能要求:假设考场有8×8的座位,本程序可自动对考生进行座位安排,每当一个考生进入考场就为他安排座位。
循环显示如下图所示的主菜单:
选择1,为新来的考生安排座位,其方法是:用户输入准考证号和姓名,然后系统随机产生该考生座位的行号和列号,
要求做到一个考生只有一个座位,而且在已有考生的位置上不能再安排新的考生;
选择2,取消某人考场座位;
选择3,要求输入座位的行号和列号,然后显示该座位学生的信息;
选择4,要求输入某考生准考证号,然后显示该学生的座位;
选择5,显示考场座次表,要求再每个座位对应的行列上显示该考生的准考证号。*/
*******************************************************************************************88
选择五要求已经安排学生的按要求打印显示,没有安排学生的显示座位为空(即打印出为行 列 考生号都为*****),8*8矩阵形式打印
*****************************************************
小弟写的代码如下:#include<iostream>
#include<cstdlib>
#include<string>
#include<fstream>
#include<iomanip>
#include<windows.h>
using namespace std;
struct student
{
string name;//学生姓名
string num;//学生考号
int row;//座位行号
int line;//座位列号
struct student *link;//存放下一结点的指针
};
//*****************************************************

typedef student* Nodeptr;

//***************************************************
void out_file(Nodeptr& head);
void print(Nodeptr here);
void print_news(Nodeptr head);
void ins_file();
void head_insert(Nodeptr head);
void menu();
Nodeptr search_rl(Nodeptr head,int& r,int& l);
Nodeptr search_name(Nodeptr head,string& name);
void my_set(Nodeptr head);//设置考生座位
void my_abolish(Nodeptr head);//取消考生座位
void show_news(Nodeptr head);//输入座位的行号和列号,然后显示该座位学生的信息
void my_search(Nodeptr head);//查找考生座位
void show_seat(Nodeptr head);//显示考场座次表
//***************************************************
int main()
{
system("color 70");

int choice;
char ans;

Nodeptr head=NULL;
head=new struct student;//创建头结点
head->link=NULL;


cout<<"***排考场座位系统***"<<endl;
do
{

menu();
cout<<"请输入选项:"<<endl;
cin>>choice;
switch(choice)
{
case 1:
my_set(head);
break;
case 2:
my_abolish(head);
break;
case 3:
show_news(head);
break;
case 4:
my_search(head);
break;
case 5:
show_seat( head);
break;
case 0:exit(0);
default:cout<<"非法输入!"<<endl;
}

cout<<"是否重新选择?(Y/N)"<<endl;
cin>>ans;

}while(ans=='Y'||ans=='y');
return 0;
}
//**********************************************************
void menu() //显示菜单界面
{

cout<<"******* 考试排座位系统 ********"<<endl;
cout<<"*********1--设定考场座位 ********"<<endl;
cout<<"*********2--取消考场座位 ********"<<endl;
cout<<"*********3--显示座位考生信息********"<<endl;
cout<<"*********4--查找学生座位 ********"<<endl;
cout<<"*********5--显示考场座次表 ********"<<endl;
cout<<"*********0--退出系统 ********"<<endl;
}
void my_set(Nodeptr head)//设置考生座位
{
head_insert(head);
}
void my_abolish(Nodeptr head)//取消考生座位
{
string name;
Nodeptr p;//此处为什么不需要再head定义????
cout<<"输入需要取消座位的考生姓名:"<<endl;

cin>>name;
p=search_name(head,name);/*体会:要想删除第n个节点,必须要找到第n-1个节点

取消座位就是删除这个学生的所有信息,也就是删除这个学生的节点*/


if(p==NULL)
{
cout<<"没有这个学生的信息!"<<endl;
}
else
{

Nodeptr temp; //执行删除操作
temp=p->link;
p->link=temp->link;
cout<<"删除成功!"<<endl;
}

}
void my_search(Nodeptr head)//要求输入某考生姓名,然后显示该学生的座位
{
string name;
Nodeptr p;

cout<<"输入考生姓名:"<<endl;

cin>>name;
p=head;
while( p->name !=name&&p->link !=NULL)
p=p->link;
cout<<"行号:"<<endl;
cout<<p->row<<endl;
cout<<"列号:"<<endl;
cout<<p->line<<endl;
}
void show_news(Nodeptr head)//输入座位的行号和列号,然后显示该座位学生的信息
{
int r,l;
Nodeptr p;
cout<<"输入考生行号和列号:"<<endl;
cin>>r>>l;
p=search_rl(head,r,l);//{用链表查找并输出考生信息}*****
cout<<"考生姓名:"<<endl;
cout<<p->name<<endl;
cout<<"考生学号:"<<endl;
cout<<p->num<<endl;
}
void show_seat(Nodeptr head)//显示考场座位
{
Nodeptr here;
here=head->link;
while(here!=NULL)
{
cout<<"**************************"<<endl;
cout<<"姓名:"<<here->name<<endl;
cout<<"学号:"<<here->num<<endl;

cout<<"行号:"<<here->row<<endl;
cout<<"列号:"<<here->line<<endl;

here=here->link;
}
}
Nodeptr search_rl(Nodeptr head,int& r,int& l)
{
Nodeptr here;
here=head;
if(here==NULL)
{
return NULL;
}
else
{
while((here->row !=r||here->line !=l)&&here->link !=NULL)
here=here->link;
if(here->line==l&&here->row==r)
return here;
else
return NULL;
}
}
void head_insert(Nodeptr head) //建立链表并希望按照需要连续建立链表节点,我想在此创建头结点并可继续增加节点
{
char ans;


Nodeptr head1=NULL;

Nodeptr p=NULL;
string name;
string number;

head1=new struct student;

cout<<"输入学生姓名:"<<endl;

cin>>name;
head1->name=name;
cout<<"请输入考生学号:"<<endl;
cin>>number;

head1->num=number;
cout<<"你输入的考生信息:"<<endl;
cout<<"姓名:"<<head1->name<<endl
<<"学号:"<<head1->num<<endl;
cout<<"产生行号:"<<endl;

//srand(8);


head1->row=rand()%8+1;
cout<<head1->row<<endl;

cout<<"产生列号:"<<endl;
head1->line=rand()%8+1;
cout<<head1->line<<endl;

/////插入新的节点////////
Nodeptr temp_ptr=NULL;
temp_ptr=head->link;
head->link=head1;
head1->link=temp_ptr;


cout<<"是否停止输入?(Y/N)"<<endl;
cin>>ans;
while(ans=='N'||ans=='n')
{

Nodeptr head1=new struct student;

cout<<"输入学生姓名:"<<endl;

cin>>name;
head1->name=name;
cout<<"请输入考生学号:"<<endl;
cin>>number;


head1->num=number;
cout<<"你输入的考生信息:"<<endl;
cout<<"姓名:"<<head1->name<<endl
<<"学号:"<<head1->num<<endl;
cout<<"产生行号:"<<endl;

//srand(8);//*******

head1->row=rand()%8+1;
cout<<head1->row<<endl;
cout<<"产生列号:"<<endl;
head1->line=rand()%8+1;
cout<<head1->line<<endl;

/////插入新的节点////////
Nodeptr temp_ptr=NULL;
temp_ptr=head->link;
head->link=head1;
head1->link=temp_ptr;


cout<<"是否停止输入?(Y/N)"<<endl;
cin>>ans;
}
}


Nodeptr search_name(Nodeptr head,string& name)
{
Nodeptr here=head;
if(here==NULL)
{
return NULL;
}
else
{
while(here->link->name!=name&&here->link !=NULL)
here=here->link;
}
return here;
}
void print(Nodeptr here)//打印考场信息
{
Nodeptr p=NULL;
p=here->link;
do
{
cout<<"座位行号 座位列号 考生考号 考生姓名:"<<endl;
cout<<here->row<<setw(4)<<here->line<<setw(4)
<<here->name<<setw(4)<<here->name<<endl;
here=here->link;
}while(here !=NULL);
}
******************************************************************************************
望各位大哥帮助,一定满分奉上,谢谢啦
...全文
218 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
eye_119_eye 2011-04-27
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 yaoxinchao 的回复:]
引用 4 楼 toadzw 的回复:

基本上一个队列存一下结构,再以一个flag标识存储一下,其位置上有没有人就OK了;或者做高级一点散列玩玩,也就OK了

就是现在积累太少,不知道怎么做啊,老师说不不达标,不让过,焦急等待中。。。。。
望高手给点基本代码或算法
[/Quote]
老师也太那个了 毕竟才大一
yaoxinchao 2011-04-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 toadzw 的回复:]

基本上一个队列存一下结构,再以一个flag标识存储一下,其位置上有没有人就OK了;或者做高级一点散列玩玩,也就OK了
[/Quote]
就是现在积累太少,不知道怎么做啊,老师说不不达标,不让过,焦急等待中。。。。。
望高手给点基本代码或算法
toadzw 2011-04-27
  • 打赏
  • 举报
回复
基本上一个队列存一下结构,再以一个flag标识存储一下,其位置上有没有人就OK了;或者做高级一点散列玩玩,也就OK了
davidli1208 2011-04-27
  • 打赏
  • 举报
回复
大一就做真么难的题目呀
panasonic0804 2011-04-27
  • 打赏
  • 举报
回复
很明显第5点的要求是按照行或者列(你自选)方式输出,而楼主的显示是按照学生顺序输出的。

64,642

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧