c++ stl list实现简单的学生信息管理系统(一)

2014-11-24 08:48:20 · 作者: · 浏览: 0
c++ stl list实现简单的学生信息管理系统
问题描述:
已知有20个学生记录(包括学号、姓名、成绩)的文件student.dat。要求 编程序实现查询、排序、插入、删除诸功能。
系统的基本功能:
A.要求显示如下界面
****************************************
1--------------查询
2--------------排序
3--------------插入
4--------------删除
****************************************
通过选择1-4来确定要做哪一个操作。
B.若选1,则出现如下界面
****************************************
1.1----------按学号查询
1.2----------按姓名查询
1.3----------按成绩查询
****************************************
通过选择1.1-1.3来确定要做哪一个操作,其中:按学号查询用二分法实现;按姓名查询用顺序法实现;按成绩查询实现查询成绩小于m分的学生;找到该生将学生记录输出到屏幕,若查无此人,输出相关信息。
C.若选2,则按成绩从大到小排序,姓名,学号顺序也随之调整。
D.若选3,将一个新学生记录按学号顺序插入,并把结果保存到文件student.dat中。
E.若选4,删除指定学生的记录,并把结果保存到文件student.dat中。
F.以上各个功能均编写成子函数,由主函数调用实现。
c++代码如下:
[cpp]
#include <iostream>
#include <fstream>
#include
#include <cmath>
#include .h>
#define MAX_STU 100//读入学生的最大数目
/*
*郑海波 blog.csdn.net/nuptboyzhb/
*email:zhb931706659@126.com
*/
using namespace std;
class Student
{
public:
char * name;
char *ID;
int grade;
Student()
{
name = new char[strlen("Anonymous-----") + 1];
ID = new char[strlen("NoIdInput------") + 1];
grade = 0;
}
Student(char * pName,char * pID, int pgrade)
:grade(pgrade)
{
name = new char[strlen(pName) + 1];
strcpy(name, pName);
ID = new char[strlen(pID) + 1];
strcpy(ID, pID);
}
Student(const Student& rhs)
:grade(rhs.grade)
{
name = new char[strlen(rhs.name) + 1];
strcpy(name, rhs.name);
ID = new char[strlen(rhs.ID) + 1];
strcpy(ID, rhs.ID);
}
Student& operator=(const Student& rhs)
{
name = new char[strlen(rhs.name) + 1];
strcpy(name, rhs.name);
ID = new char[strlen(rhs.ID) + 1];
strcpy(ID, rhs.ID);
grade = rhs.grade;
return *this;
}
// overload the == operator
// for sorting purposes, we consider that two Student objects are "equal"
// if they have the same grade
bool operator==(const Student& rhs) const
{
return (grade == rhs.grade) true : false;
}
// overload the < operator
// for sorting purposes, we consider that a Student object is "less than" another
// if it's grade is less than the other object's grade
bool operator<(const Student& rhs) const
{
return (grade < rhs.grade) true : false;
}
// overload the > operator
// for sorting purposes, we consider that a Student object is "greater than" another
// if it's grade is greater than the other object's grade
bool operator>(const Student& rhs) const
{
return (grade > rhs.grade) true : false;
}
// 显示学生的信息
void print()
{
cout << name <<" " <
}
//构造函数
~Student()
{
delete []name;
delete []ID;
}
};
list lst;//学生链表,用于存放学生数据
void print(list lst, char * name)//输入链表中所有的学生
{
list::iterator it;
cout << name << ":" << endl;
for(it = lst.begin(); it != lst.end(); ++it)
it->print();
cout << endl;
}
void screenA()//显示屏幕操作A
{
cout<<"****************************************"<
cout<<" 1--------------查询"<
cout<<" 2--------------排序"<
cout<<" 3--------------插入"<
cout<<" 4--------------删除"<
cout<<" 5--------------显示"<
cout<<" 6--------------保存"<
cout<<" 7--------------清屏"<
cout<<"****************************************"<
}
void screenB()//显示屏幕查询
{
system("cls");
cout<<"****************************************"<
cout<<" 1----------按学号查询"<