大家好,我是作者:隐匿269,今天我带来的是用链表制作教务管理系统。教务管理系统呢,其实就是一个个链表互相指向,所组成的链表网。我们只需要创建两个链表就行了,一个是具体数据,一个指向另一个链表。
#include"Link.h"
#include <iostream>
#include <string>
#include<math.h>
using std::string;
using std::cin;
using std::cout;
using std::endl;
//创建链表
L*init_link()
{
L*temp = new L;
//判断
if (temp == NULL)
{
cout << "空间申请失败!" << endl;
return 0;
}
temp->head = NULL;
temp->next = NULL;
return temp;
}
//创建节点
S*init_student()
{
S*temp = new S;
//判断
if (temp == NULL)
{
cout << "空间申请失败!" << endl;
return 0;
}
temp->name = "";
temp->num = 0;
temp->age = 0;
temp->language = 0;
temp->mathematics = 0;
temp->English = 0;
temp->Physics = 0;
temp->Chemistry = 0;
temp->biology = 0;
temp->Politics = 0;
temp->history = 0;
temp->Sports = 0;
temp->Total_score = 0;
temp->average = 0;
temp->next = NULL;
return temp;
}
//创建临时节点,
S*init_student(string name1, int num, int age, double language, double mathematics, double English, double Physics, double Chemistry, double biology, double Politics, double history, double Sports)
{
S*temp = init_student();
temp->name = name1;
temp->num = num;
temp->age = age;
temp->language =language;
temp->mathematics = mathematics;
temp->English = English;
temp->Physics = Physics;
temp->Chemistry = Chemistry;
temp->biology = biology;
temp->Politics = Politics;
temp->history = history;
temp->Sports = Sports;
temp->Total_score = temp->language + temp->mathematics + temp->English + temp->Physics + temp->Chemistry + temp->biology + temp->Politics + temp->history + temp->Sports;
temp->average = temp->Total_score / 9;
return temp;
}
//插入节点(尾插)
void Add_head(L*a,string name1, int num, int age, double language, double mathematics, double English, double Physics, double Chemistry, double biology, double Politics, double history, double Sports)
{
//判断
if (a == NULL)
{
cout << "插入失败!" << endl;
return;
}
else if (a->head == NULL)
{
a->head = new S;
//创建临时节点
S*temp = init_student(name1,num, age,language,mathematics,English,Physics,Chemistry,biology,Politics,history,Sports);
a->head->next = temp;
}
else
{//创建临时节点
S*temp = init_student(name1, num, age, language, mathematics, English, Physics, Che