由於不是計算機專業,一直對沒被要求寫過坑爹的「XXX管理系統」深表遺憾。ide
好吧。函數
機會來了。spa
選修課上寫的,野蠻暴力。code
小朋友請在家人指導下觀看。blog
1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <conio.h> 5 6 /********函數聲明******/ 7 8 void AddStudent(); 9 void Search_By_name(); 10 void Search_By_class(); 11 void Search_By_Age(); 12 void Search_By_class_And_age(); 13 void Print_By_Index(int i); 14 void PrintHelloWord(); 15 void clean(); 16 void Start(); 17 18 /********************/ 19 struct Student 20 { 21 char name[30]; 22 char phone[20]; 23 char address[100]; 24 int class_num; 25 int age; 26 }; 27 #define MaxSize 100 28 Student students[MaxSize]; 29 int current_size = 0; 30 int main() 31 { 32 33 34 35 36 Start(); //程序啓動 37 return 0; 38 39 } 40 void Search_By_name() // 返回該姓名對應索引 41 { 42 int i = 0; 43 int count = 0; 44 char name[100]; 45 printf("請輸入姓名"); 46 scanf("%s",name); 47 if(name) 48 { 49 for(i = 0;i < current_size;i++) 50 { 51 if(strcmp(students[i].name,name) == 0 ) 52 { 53 Print_By_Index(i); 54 count ++; 55 } 56 } 57 printf("總共有%d個學生",count); 58 getch(); 59 } 60 61 } 62 void Search_By_class() // 63 { 64 int num = -1; 65 int count = 0; 66 printf("請輸入班級號:"); 67 scanf("%d",&num); 68 if(num >= 1) 69 { 70 int i = 0; 71 for(i = 0;i < current_size;i++) 72 { 73 if(students[i].class_num == num) 74 { 75 Print_By_Index(i); 76 count ++; 77 } 78 } 79 printf("總共有%d位同窗",count); 80 getch(); 81 82 } 83 else 84 printf("輸入有誤"); 85 86 } 87 void Print_By_Index(int i) //打應索引爲i的學生信息 88 { 89 printf("姓名 = %s\n",students[i].name); 90 printf("電話 = %s\n",students[i].phone); 91 printf("地址 = %s\n",students[i].address); 92 printf("班級 = %d\n",students[i].class_num); 93 printf("年齡 = %d\n",students[i].age); 94 } 95 void Search_By_class_And_age() // 96 { 97 int class_num = -1; 98 int age_min = -1; 99 int age_max = -1; 100 printf("輸入要查詢的班級"); 101 scanf("%d",&class_num); 102 printf("輸入年齡下限"); 103 scanf("%d",&age_min); 104 printf("輸入年齡上限"); 105 scanf("%d",&age_max); 106 if((class_num > 0) && (age_max > age_min) && (age_max > 0) && (age_min > 0)) 107 { 108 int i = 0; 109 int count = 0; 110 for(i = 0;i < current_size;i++) 111 { 112 if(students[i].class_num == class_num && (students[i].age >= age_min && students[i].age <= age_max) ) 113 { 114 Print_By_Index(i); 115 count ++; 116 } 117 } 118 printf("總共有%d個學生",count); 119 getch(); 120 } 121 } 122 123 void clean()//清屏 124 { 125 system("cls"); 126 } 127 void PrintHelloWord() // 打印界面 128 { 129 int i = 0; 130 for(;i < 80;i++) 131 printf("*"); 132 printf("\n"); 133 134 int line = 7; 135 for(i = 0;i < line;i++) 136 { 137 int j = 0; 138 139 switch(i) 140 { 141 142 case 0: 143 printf("\t\t\t%10s\n\n","本系統功能以下"); 144 break; 145 case 1: 146 printf("\t%10s\n","[a] 添加學生信息"); 147 break; 148 case 2: 149 printf("\t%10s\n","[b] 經過姓名查信息"); 150 break; 151 case 3: 152 printf("\t%10s\n","[c] 找出班級人數及名單"); 153 break; 154 case 4: 155 printf("\t%10s\n","[d] 找出某年齡段人數及名單"); 156 break; 157 case 5: 158 printf("\t%10s\n","[e] 經過班級和年齡查找學生"); 159 break; 160 case 6: 161 printf("\t%10s\n","[f] 退出 "); 162 break; 163 } 164 165 } 166 for(;i < 87;i++) 167 printf("*"); 168 printf("\n\n"); 169 printf("請輸入您的選擇:"); 170 171 172 173 } 174 void AddStudent() //添加學生 175 { 176 if(current_size >= MaxSize - 1) 177 { 178 printf("名額已滿"); 179 getch(); 180 } 181 else 182 { 183 printf("請輸入學生姓名:"); 184 scanf("%s",students[current_size].name); 185 printf("請輸入電話號碼:"); 186 scanf("%s",students[current_size].phone); 187 printf("請輸入地址:"); 188 scanf("%s",students[current_size].address); 189 printf("請輸入班級:"); 190 scanf("%d",&students[current_size].class_num); 191 printf("請輸入年齡:"); 192 scanf("%d",&students[current_size].age); 193 current_size++; 194 } 195 printf("添加成功\n"); 196 getch(); 197 198 } 199 void Start() 200 { 201 202 203 char c = 0; 204 while(c != '#') 205 { 206 PrintHelloWord(); 207 scanf("%c",&c); 208 switch(c) 209 { 210 // 添加學生信息 211 case 'a': 212 AddStudent(); 213 break; 214 // 經過姓名查信息 215 case 'b': 216 Search_By_name(); 217 break; 218 //找出班級人數及名單 219 case 'c': 220 Search_By_class(); 221 break; 222 //找出某年齡段人數及名單 223 case 'd': 224 Search_By_Age(); 225 break; 226 //經過班級和年齡查找學生 227 case 'e': 228 Search_By_class_And_age(); 229 break; 230 case 'f': 231 c = '#'; 232 break; 233 default: 234 printf("您的輸入有誤\n"); 235 break; 236 } 237 //printf("按任意鍵繼續"); 238 //getch(); 239 clean(); 240 } 241 242 } 243 void Search_By_Age() 244 { 245 246 int age = -1; 247 248 printf("輸入年齡"); 249 scanf("%d",&age); 250 if(age > 0) 251 { 252 int i = 0; 253 int count = 0; 254 for(i = 0;i < current_size;i++) 255 { 256 if(students[i].age == age) 257 { 258 Print_By_Index(i); 259 count ++; 260 } 261 } 262 printf("總共有%d個學生",count); 263 getch(); 264 } 265 }