Student Management System (c + +, console, file read, name sorting) __c++

Source: Internet
Author: User

This is a C + + written console program, the use of simple menu to achieve student information management.

The sketch shows as follows:
Menu bar:

Query data:

Modify Data:

Print Data:

The following are the results of some actions that have been added to some student information:




In addition to the features shown above, you can also save all student information to a TXT file, or read the student information in a file, and of course, the files you read need to be arranged in the format of the saved file.

In the beginning I think the Chinese sort is the most difficult, after a lot of online data browsing, finally found a feasible way. You can Baidu Pinyin.c understand this sort of Chinese method, this file contains an array of char types, and someone stores the first letter of all Chinese characters from small to large in the Unicode code to this array, which means we only need to get the Unicode code of the Chinese character to get its first word. Mother, you use the sort algorithm to sort the numeric values (ASCII codes) that the letters convert to. Since we usually use the saved names are string string type, we need to get Unicode code, but also need to convert it to the wstring type before we can get, here I directly found a function to convert it.
Let's take a look at the source code: I was implemented using a single linked list, not only implemented a list class, the class also contains a simple structure-node. There are always three documents
⒈linked_list.h

#ifndef linked_list #define Linked_list #include <iostream> #include <iomanip> #include <string> #
Include <cstdlib> #include <fstream> using namespace std; The starting position of Chinese characters in the #define Hanzi_start 19968//unicode code is 19968 #define HANZI_COUNT 20902 Code contains 20,902 Chinese characters,  So large an array is needed to store all their initials wstring string_to_wstring (const String &s);  Converts a string to wstring type int get_first_pinyin (string name);  Extracts the first letter of Chinese characters from an array struct node//Save the Student information by one of the nodes {string Name; name int student_id; School number string Gender; sex int age; Age string Class;  Class string Health_status;  Health condition Node *next_student;
        Pointer node ()//default constructor to the next node that implements the initialization of the member {Name = "NULL";
        student_id = NULL;
        Gender = "NULL";
        age = NULL;
        Class = "NULL";
        Health_status = "NULL";
    Next_student = NULL;
        Node (string name)//constructor with name to create student information {name = name;
   cout << "Please enter the" <<name<< "School Number:";     Cin >> student_id;
        cout << "Please enter" << name << "Sex:";      
        Cin >> Gender;
        cout << "Please enter the" << name << "Age:";     
        CIN >> age;
        cout << "Please enter" << name << "class:";
        CIN >>Class;
        cout << "Please enter" << name << "health status:";
        Cin >> Health_status;
    Next_student = NULL; Node (String name,int student_id,string gender,int age,string class,string health_status) {//Incoming all information, create a student letter directly
        Interest name = name;
        student_id = student_id;
        Gender = Gender;
        Age = age;
        This->class = Class;
        Health_status = Health_status;
    Next_student = NULL;
}
};  Class Linked_list//single linked list class {int student_count;   Number of students Node *head_point; Head node, do not store student information public:static bool is_previous;
    In the query, delete or modify operations, we need to get a pointer to the node we want to operate, if it is a query or modify, we need to point to the current students; if it is deleted, we need to point to the previous student of the deleted student.
 Linked_list ()   {Node *p = new node;//When we create a new single linked list object, we should have created a header node for it and completed the initialization of the class's members.
        This->head_point =p;
        Head_point->next_student= NULL;
    Student_count = 0;  ~linked_list ()//destructor {} linked_list (const linked_list &list); Copy constructor linked_list& operator= (const linked_list &list);  Assignment constructor void Clear_linked_list ();  Destroy the linked list void Print_student_details (string name); Use student name to print student information void print_student_details (int studeng_id);  Use student number to print student information node* find_name (string Name); Use the student name to find the student and return the pointer to the student node* find_student_id (int studeng_id); Use the student number to find the student and return the pointer to the student, void Edit_student ();  The function can modify the student information by finding the name of the student to modify the void Student_id_sort (),//number size to sort, using the bubble sort method void Student_name_sort ();  Sort the last names of each name void Delete_student ();  Delete Student information, use name to find and delete void Print_every_student ();
    Print all students ' information//These two saved and read functions are not added to the menu bar, these two functions after I wrote this class after a long time to write, also bother to change the menu bar, but I tested is feasible. void Write_every_student_txt ()//Save all student information to the text{ofstream fout ("h:\\visual Studio 2015\\my projects\\linked_list\\linked_list\\student.txt");
        Files saved to the file directory, if not, will create the file, if any, will empty all the contents of the original file Node *p = Head_point; if (!fout.is_open ())//If the file creation fails, returns no subsequent operations {cout << "file creation failed ...
                ";
        Return  Fout << "name" << "School Number" << "Sex" << "Age" << "class" <<
        "Health status" << Endl;
            for (int i = 1; I <= student_count i++) {//Use left alignment, fill character control formatted output to file P = p->next_student;
            Fout << left << setw () << Setfill (') << p->name;
            Fout << left << setw (a) << Setfill (') << p->student_id;
            Fout << left << setw (8) << Setfill (") << p->gender;
            Fout << left << setw (a) << Setfill (') << p->age; Fout << left << setw () << Setfill (') << p->class;
        Fout << left << setw (km) << setfill (') << p->health_status << Endl; } fout.close (); Close this file stream} void Read_every_student_txt ()//Read student information from file {ifstream fin ("h:\\visual Studio 2015\\my proj
        Ects\\linked_list\\linked_list\\student.txt "); if (!fin.is_open ()) {cout << file open failed ...
            ";
        Return  
        Node *p = Head_point;  Char status[80];  The first line in the file displays some information by default, so this line of information should be read out and discarded Fin.getline (status,100);
        Reads 100 characters to getline string Name;
        int student_id;
        String Gender;
        int age;
        String Class;
        String Health_status;  while (Fin.good ())//good () gets whether the file is in a good state, or if the type mismatch returns false {///Add the information in the file to the list fin >> Name >> student_id >> Gender >> age >> Class >> Health_staTus    
        This->add_student (Name, student_id, Gender, age, Class, health_status);  } fin.close ();  Closes the file stream} void Add_student (string name); Add a student, using the node's constructor to add a student void Add_student (string name, int student_id, string gender, int age, String Class, String he
    Alth_status);  Enter all information directly to create an int show_print_menu ();   Display print menu int show_edit_menu ();  Display Edit menu int show_query_menu ();    Display Query menu int show_main_menu ();

Show main Menu}; #endif

⒉linked_list.cpp

 #include "stdafx.h" #include "linked_list.h" bool linked_list::is_previous = true;
    The default is to point to the previous student's pointer void Linked_list::clear_linked_list () {Node *p, *q;
    p = this->head_point;
        for (int i = 1; I <= this->student_count; i++) {//start destroy from scratch node, save the next node of the destroy node each time to destroy the node q = p;
        p = p->next_student; 
    Delete q; } delete p;
The number of nodes to be created should be the number of head nodes plus the number of students, so the last thing you need to destroy is the last student information this->student_count = 0; } linked_list::linked_list (const linked_list &list) {//Implement deep copy of two linked lists Node *q = list.
    Head_point; Linked_list *p = new Linked_list;
    Create a new linked list node *k = node; for (int i = 1; I <= list. Student_count;
        i++) {q = q->next_student;
    P->add_student (Q->name, q->student_id, Q->gender, Q->age, Q->class, q->Health_Status);
    } void Linked_list::P rint_student_details (string name) {Node *p = find_name (name); if (p->name!= "NULL") {cout << "name" <<
        "Student number" << "gender" << "Age" << "class" << "health status" << Endl;
        cout << left << setw () << Setfill (') << p->name;
        cout << left << setw (a) << Setfill (') << p->student_id;
        cout << left << setw (8) << Setfill (") << p->gender;
        cout << left << setw (a) << Setfill (') << p->age;
        cout << left << setw () << Setfill (') << p->class;

    cout << left << setw (km) << setfill (') << p->health_status << Endl;
    } void Linked_list::P rint_student_details (int studeng_id) {Node *p = find_student_id (studeng_id);  if (p->name!= "NULL") {cout << "name" << "School Number" << "gender" << "age"
        << "Class" << "health status" << Endl; cout << LEFT << SETW << Setfill (') << p->name;
        cout << left << setw (a) << Setfill (') << p->student_id;
        cout << left << setw (8) << Setfill (") << p->gender;
        cout << left << setw (a) << Setfill (') << p->age;
        cout << left << setw () << Setfill (') << p->class;

    cout << left << setw (km) << setfill (') << p->health_status << Endl;
    } void Linked_list::P rint_every_student () {Node *p;

    p = head_point;          cout << "name" << "School Number" << "Sex" << "Age" << "class" << "
    Health status "<< Endl;
        for (int i = 1; I <= student_count i++) {p = p->next_student;
        cout << left << setw () << Setfill (') << p->name; cout << left << setw (a) << setFill (') << p->student_id;
        cout << left << setw (8) << Setfill (") << p->gender;
        cout << left << setw (a) << Setfill (') << p->age;
        cout << left << setw () << Setfill (') << p->class;
    cout << left << setw (km) << setfill (') << p->health_status << Endl;
    } void Linked_list::add_student (string name) {Node *p = Head_point;
    Node *q = new node (name);
    student_count++;
    if (Student_count = = 1) {head_point->next_student = q;
        else {for (int i = 1; i < Student_count i++) {p = p->next_student;
    } p->next_student = q;

Return 
} void Linked_list::add_student (string name, int student_id, string gender, int age, String Class, String health_status)
    {Node *p = Head_point; Node *q = new node (name, student_id, gender, age, Class, Health_status);
    Create a node and connect it to the linked list student_count++;
    for (int i = 1; i < Student_count i++) {p = p->next_student;
    } p->next_student = q;
Return
        int Linked_list::show_print_menu () {for (; 1;)//To quickly jump out of the menu {System ("CLS") after doing something;
        cout << "┎┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┒" << Endl;
        cout << "┋ Student Educational Management System ┋" << Endl;
        cout << "┋① name sorting ② School Number sorting ┋" << Endl;
        cout << "┋③ Add order ④ return menu ┋" << Endl;
        cout << "┋┋" << Endl;
        cout << "┖┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┚" << Endl;
        cout << "Please enter the corresponding operation sequence number:";
        int operation_number;
        Cin >> Operation_number; if (Operation_number = = 4) {System ("CLS");
        Empty the display break of the console;
            } if (Operation_number = = 3) {print_every_student (); System ("pause");
            Display the print results, waiting for us to press any key to enter the menu option} if (Operation_number = 2) {linked_list id_sort;  Id_sort = *this;
            Call assignment constructor Id_sort.student_id_sort ();
            Id_sort.print_every_student (); Id_sort.clear_linked_list ();
        Destroy the sorted list system ("pause") after the printing is complete;
            } if (Operation_number = = 1) {linked_list name_sort;
            Name_sort = *this;
            Name_sort.student_name_sort ();
            Name_sort.print_every_student ();
            Name_sort.clear_linked_list ();
        System ("pause");
} return 0;
    int Linked_list::show_main_menu ()//submenu jump {for (; 1;)
        {cout << "┎┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┒" << Endl; cout << "┋ Student Administration Management DepartmentEC ┋ "<< Endl;
        cout << "┋① query data ② Modify Data ┋" << Endl;
        cout << "┋③ print data ④ exit system ┋" << Endl;
        cout << "┋┋" << Endl;
        cout << "┖┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┚" << Endl;
        cout << "Please enter the corresponding operation sequence number:";
        int operation_number;
        Cin >> Operation_number;  if (Operation_number = = 4) {exit (1);
            Exit program} if (Operation_number = 3) {show_print_menu (); Continue
            After exiting from the previous menu, restart the main menu bar display} if (Operation_number = 2) {show_edit_menu ();
        Continue
            } if (Operation_number = = 1) {show_query_menu ();
        Continue
} return 0; int Linked_list::show_query_menu () {bool Is_bACK = FALSE;
    for (; 1;)
        {System ("CLS");
        cout << "┎┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┒" << Endl;
        cout << "┋ Student Educational Management System ┋" << Endl;
        cout << "┋① name Inquiry ② Inquiry ┋" << Endl;
        cout << "┋③ return menu ┋" << Endl;
        cout << "┋┋" << Endl;
        cout << "┖┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┚" << Endl;
        cout << "Please enter the corresponding operation sequence number:";
        int operation_number;

        Cin >> Operation_number;
            if (Operation_number = = 3) {System ("CLS");
        Break  else if (Operation_number = = 2) {is_previous = false;
            The query points to the current node cout << "Please enter student number:";
            int student_id;
Cin >> student_id;            Print_student_details (student_id);
        System ("pause");
         }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.