同学通讯录系统(完整项目过程-迭代式开发)
本次项目参考 《C 程序设计与项目实践》这本书
对于初学者建议看本书, 学起来比较感兴趣, 人家都说兴趣是最好的老师。
这本书打破了传统的教学模式, 以各个小项目来讲解知识点。
同学通讯录系统项目开发步骤:
第一次迭代:完成系统框架的搭建。
第二次迭代:用数组实现同学通信录系统。
第三次迭代:用数组和文件实现同学通讯录系统。
第四次迭代:用链表和文件实现同学通讯录系统。
整个系统功能:
1.增加同学 2.查找同学 3.修改同学 4.删除同学 5.退出系统。
第一次迭代:版本v1.0 功能:大件系统框架
code:https://github.com/lujinjianst/myNCCL/blob/master/practices/Alumni-management-information-system/version1.0.c
运行结果:
====Alumnni management information system
1. Increase students information
2. Find students information
3. Modify students information
4. Delete students information
0. Quit system
=============================================
Please input your choice(0~4):
1
is in the process of the first 1 a choice
deal with increseing......
====Alumnni management information system
1. Increase students information
2. Find students information
3. Modify students information
4. Delete students information
0. Quit system
=============================================
Please input your choice(0~4):
2
is in the process of the first 2 a choice
deal with querying......
====Alumnni management information system
1. Increase students information
2. Find students information
3. Modify students information
4. Delete students information
0. Quit system
=============================================
Please input your choice(0~4):
3
is in the process of the first 3 a choice
deal with modifying......
====Alumnni management information system
1. Increase students information
2. Find students information
3. Modify students information
4. Delete students information
0. Quit system
=============================================
Please input your choice(0~4):
4
is in the process of the first 4 a choice
deal with deleteing......
====Alumnni management information system
1. Increase students information
2. Find students information
3. Modify students information
4. Delete students information
0. Quit system
=============================================
Please input your choice(0~4):
0
is in the process of the first 0 a choice
Welcome to use this system again, goodbye!
第二次迭代:版本v2.0 功能: 用数组存储同学录信息
code:https://github.com/lujinjianst/myNCCL/blob/master/practices/Alumni-management-information-system/version2.0.c
运行结果:
====Alumnni management information system
1. Increase students information
2. Find students information
3. Modify students information
4. Delete students information
0. Quit system
=============================================
Please input your choice(0~4):
1
is in the process of the first 1 a choice
deal with increseing......
name:a
address:b
telephone:1234
Uint:c
Increase student success
====Alumnni management information system
1. Increase students information
2. Find students information
3. Modify students information
4. Delete students information
0. Quit system
=============================================
Please input your choice(0~4):
2
is in the process of the first 2 a choice
deal with querying......
Please input to change the name of the students:a
You find classmate information below:
name:a address:b telephone:1234 work unit:c
====Alumnni management information system
1. Increase students information
2. Find students information
3. Modify students information
4. Delete students information
0. Quit system
=============================================
Please input your choice(0~4):
2
is in the process of the first 2 a choice
deal with querying......
Please input to change the name of the students:a
You find classmate information below:
name:a address:b telephone:1234 work unit:c
====Alumnni management information system
1. Increase students information
2. Find students information
3. Modify students information
4. Delete students information
0. Quit system
=============================================
Please input your choice(0~4):
3
is in the process of the first 3 a choice
deal with modifying......
Please input to change the name of the students:a
You find classmate information below:
name:a address:b telephone:1234 work unit:c
Please modify:
name:aa
address:bb
telephone:234
Uint:cc
Name for a classmates information has been modified successfully
====Alumnni management information system
1. Increase students information
2. Find students information
3. Modify students information
4. Delete students information
0. Quit system
=============================================
Please input your choice(0~4):
4
is in the process of the first 4 a choice
deal with deleteing......
Please input to be deleted the name of the students:aa
Name for aa classmates information has been deleted successfully
====Alumnni management information system
1. Increase students information
2. Find students information
3. Modify students information
4. Delete students information
0. Quit system
=============================================
Please input your choice(0~4):
2
is in the process of the first 2 a choice
deal with querying......
Please input to change the name of the students:aa
I'm sorry, name for aa classmates haven't login in the alumni
====Alumnni management information system
1. Increase students information
2. Find students information
3. Modify students information
4. Delete students information
0. Quit system
=============================================
Please input your choice(0~4):
0
is in the process of the first 0 a choice
Welcome to use this system again, goodbye!
第二次迭代增量1:增加了do_list_all 函数 列出所有同学信息
code:https://github.com/lujinjianst/myNCCL/blob/master/practices/Alumni-management-information-system/version2.1.c
运行结果;
====Alumnni management information system
1. Increase students information
2. Find students information
3. Modify students information
4. Delete students information
5. List all students information
0. Quit system
=============================================
Please input your choice(0~5):
1
is in the process of the first 1 a choice
deal with increseing......
name:a
address:b
telephone:12
Uint:c
Increase student success
====Alumnni management information system
1. Increase students information
2. Find students information
3. Modify students information
4. Delete students information
5. List all students information
0. Quit system
=============================================
Please input your choice(0~5):
5
is in the process of the first 5 a choice
The classmate alumni have 1 student information:
===============================================================
name:a address:b telephone:12 work unit:c
===============================================================
第二次迭代增量2:增加了初始化init
code:https://github.com/lujinjianst/myNCCL/blob/master/practices/Alumni-management-information-system/version2.2.c
====Alumnni management information system
1. Increase students information
2. Find students information
3. Modify students information
4. Delete students information
5. List all students information
0. Quit system
=============================================
Please input your choice(0~5):
2
is in the process of the first 2 a choice
deal with querying......
Please input to change the name of the students:a
You find classmate information below:
name:a address:HLJ telephone:0452-12345678 work unit:software engineering
====Alumnni management information system
1. Increase students information
2. Find students information
3. Modify students information
4. Delete students information
5. List all students information
0. Quit system
=============================================
Please input your choice(0~5):
5
is in the process of the first 5 a choice
The classmate alumni have 2 student information:
===============================================================
name:a address:HLJ telephone:0452-12345678 work unit:software engineering
===============================================================
name:b address:SH telephone:0452-24244355 work unit:computer
===============================================================
****相信大家从前面几个版本会有疑惑, 关闭终端后数据消失了, 那做个有什么意义呢? 当你有这样的疑惑时说明你认真去做了,接下来这个版本将解决这个问题, 将文件IO操作引入进来。
第三次迭代: v3.0 功能:用文件存储同学录信息(完整的增,删,改,查功能)
得先touch 一个文件tx1.txt,否则有段错误。
code:https://github.com/lujinjianst/myNCCL/blob/master/practices/Alumni-management-information-system/version3.0.c
*****大家现在看起来这个代码已经没什么问题 了,其实不然, 因为数组的局限性, 数组大小固定了, 不能根据需要而动态增长, 所以现在以动态链表的形式实现在内存中的存储。
第四次迭代: 用文件存储同学录信息(链表实现)
遇到个段错误 在init函数倒数第四行tail->next = NULL 应该改成p->next = NULL。
code:https://github.com/lujinjianst/myNCCL/blob/master/practices/Alumni-management-information-system/version4.0.c
为了方便看我把框架代码放在这里:
#include <stdio.h>#include <stdlib.h>#define INSERT 1#define QUERY 2#define UPDATE 3#define DELETE 4#define QUIT 0 void show_menu();void do_choice(int);int get_choice();void do_quit();void do_insert();void do_update();void do_query();void do_delete();int main(int argc, const char *argv[]){int choice;while (1){//1.display the main menushow_menu();//2.retrieve the user opitionchoice = get_choice();//3.According to the function of the corresponding choice of implementationdo_choice(choice);system("pause>nul");}return 0;}void show_menu(){system("clear");printf("====Alumnni management information system\n");printf("\t1. Increase students information\n");printf("\t2. Find students information\n");printf("\t3. Modify students information\n");printf("\t4. Delete students information\n");printf("\t0. Quit system\n");printf("=============================================\n");printf("Please input your choice(0~4):\n");}void do_quit(){printf("\n Welcome to use this system again, goodbye!\n");exit(0);}void do_insert(){printf("deal with increseing......\n");}void do_update(){printf("deal with modifying......\n");}void do_query(){printf("deal with querying......\n");}void do_delete(){printf("deal with deleteing......\n");}int get_choice(){int choice;scanf("%d", &choice);return choice;}void do_choice(int choice){printf("is in the process of the first %d a choice \n", choice);switch (choice){case INSERT :do_insert();break;case QUERY:do_query();break;case UPDATE:do_update();break;case DELETE:do_delete();break;case QUIT:do_quit();break;default:break;}}/* version2.0*/#include <stdio.h>#include <stdlib.h>#include <string.h>#define INSERT 1#define QUERY 2#define UPDATE 3#define DELETE 4#define QUIT 0//新增加的机构体来存放同学信息typedef struct{char name[100];//students' namechar addr[100];//students' addresschar phone[100];//students' telephonechar workfor[100];//work unit} TX;TX txl[100];// An array of alumni record, Up to one hundred studentsint last = 0;//The current number of alumnivoid show_menu();void do_choice(int);int get_choice();void do_quit();void do_insert();void do_update();void do_query();void do_delete();int main(int argc, const char *argv[]){int choice;while (1){//1.display the main menushow_menu();//2.retrieve the user opitionchoice = get_choice();//3.According to the function of the corresponding choice of implementationdo_choice(choice);//Sleep 5 sec, let the user see clearlysleep(3);//system("pause>nul");}return 0;}void show_menu(){system("clear");printf("====Alumnni management information system\n");printf("\t1. Increase students information\n");printf("\t2. Find students information\n");printf("\t3. Modify students information\n");printf("\t4. Delete students information\n");printf("\t0. Quit system\n");printf("=============================================\n");printf("Please input your choice(0~4):\n");}void do_quit(){printf("\n Welcome to use this system again, goodbye!\n");exit(0);}void do_insert(){printf("deal with increseing......\n");printf("name:");scanf("%s", &txl[last].name);printf("address:");scanf("%s", &txl[last].addr);printf("telephone:");scanf("%s", &txl[last].phone);printf("Uint:");scanf("%s", &txl[last].workfor);printf("Increase student success\n");last++; // increase a student success , increased 1.}void do_update(){char tname[100]; //Temporary storage input name.int i;int find = 0; //Whether the student find.printf("deal with modifying......\n");printf("Please input to change the name of the students:");scanf("%s", &tname);for (i = 0; i < last && !find; i++){if (!strcmp(tname, txl[i].name)){find = 1;printf("You find classmate information below:\n");printf("name:%s\t", txl[i].name);printf("address:%s\t", txl[i].addr);printf("telephone:%s\t", txl[i].phone);printf("work unit:%s\t", txl[i].workfor);printf("\n Please modify:\n");printf("name:");scanf("%s", &txl[i].name);printf("address:");scanf("%s", &txl[i].addr);printf("telephone:");scanf("%s", &txl[i].phone);printf("Uint:");scanf("%s", &txl[i].workfor);}}if (!find){printf("I'm sorry, name for %s classmates haven't login in the alumni\n", tname);}else{printf("Name for %s classmates information has been modified successfully\n", tname);}}void do_query(){char tname[100]; //Temporary storage input name.int i;int find = 0; //Whether the student find.printf("deal with querying......\n");printf("Please input to change the name of the students:");scanf("%s", &tname);for (i = 0; i < last && !find; i++){if (!strcmp(tname, txl[i].name)){find = 1;printf("You find classmate information below:\n");printf("name:%s\t", txl[i].name);printf("address:%s\t", txl[i].addr);printf("telephone:%s\t", txl[i].phone);printf("work unit:%s\t\n", txl[i].workfor);}}if (!find){printf("I'm sorry, name for %s classmates haven't login in the alumni\n", tname);}}void do_delete(){char tname[100]; //Temporary storage to delete students' name.int i;int find = 0; //Whether the student find.int index; //Record to be deleted in students of the array indexprintf("deal with deleteing......\n");printf("Please input to be deleted the name of the students:");scanf("%s", &tname);for (i = 0; i < last && !find; i++){if (!strcmp(tname, txl[i].name)){find = 1;index = i; //Storage to delete classmate subcript positionbreak;}}if (!find){printf("I'm sorry, name for %s classmates haven't login in the alumni\n", tname);}else{for (i = index; i <= last; i++){strcpy(txl[i].name, txl[i+1].name);strcpy(txl[i].addr, txl[i+1].addr);strcpy(txl[i].phone, txl[i+1].phone);strcpy(txl[i].workfor, txl[i+1].workfor);}printf("Name for %s classmates information has been deleted successfully\n", tname);}}int get_choice(){int choice;scanf("%d", &choice);return choice;}void do_choice(int choice){printf("is in the process of the first %d a choice \n", choice);switch (choice){case INSERT :do_insert();break;case QUERY:do_query();break;case UPDATE:do_update();break;case DELETE:do_delete();break;case QUIT:do_quit();break;default:break;}}