1、includeincludemalloc.hdefine INIT_SIZE 10 #define INCRE_SIZE 10 define SUBJECT_NUM 3define LEN 3void show_Start();void show_Table();void addRecord();void Info_delete();void deleteRecord();void delete_Num(int);void delete_Name(char tarName);void Info_modify();void modifyRecord();void modify_Num(int);
2、void modify_Name(char);void Info_query();void queryRecord();void query_Num(int);void query_Name(char);void display();void quit();void menu_CMD();char *subjectSUBJECT_NUM = struct STUDENT int num; char name20; char sex; float scoreSUBJECT_NUM; /struct STUDENT stuLEN + 1;/STUDENT record = (STUDENT*)ma
3、lloc(sizeof(STUDENT)INIT_SIZE);int static stuNum = 0; /STUDENT record = (STUDENT)malloc(sizeof(STUDENT)INIT_SIZE);int main() /record = (STUDENT)malloc(sizeof(STUDENT)INIT_SIZE); /STUDENT *record = (STUDENT)malloc(sizeof(STUDENT)INIT_SIZE);/ record1。num = 1001; strcpy(record1。name,Jason); record1。sex
4、 = M; record1.score0 = 85。0; record1。score1 = 90。0; record1.score2 = 95.0;record2.num = 1002; strcpy(record2。name,”Jerry); record2.sex = M; record2。score0 = 85。0; record2.score1 = 90。0; record2。score2 = 95.0;record3。num = 1003; strcpy(record3。name,Jessie”); record3.sex = F; record3。score0 = 85。0; re
5、cord3。score1 = 90。0; record3.score2 = 95.0;*/ Info_modify(); int key; coutkey; if(key = 1) int targetNum; cout cintargetNum; modify_Num(targetNum); coutendl; display(); if(key = 2) char targetName20; couttargetName; modify_Name(targetName); coutendl; display(); if(key = 3) exit(0); / show_Start();me
6、nu_CMD();return 0; void show_Start() /coutendl; cout” * ”endl; cout” endl; cout” ”endl; cout” endl; cout” ”endl; cout Made by Jason endl; cout * ”endl;/. void show_Table() cout”t”t” cout”tsubject0”tsubject1”t”subject2; coutendl; void menu_CMD() int key; while(1) cout”1.endl; cout2。 endl; cout3。 endl
7、; cout”4. endl; cout5。 endl; cout6. key; while(1) if(key 1)(key 6)) int key; coutendl; coutkey; else break; switch(key) case 1: addRecord(); break; case 2: deleteRecord(); break; case 3: modifyRecord(); break; case 4: queryRecord(); break; case 5: display(); break; case 6: quit(); break; /void addRe
8、cord()if(stuNum = 0) cout INIT_SIZE) coutendl; record = (STUDENT*)realloc(record,(INIT_SIZE + INCRE_SIZE)sizeof(STUDENT); cout”!endl; coutendl; coutchoi; if(choi = Y)|(choi = y)) cout”: ”; cinrecordstuNum.num; coutrecordstuNum。name; cout”(M,F) : ”; cinrecordstuNum。sex; int i; for(i = 0;i SUBJECT_NUM
9、;i+) cout”subjecti : ; cinrecordstuNum。scorei; if(choi = N)|(choi = n) cout”endl; coutendl; coutstuNum”!”endl; coutendl;/ /deleteRecordvoid Info_delete() cout : ”endl; cout”1. ”endl; cout”2。 endl; cout”3。 ”endl;/void deleteRecord() int key; coutendl; Info_delete(); cout : ; cinkey; if(key = 1) int t
10、argetNum; cout : ”; cintargetNum; / delete_Num(targetNum); coutendl; if(key = 2) char targetName20; couttargetName; delete_Name(targetName); coutendl; if(key = 3) while(1) menu_CMD(); /void delete_Num(int tarNum) int i; for(i = 1;i = stuNum;i+) if(recordi.num = tarNum) / /1。 /2. if(i = stuNum) cout”
11、: ”endl; show_Table(); coutrecordi。numt”recordi.name”trecordi.sex”t recordi。score0recordi。score1”t”recordi。score2; coutendl; coutendl”: ”endl; show_Table(); for(int i = 1;i = stuNum - 1;i+) coutrecordi.num”t”recordi。name”t”recordi.sex; for(int j = 0;j SUBJECT_NUM;j+) cout”t”recordi。scorej; coutendl;
12、 /* stuNum-; coutstuNum; coutendl; / /2。 if(i != stuNum) cout” : ”endl; show_Table(); coutrecordi.num”t”recordi。namet”recordi。sext recordi.score0”t”recordi。score1”t”recordi。score2; for(int j = i+1;j = stuNum;j+) recordj1 = recordj; / coutendl; cout : endl; show_Table(); for(int i = 1;i = stuNum-1;i+
13、) coutrecordi。num”t”recordi。name”trecordi.sex; for(int j = 0;j SUBJECT_NUM;j+) coutt”recordi.scorej; coutendl; /* stuNum; cout”stuNum coutendl; / stuNum-; cout”stuNum coutendl; /*/void delete_Name(char tarName) int i; for(i = 1;i = stuNum;i+) if(strcmp(recordi.name,tarName) = 0) / /1. /2。 / if(i = s
14、tuNum) cout” : endl; show_Table(); coutrecordi。num”t”recordi.nametrecordi。sext recordi.score0recordi。score1t”recordi。score2; coutendl; coutendl : ”endl; show_Table(); for(int i = 1;i = stuNum - 1;i+) coutrecordi.num”trecordi。name”t”recordi.sex; for(int j = 0;j SUBJECT_NUM;j+) cout”t”recordi.scorej;
15、coutendl; / if(i != stuNum) cout : endl; show_Table(); coutrecordi.num”t”recordi。nametrecordi.sex”t recordi。score0”t”recordi。score1”trecordi.score2; / for(int j = i+1;j = stuNum;j+) recordj-1 = recordj; coutendl; / cout” : endl; show_Table(); for(int i = 1;i = stuNum1;i+) coutrecordi。num”t”recordi.n
16、amet”recordi。sex; for(int j = 0;j SUBJECT_NUM;j+) couttrecordi。scorej; coutendl; coutendl; void delete_Name(char tarName) int i; for(i = 1;i = stuNum;i+) / /1. /2. / if(strcmp(recordi.name,tarName) = 0) if(i = stuNum) cout : ”endl; show_Table(); coutrecordi。num”trecordi.name”t”recordi。sex”t recordi。
17、score0”t”recordi.score1”trecordi。score2; coutendl; cout” : endl; show_Table(); for(int i = 1;i = stuNum-1;i+) coutrecordi.num”trecordi。name”t”recordi.sex; for(int j = 0;j SUBJECT_NUM;j+) cout”t”recordi。scorej; coutendl; / stuNum-; cout”stuNum”; coutendl; / / if(i != stuNum) cout”endl; show_Table();
18、coutrecordi.num”t”recordi。name”t”recordi.sext; coutrecordi。score0”trecordi。score1t”recordi.score2; coutendl; for(int j = i+1;j = stuNum;j+) recordj-1 = recordj; /。 coutendl; cout : ”endl; show_Table(); for(int i = 1;i = stuNum1;i+) coutrecordi。num”t”recordi。name”trecordi。sex; for(int j = 0;j SUBJECT
19、_NUM;j+) cout”t”recordi.scorej; coutendl; / stuNum-; coutstuNum coutendl; / stuNum; cout”stuNum”; coutendl; /*/void Info_modify() cout : ”endl; cout”1. ”endl; cout2。 endl; cout3. ”endl; void modifyRecord() int key; coutendl; Info_modify(); coutkey;/ if(key = 1) int targetNum; couttargetNum; modify_N
20、um(targetNum); coutendl; /display(); / if(key = 2) char targetName20; cout : ; cintargetName; modify_Name(targetName); coutendl; /display(); if(key = 3) while(1) menu_CMD(); /void modify_Num(int tarNum) int i; for(i = 1;i = stuNum;i+) if(recordi。num = tarNum) coutrecordi.num; cout : ”; cinrecordi。na
21、me; coutrecordi。sex; cout”subject0recordi.score0; cout”subject1recordi。score1; cout”subject2 ”; cinrecordi。score2; void modify_Name(char tarName) int i; for(i = 1;i = stuNum;i+) if(strcmp(recordi.name,tarName) = 0) coutendl: endl; coutrecordi.name; cout : ”; cinrecordi.sex; cout”subject0 : ”; cinrec
22、ordi。score0; cout”subject1” : ”; cinrecordi.score1; cout”recordi。score2; void Info_query() cout : endl; cout”1。 ”endl; cout2。 endl; cout”3。 ”endl; /queryRecord void queryRecord() int key; coutendl; Info_query(); cout”; cinkey; if(key = 1) int targetNum; couttargetNum; query_Num(targetNum); coutendl;
23、 if(key = 2) char targetName20; couttargetName; query_Name(targetName); coutendl; /. if(key = 3) while(1) menu_CMD(); void query_Num(int tarNum) int i; for(i = 1;i = stuNum;i+) if(recordi。num = tarNum) / cout: ”endl; / show_Table(); / coutrecordi。num”trecordi。name”trecordi。sex; cout”t”recordi。score0
24、”t”recordi.score1”t”recordi。score2; coutendl; /void query_Name(char tarName) int i; for(i = 1;i = stuNum;i+) if(strcmp(recordi。name,tarName) = 0) cout”: ”endl; show_Table(); coutrecordi.num”t”recordi。nametrecordi.sex; cout”t”recordi。score0”t”recordi.score1”t”recordi。score2; coutendl; /void display() show_Table(); int i,j; for(i = 1;i = stuNum;i+) /cout学号”t”姓名”t”性别”; coutrecordi.numt”recordi.nametrecordi。sex; for(j = 0;j SUBJECT_NUM;j+) couttrecordi。scorej; coutendl; coutendl; /void quit() char choi; coutchoi; if(choi = Y)|(choi = y) cout”endl; exit(0); / else coutendl; menu_CMD();