📄 5-12.c
字号:
/*-------------------The expert system shell -------------------------*/
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "process.h"
/*-------------------main program ------------------------------------*/
/* the struct of the fact base */
struct fac
{
char fname[80];
char rela[5];
int ftype;
union VALUE
{
char progn[20];
float fltvb;
}fvalue;
struct fac *fnext;
struct fac *fprv;
}fact;
/* the struct of the rule */
struct prim
{
char if_name[80];
char if_rela[5];
int if_type;
union VALUE if_value;
struct prim *if_nxt;
}* ift;
struct action
{
char then_name[80];
char then_rela[5];
int then_type;
union VALUE then_values;
}* thent;
struct rul
{
struct prim *ift;
struct action *thent;
}rul;
struct rul rule[50];
void help(), dos_shell(), editor(), compiler(), reasoning();
/*------------------------------the main program ----------------------------*/
main()
{
for(;;)
{
loop: system("cls");
switch(menu_select())
{
case 1: editor(); /*Edit the knowledge base */
break;
case 2: compiler(); /*Compile the KB */
break;
case 3: reasoning(); /*Reasoning */
break;
case 4: dos_shell();
/*Exit to dos and enter "exit" to return */
break;
case 5: help(); /*Help message */
break;
case 6: exit(0);
}
}
}
/*-------------------interface of data base --------------------*/
/*人机界面:用户与专家系统交互的接口*/
int menu_select()
{
char s[80];
int c;
puts("\n\n\t * * * The expert system * * *\n");
puts("\t\t1. Editing Knowledge Base \n");
puts("\t\t2. Compiling Knowledge Base \n");
puts("\t\t3. Reasoning \n");
puts("\t\t4. Dos shell (Exit to return) \n");
puts("\t\t5. Help \n");
puts("\t\t6. Exit to dos \n");
puts("\n\t***********************************");
do
{
printf("\n Enter your choice: ");
gets(s);
c=atoi(s);
}while(c<=0||c>6);
return c;
}
void dos_shell()
{
/*---------------------do dos shell ----------------*/
system("cls");
system("");
}
void help()
{
/*------------------Help message------------------------*/
system("cls");
puts("**************************************************");
puts("The expert system shell");
puts("This expert system shell (ESS) include 6 parts: ");
puts("Interface, Editor, Compiler, Inference Engine ");
puts("and Working Memory. Select one part of the ");
puts("menu to do the thing which you want, but before");
puts(" you do the reasoning, you must edit the KB and ");
puts("compile it.");
puts("**************************************************");
puts("Enter to return");
getch();
}
void editor()
{
int ctr=0, j=0, c=100;
FILE *fp;
char p[30][40], filename[20], s[80];
do
{
system("cls");
puts("\n\t************Editor*****************\n");
puts("\t1. Edit 2. List\n");
puts("\t3. Save 4. Quit\n");
puts("\t-----------------------------------------------------\n");
printf("Enter your choice:");
gets(s);
c=atoi(s);
switch(c)
{
case 1:
{
……
break;
}
case 2:
{
……
break;
}
case 3:
{
……
break;
}
case 4:
goto loop;
}
} while(c>0||c<4);
return;
}
void compiler()
{
……
}
void reasoning()
{
……
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -