⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ag.txt

📁 编制一个能够分析三种整数、标识符、主要运算符和主要关键字的词法分析程序。
💻 TXT
字号:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#define NUM 5

typedef struct cnode {
  char cname[16];
  int score;
  struct cnode *next;
} CNODE;                             /课程指针/

typedef struct {
  char name[20];
  CNODE *head;
} SNODE;                             /学生信息/

void initStuInfo(SNODE[]);
void inputCourseInfo(SNODE[],int No);
void outputInfo(SNODE[]);
void outScore(CNODE*);
int Menu();
void searchInfo(SNODE[]);
void renewInfo(SNODE[]);
void deleteInfo(SNODE[]);

void main()
{
  int i,n;
  SNODE s[NUM];

  clrscr();
  do
  {
    n=Menu();
    switch (n)
    {
      case 1:
	initStuInfo(s);
	for (i=0;i<NUM;i++)
	  inputCourseInfo(s,i);
	break;
      case 2:
	outputInfo(s);
	break;
      case 3:
	searchInfo(s);
	break;
      case 4:
	renewInfo(s);
	break;
      case 5:
	deleteInfo(s);
    }
  }
  while (n!=6);
}

int Menu()
{
  int n;
  char text[80];
  printf("==========Menu=========\n");
  printf("1:Input\n");
  printf("2:Output\n");
  printf("3:Search\n");
  printf("4:Renew\n");
  printf("5:Delete\n");
  printf("6:Exit\n");
  printf("Enter your choice:");
  do
  {
    gets(text);
    sscanf(text,"%d",&n);
    if (n<1||n>6) printf("Error!\n");
  }
  while (n<1||n>6);                           /?????????????????/
  return n;
}

void initStuInfo(SNODE s[])
{
  int i;

  printf("\nEnter information of %d students:\n",NUM);
  for (i=0;i<NUM;i++)
  {
    gets(s[i].name);
    s[i].head=NULL;
  }
}

void inputCourseInfo(SNODE s[],int No)
{
  char text[80],buf[40];
  int score,num,i;
  CNODE *c;

  printf("\nEnter course's number:");
  gets(text);
  sscanf(text,"%d",&num);

  printf("\nEnter course's name & score:\n");
  for (i=1;i<=num;i++)
  {
    gets(text);
    c=(CNODE*)malloc(sizeof(CNODE));
    sscanf(text,"%s%d",c->cname,&c->score);
    c->next=s[No].head;
    s[No].head=c;
  }
}

void outputInfo(SNODE s[])
{
  int i;

  for (i=0;i<NUM;i++)
  {
    printf("\n%12s:  ",s[i].name);
    outScore(s[i].head);
  }
  printf("\n");
}

void outScore(CNODE* head)
{
  CNODE *p;
  for (p=head;p!=NULL;p=p->next)
    printf("(%10s,%d)  ",p->cname,p->score);
  printf("\n");
}

void searchInfo(SNODE s[])
{
  char name[80];
  CNODE *p;
  int i;

  printf("\nPlease input the name of the student you want to search:\n");
  gets(name);
  printf("The score is:\n");
  for (i=0;i<NUM;i++)
    if (strcmp(name,s[i].name)==0) outScore(s[i].head);
  printf("\n");
}

void renewInfo(SNODE s[])
{
  CNODE* c;
  int No,i,num;
  char name[80],text[80];

  printf("\nPlease input the name of the student you want to search:\n");
  gets(name);
  printf("\nEnter course's number:");
  gets(text);
  sscanf(text,"%d",&num);
  for (i=0;i<NUM;i++)
    if (strcmp(name,s[i].name)==0) break;
  No=i;
  s[i].head=NULL;
  printf("\nEnter course's name & score:\n");
  for (i=1;i<=num;i++)
  {
    gets(text);
    c=(CNODE*)malloc(sizeof(CNODE));
    sscanf(text,"%s%d",c->cname,&c->score);
    c->next=s[No].head;
    s[No].head=c;
  }
}

void deleteInfo(SNODE s[])
{
  char text[80],name[80];
  int i,No;
  CNODE *p,*q;

  printf("\nPlease input the name of the student you want to search:\n");
  gets(name);
  for (i=0;i<NUM;i++)
  {
    if (strcmp(s[i].name,name)==0) break;
  }
  No=i;
  printf("Please input the name of the course you want to delete:\n");
  gets(name);
  for (p=s[No].head;p!=NULL;p=p->next)
    if (strcmp(name,p->cname)==0) break;
  if (p==NULL) { printf("Can't find!"); return; }
  for (q=s[No].head;q!=NULL;q=q->next)
    if (q->next==p) break;
  q->next=p->next;
  free(p);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -