国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

學(xué)生管理系統(tǒng)——C語言單鏈表結(jié)構(gòu)存儲(chǔ)

這篇具有很好參考價(jià)值的文章主要介紹了學(xué)生管理系統(tǒng)——C語言單鏈表結(jié)構(gòu)存儲(chǔ)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

一、設(shè)計(jì)內(nèi)容

學(xué)生管理系統(tǒng),是用c語言程序設(shè)計(jì)的一款簡(jiǎn)便軟件項(xiàng)目,能對(duì)學(xué)生信息進(jìn)行增刪查改、排序、導(dǎo)入、導(dǎo)出,使用鏈表的結(jié)構(gòu)存儲(chǔ)。

二、功能需求

1.學(xué)生信息批量錄入;
2.查詢所有學(xué)生信息;
3.通過學(xué)號(hào)刪除學(xué)生信息;
4.通過學(xué)號(hào)、姓名查詢學(xué)生信息;
5.通過學(xué)號(hào)修改學(xué)生信息;
6.在表中某個(gè)位置插入學(xué)生信息;
7.導(dǎo)出學(xué)生信息文件;
8、導(dǎo)入學(xué)生信息表;
9.按學(xué)號(hào)、年齡排序;

三、單鏈表數(shù)據(jù)結(jié)構(gòu)定義

// 存儲(chǔ)學(xué)生的鏈表
typedef struct //定義每個(gè)人員信息結(jié)構(gòu)體
{
  long int number;   //學(xué)號(hào)
  char name[50];     //姓名
  int age;           //年齡
  char sex[20];      //性別
  char birthday[50]; // 出生年月
  char addres[50];   //地址
  char phoneNum[50]; //電話
  char email[40];    // 郵箱
} DataType;

typedef struct link_stu // 定義鏈表
{
  DataType stuInfo;
  struct link_stu *next; // 指向下一個(gè)學(xué)生數(shù)據(jù)
} ListNode;

四、系統(tǒng)功能模塊

1.創(chuàng)建學(xué)生表批量錄入學(xué)生信息

ListNode *create()
{
  int i;
  ListNode *s, *r, *Ls = (ListNode *)malloc(sizeof(ListNode));
  Ls->next = NULL;
  r = Ls; //尾節(jié)點(diǎn)

  printf("請(qǐng)輸入學(xué)生人數(shù):");
  scanf("%d", &num);
  for (i = 1; i <= num; i++)
  {
    s = (ListNode *)malloc(sizeof(ListNode)); // 新建學(xué)生結(jié)點(diǎn)
    printf("請(qǐng)輸入第%d個(gè)學(xué)生\n", i);
    printf("學(xué)號(hào):");
    scanf("%ld", &s->stuInfo.number);
    printf("姓名:");
    scanf("%s", &s->stuInfo.name);
    printf("年齡:");
    scanf("%d", &s->stuInfo.age);
    printf("性別:");
    scanf("%s", &s->stuInfo.sex);
    printf("出生年月:");
    scanf("%s", &s->stuInfo.birthday);
    printf("地址:");
    scanf("%s", &s->stuInfo.addres);
    printf("電話:");
    scanf("%s", &s->stuInfo.phoneNum);
    printf("郵箱:");
    scanf("%s", &s->stuInfo.email);

    s->next = Ls->next;
    Ls->next = s;
  }
  printf("錄入結(jié)束,請(qǐng)按任意鍵結(jié)束!\n");
  getch();
  return Ls;
}

2.查詢所有學(xué)生信息

// 查詢所有學(xué)生信息
void searchAll(ListNode *L)
{
  ListNode *p = L->next;
  if (p == NULL)
  {
    printf("學(xué)生表為空,請(qǐng)先創(chuàng)建學(xué)生表,按任意鍵繼續(xù)!\n");
    getch();
  }
  else
  {

    printf("———————————————————所有學(xué)生信息———————————————————————————————————————————\n");
    printf("|   學(xué)號(hào)    姓名    年齡   性別     出生年月    地址      電話       郵箱  |\n");
    printf("————————————————————————————————————————————————————————————————————————\n");
    while (p != NULL)
    {

      printf("%6ld  %6s   %5d  %5s %9s %9s %9s %9s\n", p->stuInfo.number, p->stuInfo.name, p->stuInfo.age,
             p->stuInfo.sex, p->stuInfo.birthday, p->stuInfo.addres, p->stuInfo.phoneNum,p->stuInfo.email);
      p = p->next;
    }
    printf("顯示結(jié)束,請(qǐng)按任意鍵繼續(xù)!\n");
    getch();
  }
}

3.通過學(xué)號(hào)刪除學(xué)生信息

//根據(jù)學(xué)號(hào)刪除學(xué)生信息
ListNode *deleNode(ListNode *head)
{

  ListNode *v1, *v2;
  long number;
  if (head == NULL)
  {
    printf("您操作的通訊錄此時(shí)為空,不能進(jìn)行刪除操作!");
  }
  printf("請(qǐng)輸入要?jiǎng)h除的學(xué)生的學(xué)號(hào):");
  scanf("%ld", &number);

  for (v2 = v1 = head; v1 != NULL;)
  {
    if (v1->stuInfo.number == number)
    {
      if (head->stuInfo.number == number) //對(duì)頭指針特殊處理
      {
        v1 = head;
        head = head->next;
        free(v1);
        printf("該學(xué)生已成功刪除!\n");
        v2 = v1 = head;
        return head;
      }
      else
      {
        v2->next = v1->next;
        free(v1);
        v1 = v2->next;
        printf("該學(xué)生已成功刪除!\n");
        return head;
      }
    }
    else
    {
      v2 = v1;
      v1 = v1->next;
    }
  }
  printf("你要?jiǎng)h除的學(xué)生不存在\n\n");
  return head;
}

4.通過學(xué)號(hào)、姓名查詢學(xué)生信息

// 根據(jù)學(xué)號(hào)、姓名查詢學(xué)生信息
void seleById(ListNode *head_linkman)
{
  ListNode *p1, *p2;
  char name[20];
  long number;
  int nM, num;
  if (head_linkman == NULL)
  {
    printf("您操作的學(xué)生表此時(shí)為空,不能進(jìn)行查詢操作!");
  }
  p1 = head_linkman;
  nM = 0;
  if (p1 != NULL)
  {

    
    printf("1.選擇學(xué)號(hào)查詢\n");
    printf("2.選擇姓名查詢\n");
    printf("請(qǐng)輸入查詢方式:\n");
    scanf("%d", &num);
    if (num == 1)
    {
      printf("請(qǐng)輸入要查詢的學(xué)生的學(xué)號(hào):");
      scanf("%ld", &number);
    }
    else if (num == 2)
    {
      printf("請(qǐng)輸入要查詢的學(xué)生的姓名:");
      scanf("%s", &name);
    }
    else
    {
      printf("輸入無效??!");
    }

    while (p1->stuInfo.number != number && p1->next != NULL)
    {
      p1 = p1->next;
    }
    if (p1->stuInfo.number == number || strcmp(p1->stuInfo.name, name) == 0)
    {
      nM++;
      printf("———————————————————所有學(xué)生信息———————————————————————————————————————————\n");
      printf("|   學(xué)號(hào)    姓名    年齡   性別     出生年月    地址      電話       郵箱  |\n");
      printf("————————————————————————————————————————————————————————————————————————\n");
      printf("%6ld  %6s   %5d  %5s %9s %9s %9s %9s\n", p1->stuInfo.number, p1->stuInfo.name, p1->stuInfo.age,
            p1->stuInfo.sex, p1->stuInfo.birthday, p1->stuInfo.addres, p1->stuInfo.phoneNum,p1->stuInfo.email);
    }

    if (nM == 0)
    {
      printf("該學(xué)生未錄入!\n");
    }
    printf("顯示結(jié)束,請(qǐng)按任意鍵繼續(xù)!\n");
    getch();
  }
    
}

5.通過學(xué)號(hào)修改學(xué)生信息

// 根據(jù)學(xué)號(hào)修改學(xué)生信息
void updata(ListNode *L)
{

  ListNode *p;
  long number;
  int nM;
  if (L == NULL)
  {
    printf("您操作的學(xué)生表此時(shí)為空,不能進(jìn)行修改操作!");
  }
  p = L;

  if (p != NULL)
  {

    printf("請(qǐng)輸入要修改的學(xué)生的學(xué)號(hào):");
    scanf("%ld", &number);
    while (p->stuInfo.number != number && p->next != NULL)
    {
      p = p->next;
    }
    if (p->stuInfo.number == number)
    {
      printf("姓名:");
      scanf("%s", &p->stuInfo.name);
      printf("年齡:");
      scanf("%d", &p->stuInfo.age);
      printf("性別:");
      scanf("%s", &p->stuInfo.sex);
      printf("出生年月:");
      scanf("%s", &p->stuInfo.birthday);
      printf("地址:");
      scanf("%s", &p->stuInfo.addres);
      printf("電話:");
      scanf("%s", &p->stuInfo.phoneNum);
      printf("郵箱:");
      scanf("%s", &p->stuInfo.email);
      printf("修改成功!\n");
    }

    printf("顯示結(jié)束,請(qǐng)按任意鍵繼續(xù)!\n");
    getch();
  }
}

6.查找第i個(gè)節(jié)點(diǎn)的存放地址

// 查找第i個(gè)節(jié)點(diǎn)的存放地址
ListNode *find(ListNode *head, int i)
{

  int j = 0;
  ListNode *p = head;
  if (i < 0)
  {
    printf("\n帶頭結(jié)點(diǎn)的單鏈表中不存在第%d個(gè)結(jié)點(diǎn)!\n", i);
    return NULL;
  }
  else if (i == 0)
    return p;         /*此時(shí)p指向的是頭結(jié)點(diǎn)*/
  while (p && i != j) /*沒有查找完并且還沒有找到*/
  {
    p = p->next;
    j++; /*繼續(xù)向后(左)查找,計(jì)數(shù)器加1*/
  }
  return p; /*返回結(jié)果,i=0時(shí),p指示的是頭結(jié)點(diǎn)*/
}

7.表中某個(gè)位置插入學(xué)生信息

// 在第i個(gè)結(jié)點(diǎn)新增學(xué)生信息
ListNode *insert(ListNode *head)
{
  int i;
  printf("請(qǐng)輸入學(xué)生要插入位置:");
  scanf("%d", &i);
  ListNode *p, *q;
  q = find(head, i - 1); /*查找?guī)ь^結(jié)點(diǎn)的單鏈表中的第i個(gè)結(jié)點(diǎn)*/
                         /*i=0,表示新結(jié)點(diǎn)插入在頭結(jié)點(diǎn)之后,此時(shí)q指向的是頭結(jié)點(diǎn)*/
  if (!q)                /*沒有找到*/
  {
    printf("\n帶頭結(jié)點(diǎn)的單鏈表中不存在第%d個(gè)結(jié)點(diǎn)!不能插入!\n", i);
    return head;
  }
  p = (ListNode *)malloc(sizeof(ListNode)); /*為準(zhǔn)備插入的新結(jié)點(diǎn)分配空間*/
  printf("請(qǐng)輸入要插入位置%d學(xué)生信息\n", i);
  printf("學(xué)號(hào):");
  scanf("%ld", &p->stuInfo.number);
  printf("姓名:");
  scanf("%s", &p->stuInfo.name);
  printf("年齡:");
  scanf("%d", &p->stuInfo.age);
  printf("性別:");
  scanf("%s", &p->stuInfo.sex);
  printf("出生年月:");
  scanf("%s", &p->stuInfo.birthday);
  printf("地址:");
  scanf("%s", &p->stuInfo.addres);
  printf("電話:");
  scanf("%s", &p->stuInfo.phoneNum);
  printf("郵箱:");
  scanf("%s", &p->stuInfo.email);
  p->next = q->next; /*插入(1)*/
  q->next = p;       /*插入(2),當(dāng)i=0時(shí),由于q指向的是頭結(jié)點(diǎn),本語句等價(jià)于head>next=p */
  return head;
}

8.導(dǎo)出學(xué)生信息表文件

// 保存文件
void save(ListNode *hd)
{
  
  if (hd == NULL)
  {
    printf("鏈表為空,不能保存文件,請(qǐng)按任意鍵繼續(xù)!\n");
    getch();
  }
  else
  {
  	char filename[15];
	char type[] = ".txt";
	char all[15];
  	printf("請(qǐng)輸入保存的文件名:");
  	scanf("%s",filename);
    strcpy(all,filename);
    strcat(all,type);
    FILE *fp = fopen(all, "w");
    ListNode *p = hd->next;
    while (p != NULL)
    {
      fprintf(fp, "%ld %s %d %s %s %s %s %s\n", p->stuInfo.number, p->stuInfo.name, p->stuInfo.age, p->stuInfo.sex, 
      p->stuInfo.birthday, p->stuInfo.addres, p->stuInfo.phoneNum, p->stuInfo.email);
      p = p->next;
    }
    fclose(fp);
    printf("鏈表保存結(jié)束,請(qǐng)按任意鍵繼續(xù)!\n");
    getch();
  }
}

9.導(dǎo)入學(xué)生信息表

// 導(dǎo)入學(xué)生數(shù)據(jù)
ListNode *loadFile(ListNode *head)
{
  long int number;   //學(xué)號(hào)
  char name[50];     //姓名
  int age;           //年齡
  char sex[20];      //性別
  char birthday[50]; // 出生年月
  char addres[50];   //地址
  char phoneNum[50]; //電話
  char email[40];    // 郵箱
  FILE *fp;
  char filename[15];
  char type[] = ".txt";
  char all[15];
  printf("請(qǐng)輸入保存的文件名:");
  scanf("%s",filename);
  strcpy(all,filename);
  strcat(all,type);
  if ((fp = fopen(all, "r")) == NULL)
  {
    printf("文件打開失敗!\n");
    return head;
  }

  if (head == NULL || head->next == NULL)
  {                                              // 如果鏈表為空
    head = (ListNode *)malloc(sizeof(ListNode)); // 創(chuàng)建一個(gè)頭結(jié)點(diǎn)
    head->next = NULL;
  }

  ListNode *tail = head;
  while (tail->next != NULL)
  {
    tail = tail->next;
  }

  while (fscanf(fp, "%ld%s%d%s%s%s%s%s", &number, name, &age, sex, birthday, addres, phoneNum, email) != EOF)
  {
    ListNode *newNode = (ListNode *)malloc(sizeof(ListNode));
    newNode->stuInfo.number = number;
    strcpy(newNode->stuInfo.name, name);
    newNode->stuInfo.age = age;
    strcpy(newNode->stuInfo.sex, sex);
    strcpy(newNode->stuInfo.birthday, birthday);
    strcpy(newNode->stuInfo.addres, addres);
    strcpy(newNode->stuInfo.phoneNum, phoneNum);
    strcpy(newNode->stuInfo.email, email);
    newNode->next = NULL;

    if (tail == NULL)
    { // 如果鏈表為空,則將新節(jié)點(diǎn)作為頭節(jié)點(diǎn)
      tail = newNode;
      head->next = tail;
    }
    else
    {
      tail->next = newNode;
      tail = newNode;
    }
  }

  fclose(fp);
  printf("導(dǎo)入數(shù)據(jù)成功,請(qǐng)按任意鍵繼續(xù)!\n");
  getch();
  return head;
}

10.按學(xué)號(hào)、年齡排序

// 按學(xué)號(hào)或年齡排序
ListNode *Sort(ListNode *mylist, int num)
{

  if ((mylist->next == NULL) || (mylist->next->next == NULL))
  {
    return NULL;
  }

  ListNode *head, *pre, *cur, *next, *end, *temp;
  head = mylist;
  end = NULL;
  //從鏈表頭開始將較大值往后沉
  while (head->next != end)
  {
    for (pre = head, cur = pre->next, next = cur->next; next != end; pre = pre->next, cur = cur->next, next = next->next)
    {
      if (num == 1)
      { // num=1時(shí)按學(xué)號(hào)排序
        //相鄰的節(jié)點(diǎn)比較
        if (cur->stuInfo.number > next->stuInfo.number)
        {
          cur->next = next->next;
          pre->next = next;
          next->next = cur;
          temp = next;
          next = cur;
          cur = temp;
        }
      }
      if (num == 2)
      {
        if (cur->stuInfo.age > next->stuInfo.age)
        {
          cur->next = next->next;
          pre->next = next;
          next->next = cur;
          temp = next;
          next = cur;
          cur = temp;
        }
      }
    }
    end = cur;
  }
  return mylist;
}
  1. 主函數(shù)調(diào)用
void prin()
{
  printf("=====================================歡迎使用學(xué)生管理系統(tǒng)===============================\n");
  printf("||                                  1.創(chuàng)建學(xué)生表批量錄入學(xué)生信息                      ||\n");
  printf("||                                  2.查詢所有學(xué)生信息                                ||\n");
  printf("||                                  3.通過學(xué)號(hào)刪除學(xué)生信息                            ||\n");
  printf("||                                  4.通過學(xué)號(hào)、姓名查詢學(xué)生信息                      ||\n");
  printf("||                                  5.通過學(xué)號(hào)修改學(xué)生信息                            ||\n");
  printf("||                                  6.表中某個(gè)位置插入學(xué)生信息                        ||\n");
  printf("||                                  7.導(dǎo)出學(xué)生信息表文件                              ||\n");
  printf("||                                  8.導(dǎo)入學(xué)生信息表                                  ||\n");
  printf("||                                  9.按學(xué)號(hào)、年齡排序                                ||\n");
  printf("||                                  10.退出系統(tǒng)!                                     ||\n");
  printf("========================================================================================\n");
  printf("請(qǐng)選擇你的功能:");
}

void main()
{

  ListNode *ls = NULL;
  int number, num;
  while (1)
  {
	    prin();
	    scanf("%d", &number);
	    switch (number)
	    {
	    case 1: // 創(chuàng)建學(xué)生表批量錄入學(xué)生信息
		      ls = create();
		      break;
	    case 2: // 查詢所有學(xué)生信息
	          if (ls)
		      {
			        searchAll(ls);
		            break;
		      }
		      else
		      {
			        printf("學(xué)生表為空,請(qǐng)先創(chuàng)建學(xué)生表,按任意鍵繼續(xù)!\n");
			        break;
		      }
		      
	    case 3: // 通過學(xué)號(hào)刪除學(xué)生信息
		      if (ls)
		      {
			        ls = deleNode(ls);
			        break;
		      }
		      else
		      {
			        printf("學(xué)生表為空,請(qǐng)先創(chuàng)建學(xué)生表,按任意鍵繼續(xù)!\n");
			        break;
		      }
	    case 4: // 通過學(xué)號(hào)查詢學(xué)生信息
		      seleById(ls);
		      break;
	    case 5: // 通過學(xué)號(hào)修改學(xué)生信息;
		      if (ls)
		      {
			        updata(ls);
			        break;
		      }
		      else
		      {
			        printf("學(xué)生表為空,請(qǐng)先創(chuàng)建學(xué)生表,按任意鍵繼續(xù)!\n");
			        break;
		      }
	    case 6: // 第i個(gè)結(jié)點(diǎn)新增學(xué)生信息);
		      if (ls)
		      {
			        ls = insert(ls);
			        break;
		      }
		      else
		      {
			        printf("學(xué)生表為空,請(qǐng)先創(chuàng)建學(xué)生表,按任意鍵繼續(xù)!\n");
			        break;
		      }
	    case 7: // 導(dǎo)出文件
		      save(ls);
		      break;
	    case 8: // 導(dǎo)入文件
		      ls = loadFile(ls);
		      break;
	    case 9:
	    	  if(ls) {
		    	  printf("===========================================\n");
			      printf("1.按學(xué)號(hào)進(jìn)行排序\n");
			      printf("2.按年齡進(jìn)行排序\n");
			      printf("請(qǐng)選擇排序的方式\n");
			      scanf("%d", &num);
			      ls = Sort(ls, num);
			      printf("=================排序后的學(xué)生信息=================\n");
			      searchAll(ls);
			      break;
			  } else {
			  	  printf("學(xué)生表為空,請(qǐng)先創(chuàng)建學(xué)生表,按任意鍵繼續(xù)!\n");
			      break;
			  }
		     
	    case 10: // 退出系統(tǒng)!
		      printf("退出系統(tǒng)!");
		      exit(0);
	    default:
	          break;
    }
  }
}

Tip:該系統(tǒng)是數(shù)據(jù)庫(kù)結(jié)構(gòu)基于C語言的一個(gè)課堂實(shí)訓(xùn)有很多不足之處,看到這的小伙伴請(qǐng)自己注意哦!文章來源地址http://www.zghlxwxcb.cn/news/detail-784077.html

到了這里,關(guān)于學(xué)生管理系統(tǒng)——C語言單鏈表結(jié)構(gòu)存儲(chǔ)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包