您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關使用C語言怎么實現一個學生選課系統,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
C語言是一門面向過程的、抽象化的通用程序設計語言,廣泛應用于底層開發,使用C語言可以以簡易的方式編譯、處理低級存儲器。
代碼:
#include<stdio.h> #include<windows.h> #include<stdlib.h> #include<conio.h> typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; #define CLASS_CLS system("cls") #define CLASS_NAME 80 typedef struct class { char name[CLASS_NAME]; /* 課程名稱 -- 唯一性 */ uint32_t nature; /* 課程性質(必修或者選修) */ uint32_t total_period; /* 課程總學時 */ uint32_t teach_period; /* 授課學時 */ uint32_t exper_period; /* 上機學時 */ uint32_t start_time; /* 課程開始時間 */ uint8_t score; /* 課程學分 */ uint8_t is_exsit; /* 課程是否存在 */ struct class *next; } class_t; // 課程結構體 class_t *head = NULL; static uint32_t count = 1; void play(char *text, int display, int time, int nu) //動畫打印 { CLASS_CLS; int i, len; for(i = 0; i <= nu; i++) { printf("\n"); } for(i = 0; i < 25; i++) { printf(" "); } len = strlen(text); for(i = 0; i < len; i++) { printf("%c", text[i]); Sleep(display); } Sleep(time); } void titile(char *text, char *str) { CLASS_CLS; uint8_t i; for(i = 0; i < 25; i++) { printf(" "); } printf("%s\n", text); for(i = 0; i <= 60; i++) { printf("%s", str); } printf("\n"); } void menu(void) { titile("【學生選課系統】", "-"); printf("\n\t|-----------------------------------|"); printf("\n\t| [1]--增加課程 |"); printf("\n\t| [2]--瀏覽課程 |"); printf("\n\t| [3]--查詢課程 |"); printf("\n\t| [4]--刪除課程 |"); printf("\n\t| [5]--修改課程 |"); printf("\n\t| [Q]--退出系統 |"); printf("\n\t|-----------------------------------|"); } void get_bat_data(void) { class_t *point, *q; uint32_t count = 0; FILE *fp = fopen("c:\\student_elective.dat", "rb"); rewind(fp); point = (class_t *)malloc(sizeof(class_t)); head = point; while(!feof(fp)) { count++; fread(point, sizeof(class_t), 1, fp); point->next = (class_t *)malloc(sizeof(class_t)); q = point; point = point->next; } q->next = NULL; fclose(fp); } void save_bat_data(void) { class_t *point = head; FILE *fp = fopen("c:\\student_elective.dat", "w+"); while(NULL != point) { count++; fwrite(point, sizeof(class_t), 1, fp); point = point->next; } fclose(fp); } uint32_t num_check(void) { char ch; uint32_t sum = 0; while(1) { ch = getch(); if('\n' == ch || '\r' == ch) { return sum; } else if('\b' == ch) { sum /= 10; printf("\b \b"); } else if(('0' <= ch) && ('9' >= ch)) { sum *= 10; sum += ch - '0'; printf("%d", ch - '0'); } } } void create(void) { class_t *point, *q; char tmp[CLASS_NAME], ch; uint8_t flag = 0; while(1) { if(1 != count) { printf("是否繼續增加課程(y/n):"); gets(tmp); if(strcmp(tmp, "n") == 0) { break; } } point = (class_t *)malloc(sizeof(class_t)); point->is_exsit = 0; printf("\n====請輸入第%d個選修課程信息====\n", count); printf("選擇課程名稱:"); gets(point->name); q = head; while(NULL != q) { if(strcmp(q->name, point->name) == 0) { flag = 1; printf("課程名稱重復或者不合格,請重新輸入...\n"); break; } q = q->next; } if(1 == flag) { continue; } printf("課程性質:"); printf("\n[B]--【必修】 [X]--【選修】"); while(1) { ch = getch(); if(ch == 'b' || ch == 'B') { point->nature = 1; break; } if(ch == 'x' || ch == 'X') { point->nature = 2; break; } } printf("\n輸入總學時:(只接受數字!)"); point->total_period = num_check(); printf("\n輸入授課學時:(只接受數字!)"); point->teach_period = num_check(); printf("\n輸入上機學時:(只接受數字!)"); point->exper_period = num_check(); printf("\n輸入本課程學分:(只接受數字!)"); point->score = num_check(); printf("\n輸入開課學期:(只接受數字!)"); point->start_time = num_check(); point->is_exsit = 1; point->next = head; head = point; count++; } printf("信息錄入完畢,按任意鍵繼續……"); getch(); } void display(void) { class_t *point = head; CLASS_CLS; titile("【查看課程】", "-"); printf("\n名稱 \t性質\t總學時\t授課學時\t上機學時\t學分\t開課學期"); while(NULL != point) { if(1 == point->is_exsit) { printf("\n%-14s ", point->name); if(1 == point->nature) { printf("必修課"); } else { printf("選修課"); } printf(" %d時 %d時 %d時 %d分 %d時", point->total_period, point->teach_period, point->exper_period, point->score, point->start_time); } point = point->next; } getch(); } // 對照學生管理系統自行拓展 void search(void) { } void modify(void) { } void delete(void) { } int main(void) { uint8_t value; uint8_t movie = 1; char choice[3]; FILE *fp = fopen("c:\\student_elective.dat", "a"); fclose(fp); system("color 30"); system("mode con:cols=100 lines=35"); system("title 【選修課系統】"); if(1 == movie) { play("歡迎使用【選修課系統】", 80, 1500, 10); } while(1) { CLASS_CLS; menu(); do { gets(choice); value = atoi(choice); } while((value > 12) || (value < 0)); switch(value) { case 1: create(); break; case 2: display(); break; case 3: search(); break; case 4: modify(); break; case 5: delete(); break; case 6: save_bat_data(); break; case 7: get_bat_data(); break; case 8: exit(1); break; default: break; } } return 0; }
以上就是使用C語言怎么實現一個學生選課系統,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。