Student Communication System Course Design
1. Purpose of this course
(1) Proficient in the basic knowledge and skills of C language;
(2) Master the chain storage structure of linear tables;
(3) Master the related operations of structures;
(4) Familiar with the query, insert and delete functions of the chain structure;
(5) Cultivate the ability to analyze and solve problems; improve students' writing ability of scientific and technological papers.
2. Curriculum Design Tasks and Requirements
1) Basic requirements:
(1) Design a menu that will be displayed in the realized function, and there will be a selection prompt
(2) Able to query the list of all members;
(3) Able to query the information of a member by number or name
(4) Ability to add, delete, and modify the information of a member
(5) It is required to have an error prompt function, such as gender, only F, M can be entered, and the input error prompts to re-enter
2) Innovation requirements:
Save the address book information as a file, which can be written and read.
Problem Description
(Describe the problem that the programming is required to solve)
- Realize the main interface of student communication system, and can refresh dynamically.
- Realize the operation of adding communication information in the student communication system, which can prompt for input, and prompt whether to continue adding or exit the adding interface after adding a student's information, and exit this interface after adding.
- Realize the operation of deleting student communication information in the student communication system, can prompt to enter the name of the student to be deleted, and output all the information of the student to be deleted on the screen to prevent the wrong person from being deleted, and can be used when the current system student information is empty. Prompt that the current address book is empty, and you can also prompt whether to exit this interface after the deletion is completed.
- Realize the operation of modifying student information in the student communication system, can prompt to input the name of the student to be modified, and output all the information of the student on the screen, and can prompt that the current address book is empty when the current system student information is empty, and also After the modification is completed, all the modified information of the student can be displayed and prompted whether to exit this interface.
- Realize the operation of querying student information in the student communication system, and can prompt to input the name or mobile phone number of the student to be queried, and output all the information of the student on the screen, and prompt the query to be successful.
- It realizes the function of outputting all the information of all students of the student communication system, and outputs all the information of each student one by one by traversing the singly linked list.
- Realize the file operation of the student communication system, can output all the student information in the student communication system to the file, and can automatically import the student information in the file when entering the student communication system, and can dynamically refresh in real time - in addition, deletion and modification operations Concurrent changes can be made to the student information in the later file.
brief introduction
2.1 Basic requirements:
(Give specific requirements to be met by the program.) - The student communication system has a menu that displays all the functions of the system, and can add, delete, and modify the information of a certain member.
- The student communication system can query the list of all members, and can query the information of a member by number or name
- Design a menu that will be displayed in the implemented functions, with selection prompts, and error prompts. For example, gender can only be input F, M, and the input error prompts to re-enter.
- This system adopts file operation to store all student information in the file to ensure the integrity of student information preservation as much as possible.
- The system calls the API function of windows to prompt the customers who use the system, so as to increase the comfort of the customers as much as possible
The source code is as follows:
#include<iostream> #include<graphics.h> #include<fstream> #include<string> using namespace std; typedef struct _T_data { char name[12]; char sex; char tel[12]; }T_data; typedef T_data* Pt_data; typedef struct _T_students { T_data data; struct _T_students * pt_next; }T_student; typedef T_student* Pt_student; char MyName[12]; char MySex; char MyTel[12]; void AddStudnet(Pt_student &head);//add students bool DelStudent(Pt_student &head);//delete student bool UpdateStudent(Pt_student &head);//Modify students bool Querystudent(Pt_student &head);//query students bool ClearListStudent(Pt_student &head);//clear linked list student void ClearFileStudent();//Clear student information from file bool Query(Pt_student &head, int choice);//Query Student Achievement bool DisplayStudent(Pt_student &head);//Display all student information in the linked list void LoadStudent(Pt_student &head);//Import student information from a file void Input(int flag);//Enter student information void Output(Pt_student &head);//output student information void Menu();//Program interface main menu void Menu() { cout << "****************************************************" << endl; cout << "\t\t Welcome to the Student Communication System" << endl; cout << "****************************************************" << endl; cout << "\t\t1.Add contacts" << endl; cout << "\t\t2.delete contact" << endl; cout << "\t\t3.Edit contacts" << endl; cout << "\t\t4.find a contact" << endl; cout << "\t\t5.Clear Contacts" << endl; cout << "\t\t6.Show contacts" << endl; cout << "\t\t7.Exit Contacts" << endl; cout << "____________________________________________________" << endl; } void Input(int flag) { switch (flag) { case 1: cout << "Please enter student name:"; cin >> MyName; break; case 2: while (1) { cout << "Please enter student gender(F or M):"; cin >> MySex; if (MySex != 'F' && MySex != 'M') { MessageBox(0, _T("Input errors, please re-enter"), _T("warn"), MB_OK|MB_ICONEXCLAMATION); continue; } break; } break; case 3: cout << "Please enter student phone number:"; cin >> MyTel; break; } } void AddStudnet(Pt_student &head) { while (1) { cout << "****************************************************" << endl; Pt_student temp; temp = (Pt_student)malloc(sizeof(T_student)); temp->pt_next = NULL; Input(1); strcpy(temp->data.name,MyName); Input(2); strcpy(&temp->data.sex, &MySex); Input(3); strcpy(temp->data.tel, MyTel); temp->pt_next = head->pt_next; head->pt_next = temp; cout << "\t Added successfully" << endl; if (MessageBox(0, _T("Whether to continue adding contacts"), _T("please choose"), MB_YESNO|MB_ICONQUESTION) == IDNO) break; } } void Output(Pt_student &head) { cout << "****************************************************" << endl; cout << "\tname" << "\t\tsex" << "\t\ttel" << endl; cout << "\t" << head->data.name << "\t\t" << head->data.sex << "\t\t" << head->data.tel << endl; } bool Query(Pt_student &head,int choice) { bool flag = false; Pt_student temp = NULL; if (1 == choice) { Input(1); for (temp = head; temp->pt_next != NULL; temp = temp->pt_next) if (!strcmp(temp->pt_next->data.name,MyName)) { Output(temp->pt_next); flag = true; } } else { Input(3); for (temp = head; temp->pt_next != NULL; temp = temp->pt_next) if (!strcmp(temp->pt_next->data.tel,MyTel)) { Output(temp->pt_next); flag = true; } } return flag; } bool Querystudent( Pt_student &head) { bool flag = false; if (head->pt_next == NULL) { MessageBox(0, _T("The current address book is empty,Please add first"), _T("warn"), MB_OK|MB_ICONEXCLAMATION); return false; } int choice = 1; cout << "****************************************************" << endl; cout << "\t1.Student name query" << endl; cout << "\t2.Student mobile phone number query" << endl; cout << "----------------------------------------------------" << endl; while (1) { cout << "\t Please enter the query method of your choice(1 or 2):"; cin >> choice; if (choice != 1 && choice != 2) { MessageBox(0, _T("input error,please enter again"), _T("warn"), MB_OK|MB_ICONEXCLAMATION); continue; } break; } if (!Query(head, choice)) MessageBox(NULL, _T("Check no such person,whether to quit"), _T("hint"), MB_OK | MB_ICONQUESTION); else MessageBox(NULL, _T("Find success,whether to quit"), _T("hint"), MB_OK | MB_ICONQUESTION); return true; } bool DelStudent(Pt_student &head) { if (head->pt_next == NULL) { MessageBox(0, _T("The current address book is empty,Please add first"), _T("warn"), MB_OK|MB_ICONEXCLAMATION); return false; } Pt_student pretemp,temp; cout << "----------------------------------------------------" << endl; cout << "\t Please enter the student information you want to delete:" << endl; Input(1); for (pretemp = head; pretemp->pt_next != NULL; pretemp = pretemp->pt_next) if (!strcmp(pretemp->pt_next->data.name , MyName)) { cout << "The information of the students to be deleted is as follows" << endl; Output(pretemp->pt_next); break; } if (pretemp->pt_next== NULL) { MessageBox(0, _T("Check no such person,Can't delete,whether to quit"), _T("warn"), MB_OK | MB_ICONEXCLAMATION); return false; } temp = pretemp->pt_next; pretemp->pt_next = temp->pt_next; delete temp; MessageBox(NULL, _T("Delete successfully, whether to exit"), _T("hint"), MB_OK | MB_ICONQUESTION); return true; } bool UpdateStudent(Pt_student &head) { bool flag = false; if (head->pt_next == NULL) { MessageBox(0, _T("The current address book is empty,Please add first"), _T("warn"), MB_OK|MB_ICONEXCLAMATION); return false; } Pt_student temp; cout << "----------------------------------------------------" << endl; cout << "\t Please enter the student information you want to modify:" << endl; Input(1); for (temp = head->pt_next; temp!= NULL; temp = temp->pt_next) if (!strcmp(temp->data.name , MyName)) { cout << "\t Modify previous student information" << endl; Output(temp); break; } if (temp == NULL) { MessageBox(0, _T("Check no such person,cannot be modified,whether to quit"), _T("warn"), MB_OK | MB_ICONEXCLAMATION); return false; } cout << "\t Please enter revised student information" << endl; Input(1); strcpy(temp->data.name, MyName); Input(2); strcpy(&temp->data.sex, &MySex); Input(3); strcpy(temp->data.tel, MyTel); cout << "\t Revised student information" << endl; Output(temp); MessageBox(NULL, _T("Successfully modified,whether to quit"), _T("hint"), MB_OK | MB_ICONQUESTION); return true; } bool ClearListStudent(Pt_student &head) { bool flag = false; if (head->pt_next == NULL) { MessageBox(0, _T("The current address book is empty,Please add first"), _T("warn"), MB_OK|MB_ICONEXCLAMATION); return false; } Pt_student temp,tempnext; for (temp = head->pt_next; temp != NULL; temp = tempnext) { tempnext = temp->pt_next; delete temp; } head->pt_next = NULL; cout << "\t\t empty" << endl; return true; } void ClearFileStudent() { ofstream fout("students.txt", ios::trunc); fout.close(); } bool DisplayStudent(Pt_student &head) { bool flag = false; if (head->pt_next == NULL) { MessageBox(0, _T("The current address book is empty,Please add first"), _T("warn"), MB_OK|MB_ICONEXCLAMATION); return false; } Pt_student temp = head->pt_next; for (; temp != NULL; temp = temp->pt_next) Output(temp); MessageBox(NULL, _T("All information to show,whether to quit"), _T("hint"), MB_OK | MB_ICONEXCLAMATION); return true; } //record keeping void SaveStudent(Pt_student &head) { Pt_student temp = head->pt_next; ofstream fout("students.txt"); while (temp) { fout << temp->data.name << "\t" << temp->data.sex << "\t" << temp->data.tel <<"\n"; temp = temp->pt_next; } fout.close(); cout << "\t Data is saved!\n"; } //read record void LoadStudent(Pt_student &head) { ifstream fin("students.txt"); int i = 0; while (fin >>MyName>>MySex>>MyTel) { Pt_student temp = (Pt_student)malloc(sizeof(T_student)); strcpy(temp->data.name, MyName); strcpy(&temp->data.sex, &MySex); strcpy(temp->data.tel, MyTel); temp->pt_next = head->pt_next; head->pt_next = temp; i++; } if (i == 0) { cout << "Failed to load,There is currently no data in the document!" << endl; fin.close(); } else { fin.close(); cout << "successfully loaded" << i << "row data" << endl; } } int main() { HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); //Get the current window handle SMALL_RECT rc; //Rectangular structure assignment rc.Left = 30; rc.Top = 30; rc.Right = 80; rc.Bottom = 70; //At this point, the width of the window is 50 and the height is 20 SetConsoleWindowInfo(hOut, TRUE, &rc);//window properties int choice; //Build a singly linked list with a head node Pt_student head; head = (Pt_student)malloc(sizeof(T_student)); head->pt_next = NULL; LoadStudent(head); //Import communication information in a file while (1) { system("cls"); Menu(); cout << "\t Please enter your choice(1-7):"; cin >> choice; if (!(0==choice || 1==choice ||2==choice||3==choice||4==choice||5==choice||6==choice)) { MessageBox(0, _T("input error,please enter again"), _T("warn"), MB_OK|MB_ICONEXCLAMATION); continue; } switch (choice) { case 1: system("cls"); AddStudnet(head); ClearFileStudent(); SaveStudent(head); break; case 2: system("cls"); DelStudent(head); ClearFileStudent(); SaveStudent(head); break; case 3: system("cls"); UpdateStudent(head); ClearFileStudent(); SaveStudent(head); break; case 4: system("cls"); Querystudent(head); break; case 5: system("cls"); ClearFileStudent(); ClearListStudent(head); break; case 6: system("cls"); DisplayStudent(head); break; case 7: system("cls"); CloseHandle(hOut); exit(0); default: break; } } CloseHandle(hOut); return 0; }