系统类程序的编写心得

来源:互联网 发布:图片文字复制软件 编辑:程序博客网 时间:2024/05/12 06:55

这里只讲面向过程的C语言代码编写。

首先,构建程序框架:

          1、明确程序要实现的操作(即函数),并查阅英语予以命名,整理成文档。

           2、预处理部分的编写,包括文件、宏常量

           3、对所有子函数进行声明

           4、编写主函数

           5、编写子函数

例:编写校友录系统,提供一下功能:1.增加同学 2.查找同学 3.修改同学 4.删除同学 5.退出系统。

第一步:整理成文档,构建程序框架

#include <stdio.h>#include <stdlib.h>#define QUIT    0#define INSERT  1#define MODIFY  2#define FIND    3#define DELETE  4void show_menu();int get_choice();void do_choice(int);void do_insert();void do_modify();void do_find();void do_delete();void do_quit();int main(int argc,char *argv[]){int choice;while(1){show_menu();choice=get_choice();do_choice(choice);}return 0;}void show_menu(){printf("This is a address book system !\n");printf("Please input choice number bettween '0'~'4'.\n");printf("0 : Quit system;\n");printf("1: Insert an entry;\n");printf("2: Modify an entry;\n");printf("3: Find an entry;\n");printf("4: Delete an entry;\n\n");printf("========================================\n");printf("Please input choice number bettween '0'~'4'.\n");}int get_choice(){int choice;scanf("%d",&choice);return choice;}void do_choice(int choice){switch(choice){case QUIT:do_quit();break;case INSERT:do_insert();break;case MODIFY:do_modify();break;case FIND:do_find();break;case DELETE:do_delete();break;default:break;}}void do_insert(){printf("is inserting an entry!\n");}void do_modify(){printf("is modifiing an entry!\n");}void do_find(){printf("is finding an entry!\n");}void do_delete(){printf("is deleting an entry!\n");}void do_quit(){printf("is quit the system, goodbey!\n");exit(0);}


0 0