C ++ Student Information Management System

The system realizes the linked list operation through the design template. The functions include querying student information, adding and deleting student information, and sorting and outputting students according to student numbers and grades. At the beginning of the program, the student information is read from the file and stored in the linked list. After that, various operations are performed on the linked list. When the program is exited, the data in the linked list can be automatically saved to the file.

The whole system includes four parts:

1. Node class

2. Linked list

3. Students

4.main function

The main function mainly includes 3 parts:

1. File reading and writing

2. Operations on linked lists

3. Function selection

First look at the node class:

template<class T> 
class StuNode
{
public:
	StuNode();//初始化
	StuNode<T> *pre;//前一结点
	StuNode<T> *next;//后一结点
	T data;//数据
};

Linked list:

template<class T>
class StuList
{
private:
	StuNode<T> *head;//链表的头结点
	StuNode<T> *tail;//链表的尾结点
	int length;//链表的长度
public:
	StuList();//默认构造函数
	StuList(StuList &list1);//拷贝构造函数
	~StuList();//析构函数
	int size();//返回长度
	void add(T e);//添加结点
	StuNode<T> *get_head();
	StuNode<T> *get_tail();
	void show();//按序输出
	void remove(T index);//移除
	void find(T index);//查找
};

The student attributes can be defined in the student class. In addition, some operators need to be overloaded. You can refer to

Implementation of CString member functions (symbol overloading, dynamic memory)

The file read and write in the main function can refer to

C ++ STL and file processing operation summary

The functions that operate on the linked list are

save_file(list);//保存
add_info(list);//添加
search_info(list);//查询
delete_info(list);//删除
stu_num_out(list);//学号排序
score_out(list);//分数排序

The selection of functional operations can use this structure:

while(1)
{
    cin>>choice;
    switch(choice)
        {
            case  :    break;
            case  :    break;    
            case  :    break;

        }
}

I think there are three more important points

1. The content of a specific class cannot appear in the template class, the template is the template

2. When operating on linked lists, you must pay attention to distinguish between operations on real data or operations on copies of data, otherwise g

3. Note that the name class and other information can be repeated, but the student number must be unique

 

 

Published 125 original articles · Like 31 · Visits 60,000+

Guess you like

Origin blog.csdn.net/Fiverya/article/details/97571394