//我自己编的学员管理系统 帮我完善一下吧 谢谢
#include<iostream.h>
#include <cstdlib>
#include"need.h"
void main()
{
int n;
cout<<"欢迎登陆学员成绩管理系统!!"<<endl;
cout<<"您能进行的操作如下:"<<endl;
cout<<endl<<endl;
cout<<"1.学员登记(学号/姓名/成绩)"<<endl;
cout<<"2.学员查找"<<endl;
cout<<"3.打印成绩单"<<endl;
cout<<"4.插入学员成绩"<<endl;
cout<<"5.删除学员"<<endl;
cout<<"6.学员排序"<<endl;
cout<<"7.退出系统"<<endl<<endl;
cout<<"请选择您要进行的操作(数字1-7):";
lable:
{
cin>>n;
switch(n)
{
case 1:
cout<<"开始登记学员信息..."<<endl;
enregister<stu>();
cout<<"登记完毕,请选择其他操作:";
goto lable;
case 2:
cout<<"开始查找所需学员..."<<endl;
findstudent<stu>();
cout<<"查找完毕,请选择其他操作:";
goto lable;
case 3:
cout<<"打印学生的成绩单..."<<endl;
print<stu>();
cout<<"修改完毕,请选择其他操作:";
goto lable;
case 4:
cout<<"进行修改,插入学员..."<<endl;
insert<stu>();
cout<<"修改完毕,请选择其他操作:";
goto lable;
case 5:
cout<<"清理已经登陆的学员信息..."<<endl;
deletestudent<stu>();
cout<<"清理完毕,请选择其他操作:";
goto lable;
case 6:
cout<<"将已登记的学员排序,请稍候..."<<endl;
inorder<stu>();
cout<<"排序完毕,请选择其他操作:";
goto lable;
case 7:
system("pause");
cout<<"退出本系统,欢迎下次使用,再见!!!"<<endl;
break;
default:
cout<<"输入字母错误,请重新输入:";
goto lable;
}
}
}
//头文件在这里 共两个 "cnode.h"和"need.h"
//cnode.h
#ifndef CIRCULAR_NODE_CLASS
#define CIRCULAR_NODE_CLASS
template <class T>
class CNode
{
private:
// circular link to the next node
CNode<T> *next;
public:
// data is public
T data;
// constructors
CNode(void);
CNode (const T& item);
// list modification methods
void InsertAfter(CNode<T> *p);
CNode<T> *DeleteAfter(void);
// obtain the address of the next node
CNode<T> *NextNode(void) const;
};
// constructor that creates an empty list and
// leaves the data uninitialized. use for header
template <class T>
CNode<T>::CNode(void)
{
// initialize the node so it points to itself
next = this;
}
// constructor that creates an empty list and initializes data
template <class T>
CNode<T>::CNode(const T& item)
{
// set node to point to itself and initialize data
next = this;
data = item;
}
// return pointer to the next node
template <class T>
CNode<T> *CNode<T>::NextNode(void) const
{
return next;
}
// insert a node p after the current one
template <class T>
void CNode<T>::InsertAfter(CNode<T> *p)
{
// p points to successor of the current node, and current node
// points to p.
p->next = next;
next = p;
}
// delete the node following current and return its address
template <class T>
CNode<T> *CNode<T>::DeleteAfter(void)
{
// save address of node to be deleted
CNode<T> *tempPtr = next;
// if next is the address of current object (this), we are
// pointing to ourself. We don't delete ourself! return NULL
if (next == this)
return NULL;
// current node points to successor of tempPtr.
next = tempPtr->next;
// return the pointer to the unlinked node
return tempPtr;
}
#endif // CIRCULAR_NODE_CLASS
//need.h
#include<iostream.h>
//#include<fstream.h>
#include"cnode.h"
struct stu
{
double num;
char name;
int score;
}std;
CNode<stu>*head=new CNode<stu>();
template<class T>
void enregister(void) //建立一个data域是stu类型的循环链表
{
CNode<T>*p,*ptr; //存储打入的学员信息
ptr=head;
struct stu std;
// int n=1;
while(1)
{
cout<<"请输入学员的学号/姓名/成绩:"<<endl;
cin>>std.num>>std.name>>std.score;
// ifstream in("data.txt");
if(std.num==0) break;
p=new CNode<T>(std);
if(head->NextNode()==head)
{
head->InsertAfter(p);
ptr=p;
}
else
{
ptr->InsertAfter(p);
ptr=p;
}
}
}
template<class T>
void print(void)
{
CNode<T>*ptr;
struct stu stp;
ptr=head->NextNode();
/* if(ptr==head)
{
cout<<"现在没有学员登记,请先进行学员登记"<<endl;
enregister();
}
else*/
while(ptr!=head)
{
stp=ptr->data;
cout<<stp.num<<" ";
cout<<stp.name<<" "<<stp.score<<" ";
ptr=ptr->NextNode();
cout<<endl;
}
}
template<class T>
void findstudent()
{
struct stu stp,st;
double n=1,m;
CNode<T>*ptr=head->NextNode();
st=stp=ptr->data;
m=stp.num;
while(n!=0)
{
cout<<"请输入需要查找的学员的学号(输入0结束):";
cin>>n;
while(ptr!=head && n!=m)
{
ptr=ptr->NextNode();
st=ptr->data;
m=st.num;
}
if(ptr==head)
cout<<"这个学员不存在。"<<endl;
else
{
cout<<st.num<<" ";
cout<<st.name<<" "<<st.score<<" ";
}
ptr=head->NextNode();
cout<<endl;
}
}
template<class T>
void insert(void)
{
// struct stu std;
CNode<T>*ptr,*p;
int n=1;
ptr=head->NextNode();
while(n!=0)
{
while(ptr->NextNode()!=head)
ptr=ptr->NextNode();
cout<<"输入需要插入学员的信息:"<<endl;
cin>>std.num>>std.name>>std.score;
p=new CNode<T>(std);
ptr->InsertAfter(p);
cout<<"输入结束,输入0结束,其他数字继续。。。"<<endl;
cin>>n;
}
}
template<class T>
void deletestudent(void)
{
struct stu st;
CNode<T>*ptr=head->NextNode(),*p;
double n=1,m;
while(n!=0)
{
p=head;
st=ptr->data;
m=st.num;
cout<<"请输入要删除的学员的学号:(输0结束)";
cin>>n;
while(ptr!=head && n!=m)
{
p=ptr;
ptr=ptr->NextNode();
st=ptr->data;
m=st.num;
}
if(ptr==head)
{
cout<<"这个学员不存在。"<<endl;
break;
}
else
p->DeleteAfter();
ptr=head->NextNode();
cout<<endl;
}
}
template<class T>
void inorder()
{
CNode<T>*ptr,*p;
double m,n;
struct stu str,st,stp;
for(ptr=head->NextNode();ptr->NextNode()!=head;ptr=ptr->NextNode())
for(p=ptr->NextNode();p!=head;p=p->NextNode())
{
str=ptr->data;stp=p->data;
m=str.score;n=stp.score;
if(m>n)
{
st=str;str=stp;stp=st;
}
}
}
求教:
1。登记函数中只能输入1w1的信息,输入0o0结束,怎样修改结构体内的类型能输入0444025+汉字+数字的结构
2。排序有点问题
3。不太人性化,
麻烦大家能抽空看下,给我提出些意见,谢谢!!!
[此贴子已经被作者于2006-12-30 0:51:18编辑过]