程序指教求助,求各路大侠指教一下,小弟没齿难忘!!!!
小弟大一,做课程设计时遇到一些困难,苦思之后不知道如何改进,希望各路大神给点帮助,在此谢过啦!!
**********************************************************************************************
第五点要求需改进::::
/*功能要求:假设考场有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);
}
******************************************************************************************
望各位大哥帮助,一定满分奉上,谢谢啦