C / C + + Programming Notes: C language score management system! Source sharing of management system based on chain structure

Time:2020-8-13

Recently, many students need to complete their own C language course design because of the requirements of the school, so many people have private letters or added me to chat with me. The most frequently asked question is “student achievement management system“. In fact, when you write too many projects, you will find that: in fact, all kinds of management systems are inseparable from a core – linked list!

Yes, whether you want to write student achievement management system, dormitory management system, train ticket management system, or tourism management system, you need to use our chain structure to write. Today, we will see how to use C language chain management system to write!

This issue of sharing is not to teach you to write this student achievement management system directly, but to use this as the thread to lead to the core of our university project management system chain structure.

Not to say much, we’ll take a look at the core of this article — the core source code of chain structure management system! Let you do: a watch in hand, I have the system!

Source code

Let’s take a look at the code of our SingleList. H file, in fact, is to perform specific operations on our data. Of course, the core is our chain structure

#include 
#include 
#include 
struct MM
{
    char name[20];
    int age;
    int num;
    char addr[20];
};
struct Node
{
    //int data;
    struct MM data;
    struct Node* next;
};
//Everything that involves data needs to be changed
struct Node* createHead()
{
    struct Node* headNode = (struct Node*)malloc(sizeof(struct Node));
    headNode->next = NULL;
    return headNode;
}
struct Node* createNode(struct MM  data)
{
    struct Node * newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = data;
    newNode->next = NULL;
    return newNode;
}
void insertByHead(struct Node* headNode, struct MM data)
{
    struct Node* newNode = createNode(data);
    newNode->next = headNode->next;
    headNode->next = newNode;
}
//Press find to browse
void searchAllInfo(struct Node* headNode, char *name)
{
    struct Node* pMove = headNode->next;
    while (pMove != NULL)
    {
        //!strcmp(pMove-> data.name The condition can be changed to
        //strcmp(pMove->data.name,name)==0
        //!: negative true to false, false to true
        //! - 1 equals 0
        //Non zero representation holds in computer
        if (!strcmp(pMove->data.name, name))
            printf("%s\t%d\t%d\t%s\n", pMove->data.name, pMove->data.age, pMove->data.num, pMove->data.addr);
        pMove = pMove->next;
    }
}
//Search by name
struct Node* searchInfo(struct Node* headNode, char *name)
{
    struct Node* pMove = headNode->next;
    while (pMove != NULL&&strcmp(pMove->data.name, name))
    {
        pMove = pMove->next;
    }
    Return pmove; // return null, not found
}

//By name instead
//Delete a method
void deleteByAppoin(struct Node* headNode, char *name)
{
    struct Node* posNodeLeft = headNode;
    struct Node* posNode = headNode->next;
    //String comparison + data peeling onion
    while (posNode != NULL&&strcmp(posNode->data.name ,name))
    {
        posNodeLeft = posNode;
        posNode = posNodeLeft->next;
    }
    if (posNode == NULL)
    {
        Printf ("the specified location was not found, cannot be deleted);";
    }
    else
    {
        posNodeLeft->next = posNode->next;
        free(posNode);
        posNode = NULL;
        Printf ("deleted successfully!");
    }
}

//Delete all names with the same name
void deleteAll(struct Node* headNode, char *name)
{
    while (searchInfo(headNode, name) != NULL)
    {
        deleteByAppoin(headNode, name);
    }
}

//Change all names with the same name
void modifyALL(struct Node* headNode, char *name,struct MM newInfo)
{
    while (searchInfo(headNode, name) != NULL)
    {
        searchInfo(headNode, name)->data = newInfo;
    }
}

//Printing -- > specific requirements: title
void printList(struct Node* headNode)
{
    struct Node* pMove = headNode->next;
    //Header of table data
    printf("name\tage\tnum\taddr\n");
    while (pMove != NULL)
    {
        //To print the data of the structure, you need to peel the onion
        printf("%s\t%d\t%d\t%s\n", pMove->data.name, pMove->data.age, pMove->data.num, pMove->data.addr);
        pMove = pMove->next;
    }
}

//Bubble sorting of linked list
void BubbleSortList(struct Node*headNode)
{
    //0---size
    for (struct Node* p = headNode->next; p != NULL; p = p->next)
    {
        for (struct Node* q = headNode->next; q->next != NULL; q = q->next)
        {
            if ((q->data.age > q->next->data.age))
            {
                struct MM tempData = q->data;
                q->data = q->next->data;
                q->next->data = tempData;
            }
        }
    }
    printList(headNode);
}

void BubbleSortByName(struct Node*headNode)
{
    //0---size
    for (struct Node* p = headNode->next; p != NULL; p = p->next)
    {
        for (struct Node* q = headNode->next; q->next != NULL; q = q->next)
        {
            if (strcmp(q->data.name, q->next->data.name)>0)
            {
                struct MM tempData = q->data;
                q->data = q->next->data;
                q->next->data = tempData;
            }
        }
    }
    printList(headNode);
}

 

OK, let’s improve our interface:

#define _CRT_SECURE_NO_WARNINGS
#include "singleList.h"

Struct node * list = null; // container for storing data
//1. Menu
void makeMenu()
{
    Printf ("----- [little sister management system] ---- n");
    Printf ("\ \ t0. Exit system \";
    Printf ("\ T1. Enter information / N");
    Printf ("\ T2. Browse system \";
    Printf ("- T3. Modify system \");
    Printf ("\ T4. Find display \");
    Printf ("\ T5. Delete information ');
    Printf ("\ T6. Sort display \");
    printf("-------------------------------------\n");
}
//2. Key interaction
void keyDown()
{
    int userKey = 0;
    Struct mm tempdata; // stores user data
    struct Node* posNode = NULL;
    scanf("%d", &userKey);
    switch (userKey)
    {
    case 0:
        Printf ("normal exit, welcome to visit next time);";
        system("pause");
        exit(0);
        break;
    case 1:
        //Transfer parameters for the current function
        //Add global variables
        Printf ("please input information: (name, age, num, addr):");
        scanf("%s%d%d%s", tempData.name, &tempData.age, &tempData.num, tempData.addr);
        insertByHead(list,tempData);
        break;
    case 2:
        printList(list);
        break;
    Case 3: // modify -- > Modify job
        Printf ("please enter the name to be modified)";
        scanf("%s", tempData.name);
        //The input information is stored in the temporary variable tempinfo
        //Loop to modify: know posnode = = null position
        posNode = searchInfo(list, tempData.name);
        if (posNode == NULL)
        {
            Printf ("the specified location was not found, unable to modify! "";
        }
        else
        {
            Printf ("please enter new information: (name, age, num, addr):");
            scanf("%s%d%d%s", posNode->data.name, &posNode->data.age, &posNode->data.num, posNode->data.addr);
            //posNode->data=tempInfo;
            Printf ("modified successfully!");
        }
        break;
    Case 4: // find
        Printf ("please enter the name you want to search for)";
        scanf("%s", tempData.name);
        searchAllInfo(list, tempData.name);
        break;
    Case 5: // delete
        Printf ("please enter the name to be deleted)";
        scanf("%s", tempData.name);
        deleteByAppoin(list, tempData.name);
        break;
    case 6:
        BubbleSortList(list);
        break;        //
    default:
        Printf ("input error! Re input)!";
        break;
    }
}
int main()
{
    List = createhead(); // 1. Create container
    while (1)
    {
        makeMenu();
        keyDown();
        system("pause");
        system("cls");
    }
    system("pause");
    return 0;
}

OK, that’s all for this issue! Hope to be helpful to you, I hope you can complete your own management system according to the things shared in this article~

In fact, as a programming learner, it’s very important to have a learning atmosphere and a communication circle. Here, I recommend a C language c + + communication Q group 1108152000. No matter you are Xiaobai or a career change person, welcome to settle in and communicate with each other.

WeChat official account: C language programming learning base, learning C / C + + programming knowledge, welcome to pay attention~

Recommended Today

6.0 DOM API

DOM:Document/Object/Model DOM is a tree with nodes, which are divided into document (HTML), element (element), text (text), comment (comment) and others DOMThe main function is: throughConstructorPutnodeBecomeobjectBy calling theAPI To manipulate objects     ——————————————————————————————————————————————————————-   Interface of node 1. Properties nodeName,nodeType,nodeValue, childNodes,parentNode,parentElement firstChild,lastChild,nextSibling,previousSibling InnerText, textcontent outerText,ownerDocument ——————————————————————————————————————————————————————————— Some problems needing attention document.body.childNodes   Get child node(will get […]