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

📄 11.cpp

📁 利用顺序表完成一个班级的一个学期的所有课程的管理
💻 CPP
字号:
#define ERROR 0
#define OK 1
#include <stdio.h>
#include <string.h>
#include <conio.h>
typedef struct STU
{int num;
  char name[20];
  int wuli;
  int shuxue;
}stud;
typedef struct LIST
{ stud stu[50];
  int length;
}list;
list L;
void printlist(list L)        
{
  int i;
  printf("num    name   wuli   shuxue\n");
  for(i=0;i<L.length;i++)
	  printf("%d   %s   %d   %d\n",L.stu[i].num,L.stu[i].name,L.stu[i].wuli,L.stu[i].shuxue);
  printf("\n");
}
int listinsert(struct LIST *Li,int i,struct STU e)     
{
  struct STU *p,*q;
  if (i<1||i>Li->length+1)
	return ERROR;
  else
   {
	q=&(Li->stu[i-1]);
	for(p=&Li->stu[Li->length-1];p>=q;p--)
	   *(p+1)=*p;
	*q=e;
	Li->length++;
	return OK;
   }
}
int listdel(struct LIST *Li,int i)               
{
  struct STU *p,*q;
  int k;
  for(k=0;Li->stu[k].num!=i&&k<Li->length;k++);      
  if(k==Li->length)
	{
	 printf("\nERROR!\n");
	 return ERROR;
	}
  else
   {
	q=&(Li->stu[Li->length-1]);
	for(p=&Li->stu[k];p<=q;p++)        
	   *p=*(p+1);
	Li->length--;
	return OK;
   }
}                                     
void creatlist(int m)             
{
  int i;
  for(i=0;i<m;i++)
  { printf("please input the %dth student's information:\n",i+1);
	printf("num=");
	scanf("%d",&L.stu[i].num);
	printf("name=");
	scanf("%s",&L.stu[i].name);
	printf("wuli=");
	scanf("%d",&L.stu[i].wuli);
	printf("shuxue=");
	scanf("%d",&L.stu[i].shuxue);
	L.length++;
  }
}
main()
{
  int n,m,i,k,b,c;
  struct STU e;
  L.length=0;
  printf("please input student's number of your class:");
  scanf("%d",&n);
  creatlist(n);8;
  label:printf("please select:\n");
  printf("1. insert one student's information!\n");
  printf("2. delete one student's information!\n");
  printf("3. exit!\n");
  scanf("%d",&m);
  switch(m)           
  {
   case 1:
	  printf("\nplease input the student's information"
		   " of you want to insert:\n");
	  printf("num=");
	  scanf("%d",&e.num);
	  printf("name=");
	  scanf("%s",&e.name);
	  printf("wuli=");
	  scanf("%d",&e.wuli); 
	  printf("shuxue=");
	  scanf("%d",&e.shuxue);
	  printf("\nplease input insert area:");
	  scanf("%d",&c);
	  listinsert(&L,c,e);    
	  printlist(L);           
	  printf("List length now is  %d.\n\n",L.length);
          goto label;
	  break;
	case 2:
	  printf("\nplease input the student's num"
		   " of you want to delete:\n");
	  printf("num=");
	  scanf("%d",&k);
	  listdel(&L,k);   
	  printlist(L);    
	  printf("List length now is  %d.\n\n",L.length);
	  goto label;
          break;
	  default: break;
	}
   }

⌨️ 快捷键说明

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