当前位置:编程学习 > 网站相关 >>

学生信息管理

[plain]  
#include <stdio.h>  
#include <malloc.h>  
#include <string.h>  
#define MaxSize 50  
#define TRUE 1  
#define FALSE 0  
typedef int BOOL;  
  
typedef struct student {  
  char num[9];  
  char name[9];  
  char sex[5];  
  float score;  
}student;  
  
typedef student T ;  
  
typedef struct {  
  int Size;  
  int MaxList;  
  T Element[MaxSize];  
}List;  
  
List* initial() {  
    List *lst;  
    lst=(List *)malloc(sizeof(List));  
    return lst;  
}  
  
void CreateList(List *lst, int maxsize) {  
   lst->Size = 0;  
   lst->MaxList = maxsize;  
}  
  
BOOL Append(List *lst,T x)  
{  
  if(lst->Size > lst->MaxList) {  
      printf("Out of Data!");  
      return FALSE;  
  }  
  strcpy(lst->Element[lst->Size].num, x.num);  
  
  strcpy(lst->Element[lst->Size].name, x.name);  
  
  strcpy(lst->Element[lst->Size].sex, x.sex);  
  
  lst->Element[lst->Size].score = x.score;  
  lst->Size++;  
  return TRUE;  
}  
  
BOOL IsFull(List* lst) {  
   if(lst->Size==lst->MaxList)  
        return TRUE;  
   else  
        return FALSE;  
}  
BOOL Insert(List* lst, int pos, T x)  
 {  
    int i;  
   if ( IsFull(lst)){  
       printf("Overflow"); return FALSE;  
   }  
   if ( pos<0 || pos > lst->Size){  
       printf("Out of Bounds");  
       return FALSE;  
    }  
   for ( i=lst->Size-1;  i>=pos;  i-- ) {  
       lst->Element[i+1] = lst->Element[i];  
   }  
  strcpy(lst->Element[pos].num, x.num);  //字符;  
  strcpy(lst->Element[pos].name, x.name);  
  strcpy(lst->Element[pos].sex, x.sex);  
  lst->Element[pos].score = x.score;  
   lst->Size++;  
   return TRUE;  
 }  
  
 BOOL Remove(List* lst, int pos) {  
    int i;  
    if(pos>=0 && pos <= lst->Size-1) {  
        for(i = pos; i < lst->Size-1; i++ ) {  
            lst->Element[i] = lst->Element[i+1];  
        }  
        lst->Size = lst->Size -1;  
    }  
    else {  
        printf("要删除的位置不合法!\n");  
    }  
    return 0;  
 }  
 BOOL Replace(List* lst, int pos, T x) {  
     if(pos >= 0 && pos <= lst->Size) {  
        lst->Element[pos] = x;  
        printf("替换成功!\n");  
     }  
     else {  
        printf("输入的信息不合法\n");  
     }  
     return 0;  
 }  
 void Find(List* lst, int pos) {  
    if(pos>=0 && pos <= lst->Size-1) {  
        printf("find it!\n");  
    }  
 }  
  
void output(List *lst, int j) {  
    printf("%-10s%-10s%-10s%6f\n",lst->Element[j].num, lst->Element[j].name, lst->Element[j].sex,lst->Element[j].score);  
}  
  
 void Loc(List* lst, char *a) {  
     int i;  
     for(i = 0; i < lst->Size-1; i++) {  
        if(!strcmp(lst->Element[i].num , a)) {  
            output(lst, i);break;  
        }  
     }  
 }  
  
void Show(List *lst) {  
  int i;  
  printf("数据表中记录条数为:%d\n",lst->Size);  
  printf("____________________________________________________________________\n");  
  for(i=0; i < lst->Size; i++) {  
      printf("%-10s%-10s%-10s%6f\n",lst->Element[i].num, lst->Element[i].name, lst->Element[i].sex,lst->Element[i].score);  
      printf("____________________________________________________________________\n");  
  }  
}  
  
void input( T*  stemp ) {  
    printf("学号:");  
    scanf("%s", stemp->num);  
    printf("姓名:");  
    scanf("%s", stemp->name);  
    printf("性别:");  
    scanf("%s", stemp->sex);  
    printf("成绩:");  
    scanf("%f", &stemp->score);  
}  
  
int main()  
{  
  List *L;  
  int i, pos, maxsize;  
  int loc = 0;  
  char sf;  
  char num[10];  
  T*  stemp;  
  stemp = (T *)malloc(sizeof(T));  
  L = initial();  
  maxsize = MaxSize;  
  
  CreateList(L, maxsize);  
  
  printf("请输入所选择的功能代码:\n");  
  printf("1-Append   2-Show   3-Insert  4-Remove  5-Replace \n");  
  printf("6-find  7-Locate 0-Exit\n&
补充:综合编程 , 其他综合 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,