C language programming problem
Assignment of production practice (curriculum design)
Fundamentals of subject or task programming (C) week 2
Professional computer science class level 21 related professional classes
Instructor Chen Huafeng, Hu Meiyan, Graduate Teaching Assistant
Internship tasks and objectives
Through this training, master the main knowledge points of C language: control statements, arrays, functions, structures, files, etc., master the structured programming method of C program, and be able to use C language to develop simple applications.
Time and place of internship
Computer classes 211 and 212, 20-606, February 28, 2022 - March 4, 2022
Specific content of practice (topic 1) library borrowing system
(topic 2) student file management system
Source download
Link: https://pan.baidu.com/s/1mq8kqN3BvK0IvZBEUP9Oag
Extraction code: 1111
(topic 3) restaurant service management system
Source download
Link: https://pan.baidu.com/s/1mq8kqN3BvK0IvZBEUP9Oag
Extraction code: 1111
(Title IV) hotel service management system
Source download
Link: https://pan.baidu.com/s/1mq8kqN3BvK0IvZBEUP9Oag
Extraction code: 1111
(topic 5) game topics (self prepared)
Source download
Link: https://pan.baidu.com/s/1mq8kqN3BvK0IvZBEUP9Oag
Extraction code: 1111
After copying this content, open Baidu online disk mobile App, which is more convenient to operate
Internship task arrangement basic task 1. Topic selection, each person selects a topic to complete, one topic for each person, and complete it independently.
2. Understand the meaning of the question and clarify the design objectives and tasks. The functional module must include 7 modules: data addition, deletion, modification, query, storage, sorting and other personalized functions.
3. Use C language to realize the subject design, coding, debugging, operation and acceptance.
4. The instructor shall check and accept the design results and ask questions.
Extended task 1. Software development: understand the ideas and basic methods of software development, and standardize the design process and documents
2. Menu display: it can use the graphic knowledge of C language to design more beautiful and convenient
3. Table display: add a table to the displayed record content, and the table lines are realized by drawing lines and other functions
Internship requirements 1 Clear design tasks, be able to dictate and describe their own subject requirements and expected results in words;
2. Be clear about the application of main knowledge in the design process, and communicate with the instructor in time if it is unclear;
3. Be able to carry out overall design, that is, be clear about the data and document design, function design and function module design in the subject;
4. Be able to design and code each module, i.e. function in detail;
5. Be able to conduct joint debugging for all function modules;
6. Careful coding and unified style to minimize syntax errors in the code;
7. Various debugging data, pay attention to special circumstances and boundary data processing, and try to reduce the logic errors of the code;
Preparation requirements of Internship (Design) report 1 Design assignment
2. Overall design (data, document design, function design, function module design)
3. Detailed design (functional description of each module, main flow chart and function composition)
4. Debugging and testing (describe the debugging data, test scheme and results of several typical modules)
5. Some main codes (main function module codes, comments, operation results)
6. Design experience and suggestions
7. References
The instructor shall check the completion of the above tasks, record the attendance every day, and finally conduct on-site inspection and question and answer, and correct the internship report.
Score evaluation: 70 points for the final system (15% for adding, deleting, modifying, querying, storing and sorting modules and 10% for other personalized functions) + 30 points at ordinary times (60 points for content completeness, 25 points for format standardization and 15 points for innovation).
Clear design tasks on the first day
(1) Purpose
-
Be familiar with the composition of the system and the function of each functional module
-
Master the composition of C program
-
Master the function of main function
-
Master the display method of menu
-
Master the processing method of menu
-
Master the debugging method of function
(2) Content -
The instructor assigns questions and analyzes the meaning of the questions
-
Instruct the teacher to explain the usage of file functions;
-
Discuss with the instructor to further clarify the meaning of the topic and analyze the main knowledge points and algorithms of the topic
-
According to the analysis, students review the knowledge points: switch statement, circular statement, structure, function and structure array
-
Write main interface
(3) Guide -
Experimental environment
Available in C-Free or VC + + or VS.net -
Review knowledge points:
(1) Statement, structure, function, Switch body
(2) Master array elements: addition, deletion, modification, query, sorting and statistics;
Day 2 overall design
(1) Purpose -
Basically complete the overall design: data file design, function design and module design;
-
Program and design the main interface. If the program cannot be realized, it needs to be drawn by sketch;
(2) Content -
Analyze the topic selection, describe the function module and design the main interface;
-
Define the main data, design function modules and the calling relationship between functions.
(3) Guide -
Refer to the function module diagram of "student status management system";
-
Refer to the function module diagram of "performance management system";
-
Define structure and structure array;
typedef struct //Date structure { int year; int month; int day; } Date; typedef struct //Student status structure { char xh[20];//Student number char xm[10];//full name char lxdh[12]; //contact number char jtdz[30]; //Home address Date birthday; //birthday char zy[15]; //major } XJ; XJ xsxj[100]; //Define an array with XJ to store scores; typedef struct //Achievement structure { char xh[20]; //Student number char xm[10]; //full name Date birthday; //date of birth char kcmc[15]; //Course name int cj; //achievement } CJ; CJ xscj[100]; //Use the structure CJ to define an array to store scores
Day 3 detailed design
(1) Purpose
- Decompose the function modules and analyze the calling process between functions;
- Write each function code and realize the function modules one by one;
(2) Content
Write the code of each processing function module;
(3) Guide
- Completion module of "student status management system": add student status information, delete student status information and modify student status information;
- "Performance management system" completion module: add performance information, delete performance information and modify performance information;
Day 4 detailed design
(1) Purpose
1. Decompose the function modules and analyze the calling process between functions;
2. Write each function code and realize the function modules one by one;
(2) Content
- Structure definition, structure array definition;
- Complete the code implementation of each processing function module;
(3) Guide
3. Completion module of "student status management system": query student status information, count student status information and sort student status information;
4. "Performance management system" completion module: query performance information, statistical performance information and sort performance information;
On the fifth day, test the joint commissioning and test the score
(1) Purpose
- Add file storage function for the program;
- Joint debugging of all program modules
- Eliminate the test errors in the program and improve the shortcomings of the program
- Students demonstrate and answer questions, and the teacher checks the results and scores
(2) Content
- Use single step and breakpoint debugging methods to find errors in functions.
- Make the program meet the design requirements and achieve the corresponding design effect.
(3) Guide
- File reading and writing functions of common structure data: fread(), fwrite().
- Implement the file operation interface in the system.
Attachment: some reference codes
"Student status management system" and "achievement management system" can be composed of the following function modules, which are introduced as follows:
Function name (function module) or other function main() Main function menu_select() Menu selection handle_menu() Menu processing s_read() Read record s_save() Keep records xhexist() Judge whether a student number exists s_add() Add record modi_xh() Modify records by student number modi_xm() Modify records by name del_xh() Delete records by student number del_xm() Delete records by name sear_all() Query all records sear_xm() Query records by name sear_xh() Query records by student number sear_sr() Query records by birthday sear_jtdz() Query records by home address sort_xh() Sort by student number sort_cj() Sort by grade count1() Statistics???
Other functions
Overall design idea: in order to simplify the program, all recording operations are completed through the structure array. When the program starts to execute, the data file is read into the structure array at one time, and the subsequent operations on the data are completed through the structure array. "Add, modify, delete" is used to write files, and "find, sort" is used to read files.
(1) Main control module
typedef struct //Date structure { int year; int month; int day; } Date; typedef struct //Student status structure { char xh[20];//Student number char xm[10];//full name char lxdh[12]; //contact number char jtdz[30]; //Home address Date birthday; //birthday char zy[15]; //major } XJ; #include "stdio.h" #include "stdlib.h" #include "conio.h" #include "ctype.h" #include "string.h" #define LEN sizeof(struct XJ) XJ stud[100]; //Define an array with XJ to store scores int reccount=0; /*Define global variables to store current records and the number of records*/ void s_read( ); /*Function declaration: read record*/ void s_save( ); /*Function declarations: saving records*/ int xhexist(char num[],int w); /*Function declaration: judge whether the student number exists*/ void s_add( ); /*Function declaration: append record*/ void sear_xh( ); /*Function declaration: query by student number*/ void sear_xm( ); /*Function declaration: query by name*/ void sear_all( ); /*Function declaration: query all records*/ void sear_sr( ); /*Function declaration: query records according to the entered birth year, month or date*/ void sear_jtdz( ); /*Function declaration: query records by the entered address*/ void modi_xh( ); /*Function declaration: modified by student number*/ void modi_xm( ); /*Function declaration: modify by name*/ void del_xh( ); /*Function declaration: delete by student number*/ void del_xm( ); /*Function declaration: delete by name*/ void sort_xh( ); /*Function declaration: sort by student number*/ void sort_cj( ); /*Function declaration: sort by grade*/ int menu_select(); /*Function declarations: menu selection*/ void handle_menu(); /*Function declarations: menu handling*/ void main() /*Program entry { s_read( ); /*Call the read record function*/ handle_menu(); /*Call menu handler*/ } /*The menu processing functions are defined below*/ void handle_menu() { intsel,flag; for(; ;) { switch (menu_select()) /*Used to call the menu selection function*/ { case 1 : s_add( ); /*Call the append record function*/ break; case 2: flag=1; while (flag) { /*The modification record submenu is shown below*/ printf("\n [Modify record submenu]\n\n"); printf(" +------------------------+\n"); printf(" | 1. Modify by student number |\n"); printf(" | 2. Modify by name |\n"); printf(" | 0. return |\n"); printf(" +------------------------+\n"); printf(" Please select (0)~2:"); scanf("%d",&sel); switch(sel) { case 0: flag=0; break; case 1: modi_xh( ); break; case 2: modi_xm( ); break; } } break; case 3: flag=1; while (flag) { /*The delete record submenu is shown below*/ printf("\n [Delete record submenu]\n\n"); printf(" +------------------------+\n"); printf(" | 1. Delete by student number |\n"); printf(" | 2. Delete by name |\n"); printf(" | 0. return |\n"); printf(" +------------------------+\n"); printf(" Please select 0~2:"); scanf("%d",&sel); switch(sel) { case 0: flag=0; break; case 1: del_xh( ); break; case 2: del_xm( ); break; } } break; case 4: flag=1; while (flag) { /*The query submenu is shown below*/ printf("\n [Query record submenu]\n\n"); printf(" +------------------------+\n"); printf(" | 1. Query by student number |\n"); printf(" | 2. Query by name |\n"); printf(" | 3. Query all |\n"); printf(" | 0. return |\n"); printf(" +------------------------+\n"); printf(" Please select( 0~3:"); scanf("%d",&sel); switch(sel) { case 0: flag=0; break; case 1: sear_xh( ); break; case 2: sear_xm( ); break; case 3: sear_all( ); break; } } break; case 5: flag=1; while (flag) { /*The submenu of sorting records is shown below*/ printf("\n [Sort records submenu]\n\n"); printf(" +------------------------+\n"); printf(" | 1. Sort by student number |\n"); printf(" | 2. Sort by grade |\n"); printf(" | 0. return |\n"); printf(" +------------------------+\n"); printf(" Please select 0~2:"); scanf("%d",&sel); switch(sel) { case 0: flag=0; break; case 1: sort_xh( ); break; case 2: sort_cj( ); break; } } break; case 0: printf("exit,bye!\n"); s_save( ); //Before calling, once the function is saved, save the array in the array to the file. exit(0); } } } /*Select menu functions as defined below*/ int menu_select() { char s[2]; int cn; /*The main menu is shown below*/ printf("\n\n [Main menu]\n"); printf("\n"); printf(" +--------------------+\n"); printf(" | 1—Append record |\n"); printf(" | 2—Modify record |\n"); printf(" | 3—Delete record |\n"); printf(" | 4—Query record |\n"); printf(" | 5—sort record |\n"); printf(" | 0—sign out |\n"); printf(" +--------------------+\n"); for (; ;) { printf("\n Please select (0~5):"); scanf("%d",&cn); printf("\n"); if (cn<0 || cn>5) printf("\n input error!"); else break; } returncn; }
(2) Main functional modules
1,s_read() function:
When the system is used for the first time, the data file "st_table" shall be automatically established, and then the records can be read from the "st_table" file and stored in the structure array.
void s_read( ) { FILE *fp; inti; if((fp=fopen("st_table","rb"))==NULL) { if((fp=fopen("st_table","wb"))==NULL) { printf("Cannot open file!\n"); exit(1); } fclose(fp); } fclose(fp); if((fp=fopen("st_table","rb"))==NULL) {printf("Cannot open file!\n"); exit(1); } i=0; reccount=0; while (!feof(fp)) { if(1!=fread(&stud[i],LEN,1,fp)) break; ++reccount; i++; } fclose(fp); printf("Total records=%d \n",reccount); }
2,s_save() function:
When the data in the structure array changes, such as adding records, modifying records, deleting records, etc., the latest data will be written back to the disk file "st_table" through this function.
/*The following defines the write record to file function*/ void s_save( ) { FILE *fp; int i; if ((fp=fopen("st_table","wb"))==NULL) { printf("Cannot open file!\n"); exit(1); } for (i=0;i<reccount;i++) if(fwrite(&stud[i],LEN,1,fp)!=1) printf("File write error!\n"); fclose(fp); }
3. xhexist() function:
It is used to judge whether a student number exists. If it exists, it returns the function value of 1, otherwise it returns 0, because the system requires the student number as the unique keyword, that is, duplicate student numbers are not allowed. When adding or modifying, the uniqueness of the student number is guaranteed by calling this function.
/The following definitions determine whether the student number has a function/
int xhexist( char num[]) { int i; int flag=0; for (i=0;i<reccount; i++) if (strcmp(num,stud[i].xh)==0) { flag=1; break; } return (flag); }
4,s_add() function:
It is used to add a new record to the structure array and judge the repetition of student number when entering.
void s_add( ) { char s[2]; int count = recount; while (1) { printf("Student number:"); scanf("%s",stud[count].xh); if (xhexist(stud[count].xh)==1) printf("Student number already exists!\n"); else break; } printf("full name:"); scanf("%s",stud[reccount].xm); printf("contact number:"); scanf("%s",stud[reccount].lxdh); printf("Home address:"); scanf("%s",stud[reccount].jtdz); printf("Postal Code:"); .........//Enter each item to be added in turn reccount++; printf("Total records=%d\n", reccount); }
5,void modi_xh() function:
It is used to modify records by student number. First, enter the student number to be modified. If it exists, the original data will be displayed, and then prompt for new data. When entering, judge the repetition of student number. If it already exists, it is not allowed to enter; Otherwise, it will prompt that the student number does not exist.
6,void modi_xm() function:
It is used to modify records by name. First, enter the name to be modified. If it exists, the original data will be displayed, and then prompt for new data. When entering, judge the repetition of student number. If it already exists, it is not allowed to enter, and multiple records with the same name can be modified; Otherwise, the prompt name does not exist.
7,void del_xh() function:
It is used to delete records by student number. First, enter the student number to be deleted. If it exists, the original data will be displayed, and then prompt whether to delete it. If you enter Y, delete it. The deletion is realized by moving the record up; Otherwise, it will prompt that the student number does not exist.
8,void del_xm() function:
It is used to delete records by name. First, enter the name to be deleted. If it exists, the original data will be displayed, and then prompt whether to delete it. If you enter Y, delete it. The deletion is realized by moving records up, and multiple records with the same name can be deleted; Otherwise, the prompt name does not exist.
8, void sear_xh() function:
It is used to query records by student number. First, enter the student number to query. If it exists, the original data will be displayed; Otherwise, it will prompt that the student number does not exist.
9,void sear_xm() function:
It is used to query records by name. First, enter the name to query. If it exists, the original data will be displayed, and multiple records with the same name can be queried; Otherwise, the prompt name does not exist.
10,void sear_all() function:
Used to display all records.
11,void sear_sr() function:
Used to complete the query by birthday. First enter the birthday to be queried. You can enter four kinds of data and get the corresponding query results respectively: ① enter the year (format 4 digits: 19 * *), and query and display all student records born in this year; ② Enter the month (Format: 1-2 digits: integer between 1-12) to query and display all student records born in this month; ③ Enter the month and year (Format: 6 digits: 198708) to query and display all student records born in this year and this month; ④ Enter the month / date (format 4 digits: 0621) to query and display all student records born on the same day of the same month.
12,void sear_jtdz() function:
It is used to complete the query by home address. First, enter the address. The format can be any string. By matching the substring in the string, find out all student records consistent with the home address and the input address.
13,void sort_xh() function:
It is used to sort records by student number. It is required to sort by bubbling method.
14,void sort_cj() function:
Used to sort by grades, you can use selective sorting or bubble sorting algorithm.
15. Others, designed by yourself;