1樓:
//stud_info.c
/****定義一個包含學生資訊(學號,姓名,成績)的連結串列,使其具有如下功能:
(1) 根據指定學生個數,逐個輸入學生資訊;
(2) 逐個顯示學生表中所有學生的相關資訊;
(3) 根據姓名進行查詢,返回此學生的學號和成績;
(4) 根據指定的位置可返回相應的學生資訊(學號,姓名,成績);
(5) 給定一個學生資訊,插入到表中指定的位置;
(6) 刪除指定位置的學生記錄;
(7) 統計表中學生個數。
*/#include
#include
#include
#define max_len 36
#pragma pack(1)
typedef struct stu_info
stu;
typedef struct lnode
stunode,*stulist;
#pragma pack()
//建立帶頭結點的學生連結串列
stulist create_stulist()
//輸入一個學生資訊並插入到學生連結串列當中(頭插法)
void input_stuinfo(stulist l)
//2. 逐個顯示學生表中所有學生的相關資訊
void show_studinfo(stulist l)
printf("\n************************ student info ************************\n");
while(s)
}//3. 根據姓名進行查詢,返回此學生的學號和成績(這裡就不考慮重名的問題了)
void find_stud_by_name(stulist l, const char *name)
while(s)
s = s->next;
}printf("i`m sorry, there is no %s student!\n\n", name);
}//7. 統計表中學生個數
int cal_stud_count(stulist l)
return count;
}//4. 根據指定的位置可返回相應的學生資訊(學號,姓名,成績)
void find_stud_by_location(stulist l, int loc)
int i=0;
int count = cal_stud_count(l);
if(loc > count || loc <= 0)
for(i=1; i<=count; ++i)
s = s->next;}}
//5. 給定一個學生資訊,插入到表中指定的位置
void insert_studinfo(stulist l, int loc)
else if(loc <= length && loc > 0)
else if(i == loc-1)
p = p->next;}}
else
printf("insert student info in %d location successfully.\n\n", loc);
}//6. 刪除指定位置的學生記錄
void delete_studinfo(stulist l, int loc)
else if(loc <= length && loc > 0)
else if(i == loc-1)
p = p->next;}}
else
printf("delete student info in %d location successfully.\n\n", loc);
}//銷燬連結串列
void destroy_stulist(stulist l)
free(l);
l = null;
}//清空連結串列
void clear_stulist(stulist l)
l->next = null;
}int main(int argc, char const *argv)
//1. 根據指定學生個數,逐個輸入學生資訊
printf("please enter the student`s number: ");
scanf("%d", &n);
printf("please enter %d students info:\n", n);
for (i = 0; i < n; ++i)
//2. 顯示學生連結串列的資訊
show_studinfo(l);
//3. 根據姓名進行查詢,返回此學生的學號和成績
printf("\nplease input student name: ");
scanf("%s", name);
find_stud_by_name(l, name);
//4. 根據指定的位置輸出相應的學生資訊
printf("\n請輸入你要查詢的學生的位置: ");
scanf("%d", &loc);
find_stud_by_location(l, loc);
//5. 給定一個學生資訊,插入到表中指定的位置
printf("\n請輸入你要插入的學生的位置: ");
scanf("%d", &loc);
insert_studinfo(l, loc);
show_studinfo(l);
//6. 刪除指定位置的學生記錄
printf("\n請輸入你要刪除的學生的位置: ");
scanf("%d", &loc);
delete_studinfo(l, loc);
show_studinfo(l);
//7. 統計表中學生人數
printf("\n學生人數: %d\n", cal_stud_count(l));
destroy_stulist(l);
return 0;
}//示例執行結果:
please enter the student`s number: 6
please enter 6 students info:
please input student number: 20191001
please input student name: aaaa
please input student score: 98
please input student number: 20191002
please input student name: bbbb
please input student score: 89
please input student number: 20191003
please input student name: cccc
please input student score: 82
please input student number: 20191004
please input student name: dddd
please input student score: 77
please input student number: 20191005
please input student name: eeee
please input student score: 68
please input student number: 20191006
please input student name: ffff
please input student score: 58
************************ student info ************************
stuno: 20191006 name: ffff score: 58.00
stuno: 20191005 name: eeee score: 68.00
stuno: 20191004 name: dddd score: 77.00
stuno: 20191003 name: cccc score: 82.00
stuno: 20191002 name: bbbb score: 89.00
stuno: 20191001 name: aaaa score: 98.00
please input student name: cccc
found it! stuno: 20191003 score: 82.00
請輸入你要查詢的學生的位置: 5
stuno: 20191002 name: bbbb score: 89.00
請輸入你要插入的學生的位置: 3
please input student number: 20191007
please input student name: gggg
please input student score: 100
insert student info in 3 location successfully.
************************ student info ************************
stuno: 20191006 name: ffff score: 58.00
stuno: 20191005 name: eeee score: 68.00
stuno: 20191007 name: gggg score: 100.00
stuno: 20191004 name: dddd score: 77.00
stuno: 20191003 name: cccc score: 82.00
stuno: 20191002 name: bbbb score: 89.00
stuno: 20191001 name: aaaa score: 98.00
請輸入你要刪除的學生的位置: 4
delete student info in 4 location successfully.
************************ student info ************************
stuno: 20191006 name: ffff score: 58.00
stuno: 20191005 name: eeee score: 68.00
stuno: 20191007 name: gggg score: 100.00
stuno: 20191003 name: cccc score: 82.00
stuno: 20191002 name: bbbb score: 89.00
stuno: 20191001 name: aaaa score: 98.00
學生人數: 6
c語言程式設計題如下圖所示,C語言程式設計題,如下圖,有誰知道?
include include int isprime int n else return r void outputprimefactor 1 int n else if over else void outputprimefactor 2 int n else printf d i output...
C語言問題C語言問題,C語言問題C語言問題
include include int main b k p b k 0 puts b return 0 c語言問題c語言問題 include int main int h,m scanf d d h,m printf s num h if m 0 else printf o clock print...
C語言問題,C語言問題C語言問題
這題考的是自動型別轉換,由編譯系統自動完成,轉換是 向上 靠的 舉個例子 include stdio.h void main 你編譯一下就會有警告 conversion from double to float possible loss of data 也就是說系統預設轉化了a,b的資料型別為do...