当前位置:网站首页>C language student management system - can check the legitimacy of user input, two-way leading circular linked list
C language student management system - can check the legitimacy of user input, two-way leading circular linked list
2022-06-24 06:41:00 【chfens】
It's been a long time .. There are a lot of things to sum up and write a blog , My blog ToDo List and a lot of items , Make up little by little ..
One of the courses in this semester is to design a student management system , Store students' basic information and grades . I use C Written language , Studying recently C++, Looking back at this system, I feel very uncomfortable ,C++ The feature of can reduce a lot of redundant code .
function
Add, delete, check, modify and sort , Data can be saved to disk , Read the file information every time you initialize .
Storage
The data in memory is Double headed circular linked list Storage , Therefore, the insertion and deletion time complexity is O(1), Data can be saved in Local disk Of txt In file , You can modify the storage path in your code .
The main points of
Put forward some key points that should be paid attention to when designing this system :
- The use of data structures
Here I use the two-way leading circular linked list , The reader can modify it to Single chain list , I just used this data structure to make my code different from my classmates , In terms of efficiency, it is impossible to distinguish . Designing this system requires you to be familiar with the linked list structure , Be able to write, add, delete, check and modify by yourself .
- Input validity
At first, there was no formal judgment , Just directly read the data entered by the user , So I was scolded by the teacher , But the teacher didn't tell us before = =.
Input judgments include students Information input The legality of and Option selection The legitimacy of time .
When users enter information, they may naughty , For example, input the student ID in Chinese , Name, student ID, etc , Therefore, it is necessary to check whether the format is correct , If it is not correct, continue to lose , Until you lose right .
When choosing Options , For example, I 5 Options from 1 To 5, But you entered a number other than , Or you enter a character , Because I use scanf Read options , If a character is entered, it will not be read , If set in while It will cause jamming , Because characters will always Stay in the buffer .
- Modular programming
Keep modularity in mind when designing , Functions should be highly cohesive and low coupling , You can reuse it when you want to use it .
( The following content is directly copied from my experiment report )
Let's start with student ID judgment :
Student ID is used The character array stores Of , It is necessary to judge whether the student number entered is Pure number , Letters or symbols are not allowed , And the student number shall be five digits , The range of student ID allowed to be entered is 0 To 10^5 - 1, Considering the above two points , When inputting student information, first use an integer data to receive the data input by the user . If the format is correct , Then the data will be modulo each time 10 Followed by the characters 0 Of ASCII value , That is, the last bit of the integer is converted into character data and stored at the end of the array , The student ID can be stored . If you use int Type receive user input , Problems will occur when the data value entered by the user is too large , So choose long long int Type storage . When the number is successfully entered and stored in stuNumber After... In the array , call isExistStu() Function to check whether a student with this student number already exists . If all the above conditions can pass , Then execute the following procedure .
Name judgment :
Name use The character array stores , Only users are allowed to enter Chinese characters , Letters... Are not allowed 、 Numbers or symbols . Name word count support 2 To 4 position , First, judge whether the user enters characters or numbers , If not , It is necessary to further determine whether to input Chinese characters with non Chinese symbols .
Set the current environment Coding format by Simplified Chinese (GB2312), It is known that a Chinese character or a Chinese symbol in the character set under this encoding format occupies Two bytes , And of each byte highest All for 1, Therefore, it is possible to distinguish whether the contents of the space are Chinese characters . use for Loop to judge whether the user input is pure Chinese , If it is not in Chinese, let the user re-enter . If it's in Chinese , Then check whether there are Chinese symbols .
It is known that GB2312 Code the characters included “ Partition ” Handle , common 94 Districts , Each zone contains 94 bits , common 8836 A code bit .01-09 District Include all the characters except Chinese characters 682 Characters .GB2312 It is specified that each character included shall be represented by two bytes , The first byte is “ High byte ”, Corresponding 94 Districts ; The second byte is “ Low byte ”, Corresponding 94 bits . So its location code range is :0101-9494. Add... To the area code and tag number respectively 0xA0 Namely GB2312 code . Therefore, when characters other than Chinese characters are stored , The high-level content is A0-A9, You can check the high order of each Chinese input when stored in the array to determine whether it is a symbol . If all the above conditions can pass , Then execute the following procedure .
Various achievements :
Grades are stored in single precision floating-point variables , It is also not allowed to enter characters or symbols , The score range is 0-100, At most one decimal place , And the decimal part can only be 0.0 or 0.5. use modf() Function takes the decimal part of the input number to determine whether it is 0.5 or 0.0, If not, re-enter .

Sort student grades
Select... From the main menu 8 When sorting student information , call GetNumStu Function to get the number of information in the linked list , Then open up two arrays of equal size , Array theScore Save results , Array theNode Where the student information is stored The address of the node . Then prompt the user to enter the options to sort . Then call SortStu function , With Student grades are indexed , Turn the ranking of students' grades into the ranking of corresponding nodes . First, the students' scores to be sorted are stored in theScore in , At the same time, the corresponding student nodes are stored in theNode in . After through Insertion sort The results are sorted and modified at the same time theNode The order of nodes in . After sorting, return to . Cycle call PrintStu Print structure pointer array theNode The information of middle school students can get the ranking results of grades , Release the two opened arrays after printing , Then return to the main menu interface .
file save
use fread and fwrite function , instead of fscanf and fprintf, Because it's inconvenient to use .
I'm not going to post the code here , Upload the code to my code cloud , Take it from yourself if you need it .
Student management system source code
Any questions about the code can be raised in the comments section !
Conclusion
for C A small test of language , I hope I can have the motivation to continue my study , Continue to blog more !!!! To achieve a little , From “ Youheng ” Start with two words .
边栏推荐
- Kangaroo cloud: the overall architecture and key technical points of building a real-time computing platform based on Flink
- Printer connection mode
- leetcode:85. 最大矩形
- Enter the software test pit!!! Software testing tools commonly used by software testers software recommendations
- I want to say "three no" to digital transformation
- Several methods for reinstalling the system:
- How to open a hidden file
- Tencent security apkpecker launched dex-vmp automatic shelling service
- Centos7 deploying mysql-5.7
- Web automation test (3): Selenium basic course of web function automation test
猜你喜欢
Fault analysis | using --force to batch import data leads to partial data loss

About Stacked Generalization

记录--关于virtual studio2017添加报表控件的方法--Reportview控件

A cigarette of time to talk with you about how novices transform from functional testing to advanced automated testing
![跳跃游戏II[贪心练习]](/img/e4/f59bb1f5137495ea357462100e2b38.png)
跳跃游戏II[贪心练习]

leetcode:84. 柱状图中最大的矩形

The product layout is strengthened, the transformation of digital intelligence is accelerated, and FAW Toyota has hit 2022million annual sales

目标5000万日活,Pwnk欲打造下一代年轻人的“迪士尼乐园”

leetcode:剑指 Offer 26:判断t1中是否含有t2的全部拓扑结构

记录--关于JSP前台传参数到后台出现乱码的问题
随机推荐
Papamelon 11 number of calculation permutation [combinatorics]
Wordpress5.8 is coming, and the updated website is faster!
What are the easy-to-use character recognition software? Which are the mobile terminal and PC terminal respectively
Asp+access web server reports an error CONN.ASP error 80004005
Surveying and mapping principle of GIS coordinate system: geoid / datum / reference ellipsoid /epsg/sri/wkt
Analysis and treatment of easydss flash back caused by system time
When easynvs is deployed on the project site, easynvr cannot view the corresponding channel. Troubleshooting
go 断点续传
Do you want to research programming? I got six!
In the half year, there were 2.14 million paying users, a year-on-year increase of 62.5%, and New Oriental online launched its private domain
数据库 存储过程 begin end
When should I use Apache Druid
Code scanning | a sharp tool for controlling code quality
Nature Neuroscience: challenges and future directions of functional brain tissue characterization
Why does the remote end receive a check-out notice when the TRTC applet turns off audio and video locally
Apache enables gzip compressed web page transmission method
目标5000万日活,Pwnk欲打造下一代年轻人的“迪士尼乐园”
The installation method of apache+mysql+php running environment under Windows
Use of SAP QM inspection points
When the VPC main network card has multiple intranet IP addresses, the server cannot access the network internally, but the server can be accessed externally. How to solve this problem