| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1053 人关注过本帖
标题:[讨论]学生成绩管理(VC++)(已更新)
取消只看楼主 加入收藏
xiaori
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2006-11-22
收藏
 问题点数:0 回复次数:2 
[讨论]学生成绩管理(VC++)(已更新)

//我自己编的学员管理系统 帮我完善一下吧 谢谢
#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编辑过]

搜索更多相关主题的帖子: endl cout 学员 学生 
2006-12-26 13:38
xiaori
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2006-11-22
收藏
得分:0 
能详细的说一下么,或者发出你的解法来看下
[QUOTE]
和我写程序的习惯不一样
我不太理解你的想法
[/QUOTE]

[此贴子已经被作者于2006-12-30 0:48:05编辑过]


希望和大家交朋友,相互帮助,共同提高!
2006-12-27 23:15
xiaori
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2006-11-22
收藏
得分:0 

谢谢大家的参与,我的程序已经更新完毕,希望大家提出宝贵意见
//main函数
#include<iostream.h>
#include <cstdlib>
#include"need.h"

void main()
{
int n;
cout<<endl<<endl;
cout<<"欢迎登陆学员成绩管理系统!!"<<endl<<endl;

cout<<"*****************************************"<<endl<<endl;

cout<<"首先从文件中读取学员信息(学号/姓名/成绩)..."<<endl<<endl;

enregister<stu>();
cout<<"读取完毕"<<endl;

cout<<"-----------------------------------------"<<endl;

cout<<"您能进行的操作如下:"<<endl;
cout<<endl<<endl;
lable:
cout<<"1.打印成绩单"<<endl;
cout<<"2.学员查找"<<endl;
cout<<"3.插入学员成绩"<<endl;
cout<<"4.删除学员"<<endl;
cout<<"5.学员排序"<<endl;
cout<<"0.退出系统"<<endl<<endl;
cout<<"请选择您要进行的操作(数字1-5):";

{
cin>>n;
switch(n)
{
case 1:
cout<<"\n学生成绩单如下"<<endl;
cout<<"-----------------------------------------"<<endl;
print<stu>();
cout<<"-----------------------------------------"<<endl;
cout<<"\n打印完毕,请选择其他操作:"<<endl;
goto lable;


case 2:
findstudent<stu>();
cout<<"查找完毕,请选择其他操作:"<<endl;
goto lable;

case 3:
insert<stu>();
cout<<"-----------------------------------------"<<endl<<endl;
cout<<"修改完毕,请选择其他操作:"<<endl;
goto lable;
case 4:
cout<<"删除学员信息..."<<endl<<endl;
deletestudent<stu>();
cout<<"清理完毕,请选择其他操作:"<<endl;
goto lable;
case 5:
inorder<stu>();
cout<<"排序完毕,请选择其他操作:"<<endl<<endl;
goto lable;
case 0:
cout<<"\n退出本系统,欢迎下次使用,再见!!!"<<endl;
cout<<"*****************************************"<<endl<<endl;
break;
default:
cout<<"输入字母错误,请重新选择:"<<endl;
goto lable;
}
}
}


\\need.h函数
#include<iostream.h>
#include<iomanip.h>
#include<string.h>
#include<fstream.h>
#include"cnode.h"

struct stu
{
char num[30];
char name[30];
double score;
};
CNode<stu>*head=new CNode<stu>();

template<class T>
void enregister(void)
{
ifstream in;
in.open("dengji.txt");

if(in.fail())
{
cerr<<"Error is happen,founction closed!";
exit(-1);
}

CNode<T>*p,*ptr;
ptr=head;
struct stu std;
while(in>>std.num)
{
in>>std.name;
in>>std.score;

p=new CNode<T>(std);
ptr->InsertAfter(p);
ptr=p;
}
in.close();

}


template<class T>

void print(void)
{
CNode<T>*ptr;
struct stu stp;
ptr=head->NextNode();
cout<<"学号"<<" "<<"姓名"<<" "<<"成绩"<<endl;
while(ptr!=head)
{
stp=ptr->data;
cout<<setw(7)<<setiosflags(ios::left)<<stp.num<<" ";
cout<<setw(10)<<setiosflags(ios::left)<<stp.name<<" "<<setw(7)<<setiosflags(ios::left)<<stp.score;
cout<<resetiosflags(ios::left);
ptr=ptr->NextNode();
cout<<endl;
}
}

template<class T>
void findstudent()
{
struct stu stp;
char n[30];
char m='y';
CNode<T>*ptr=head->NextNode();

while(m!='n')
{
cout<<endl;
cout<<"输入需要查找学员的学号:";
cin>>n;
stp=ptr->data;

while(ptr!=head && strcmp(n,stp.num))
{
ptr=ptr->NextNode();
stp=ptr->data;
}

if(ptr==head)
{
cout<<"-----------------------------------------"<<endl;
cout<<"这个学员不存在。"<<endl;
cout<<"-----------------------------------------"<<endl;
}
else
{
cout<<"-----------------------------------------"<<endl;
cout<<stp.num<<" ";
cout<<stp.name<<" "<<stp.score<<endl;
cout<<"-----------------------------------------"<<endl;

}

ptr=head->NextNode();
cout<<"是否继续进行查找(y/n):";
cin>>m;
}
cout<<endl;
}


template<class T>
void insert(void)
{
ofstream out;
out.open("shuchu.txt");
struct stu std;
CNode<T>*ptr,*p,*q;
double n;
char m='y';
ptr=head->NextNode();
q=head;

if(out.fail())
{
cerr<<"Error is happen,founction closed!";
exit(-1);
}

while(m!='n')
{
cout<<"输入需要插入学员的信息..."<<endl;
cout<<"学号:";
cin>>std.num;
cout<<"姓名:";
cin>>std.name;
cout<<"成绩:";
cin>>std.score;
p=new CNode<T>(std);
n=std.score;
while(ptr!=head&&n>ptr->data.score)
{
q=ptr;
ptr=ptr->NextNode();
}

q->InsertAfter(p);
ptr=head->NextNode();
for(p=head->NextNode();p!=head;p=p->NextNode())
{
out<<setw(7)<<setiosflags(ios::left)<<p->data.num;
out<<setw(10)<<setiosflags(ios::left)<<p->data.name;
out<<setw(7)<<setiosflags(ios::left)<<p->data.score<<endl;
out<<resetiosflags(ios::left);
}
out.close();
cout<<"是否继续进行插入(y/n):";
cin>>m;
}
cout<<endl;
}


template<class T>
void deletestudent(void)
{
struct stu ;
CNode<T>*ptr=head->NextNode(),*p;
char n[30]="1";
char m='y';
while(m!='n')
{
p=head;
cout<<"输入要删除学员的学号:";
cin>>n;

while(ptr!=head && strcmp(n,ptr->data.num))
{
p=ptr;
ptr=ptr->NextNode();
}
cout<<"\n-----------------------------------------"<<endl;
if(ptr==head)
cout<<"这个学员不存在。";
else
{
p->DeleteAfter();
cout<<"学员"<<n<<"被删除";
}
cout<<"\n-----------------------------------------"<<endl;

ptr=head->NextNode();
cout<<endl;
cout<<"是否继续进行删除(y/n):";
cin>>m;
}
cout<<endl;
}

template<class T>
void inorder()
{
CNode<T>*ptr,*p;
double m,n;
struct stu st;
for(ptr=head->NextNode();ptr->NextNode()!=head;ptr=ptr->NextNode())
for(p=ptr->NextNode();p!=head;p=p->NextNode())
{
m=ptr->data.score;n=p->data.score;
if(m>n)
{
st=ptr->data;ptr->data=p->data;p->data=st;
}
}
cout<<endl;

}


\\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



\\TXT文件
\\"dengji.txt"
07703 刘志海 67
06404 王帅 57
06005 尹浩 76
70006 刘松杨 88
44007 徐国旺 77
44009 孙晶晶 97
06010 何燕辉 33
04012 车少君 68
44015 刘兆洋 66

更新的内容
1。输入采用重记事本输入
2。优化了结构,程序更加人性化

希望大家能多提出宝贵意见谢谢!!




希望和大家交朋友,相互帮助,共同提高!
2006-12-30 00:44
快速回复:[讨论]学生成绩管理(VC++)(已更新)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027687 second(s), 8 queries.
Copyright©2004-2025, BC-CN.NET, All Rights Reserved