当前位置:编程学习 > C/C++ >>

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

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 <<span class="GRcorrect" id="GRmark_5fc8fc187032ce782ecac928f035d97f41d26a88_iostream:0" grphrase="5fc8fc187032ce782ecac928f035d97f41d26a88" grtype="null">iostream</span>>  
#include <<span class="GRcorrect" id="GRmark_c85475ec45e79bf31944ddd7b9056330f5830822_fstream:0" grphrase="c85475ec45e79bf31944ddd7b9056330f5830822" grtype="null">fstream</span>>  
#include <list>  
#include <<span class="GRcorrect" id="GRmark_4b0a33f65e13f1f129d6d1e51548c3ab91888b26_cmath:0" grphrase="4b0a33f65e13f1f129d6d1e51548c3ab91888b26" grtype="null">cmath</span>>  
#include <string<span class="GRcorrect" id="GRmark_fcc4c679808977b2a91b05c30d2e55360b066247_.:0" grphrase="fcc4c679808977b2a91b05c30d2e55360b066247" grtype="null">.</span>h>  
#define MAX_STU 100//读入学生的最大数目  
/* 
 *郑海波 blog.csdn.net/nuptboyzhb/ 
 *email:zhb931706659@126.com 
 */  
<span class="GRcorrect" id="GRmark_d101e8caae62915e3f88a5fb668c63e9f9483281_using:0" grphrase="d101e8caae62915e3f88a5fb668c63e9f9483281" grtype="null">using</span> namespace <span class="GRcorrect" id="GRmark_d101e8caae62915e3f88a5fb668c63e9f9483281_std:1" grphrase="d101e8caae62915e3f88a5fb668c63e9f9483281" grtype="null">std</span>;  
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 <<" " <<ID << " " << grade << endl;  
    }  
    //构造函数  
    ~Student()  
    {  
        delete []name;  
        delete []ID;  
    }  
};  
list<Student> lst;//学生链表,用于存放学生数据  
void print(list<Student> lst, char * name)//输入链表中所有的学生  
{  
    list<Student>::iterator it;  
    cout << name << ":" << endl;  
      
    for(it = lst.begin(); it != lst.end(); ++it)  
        it->print();  
    cout << endl;  
}  
void screenA()//显示屏幕操作A  
{  
    cout<<"**************
补充:软件开发 , C++ ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,