您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關(guān)使用C語言怎么實(shí)現(xiàn)一個(gè)學(xué)生選課系統(tǒng),小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
C語言是一門面向過程的、抽象化的通用程序設(shè)計(jì)語言,廣泛應(yīng)用于底層開發(fā),使用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; /* 課程性質(zhì)(必修或者選修) */ uint32_t total_period; /* 課程總學(xué)時(shí) */ uint32_t teach_period; /* 授課學(xué)時(shí) */ uint32_t exper_period; /* 上機(jī)學(xué)時(shí) */ uint32_t start_time; /* 課程開始時(shí)間 */ uint8_t score; /* 課程學(xué)分 */ uint8_t is_exsit; /* 課程是否存在 */ struct class *next; } class_t; // 課程結(jié)構(gòu)體 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("【學(xué)生選課系統(tǒng)】", "-"); 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]--退出系統(tǒng) |"); 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("是否繼續(xù)增加課程(y/n):"); gets(tmp); if(strcmp(tmp, "n") == 0) { break; } } point = (class_t *)malloc(sizeof(class_t)); point->is_exsit = 0; printf("\n====請輸入第%d個(gè)選修課程信息====\n", count); printf("選擇課程名稱:"); gets(point->name); q = head; while(NULL != q) { if(strcmp(q->name, point->name) == 0) { flag = 1; printf("課程名稱重復(fù)或者不合格,請重新輸入...\n"); break; } q = q->next; } if(1 == flag) { continue; } printf("課程性質(zhì):"); 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輸入總學(xué)時(shí):(只接受數(shù)字!)"); point->total_period = num_check(); printf("\n輸入授課學(xué)時(shí):(只接受數(shù)字!)"); point->teach_period = num_check(); printf("\n輸入上機(jī)學(xué)時(shí):(只接受數(shù)字!)"); point->exper_period = num_check(); printf("\n輸入本課程學(xué)分:(只接受數(shù)字!)"); point->score = num_check(); printf("\n輸入開課學(xué)期:(只接受數(shù)字!)"); point->start_time = num_check(); point->is_exsit = 1; point->next = head; head = point; count++; } printf("信息錄入完畢,按任意鍵繼續(xù)……"); getch(); } void display(void) { class_t *point = head; CLASS_CLS; titile("【查看課程】", "-"); printf("\n名稱 \t性質(zhì)\t總學(xué)時(shí)\t授課學(xué)時(shí)\t上機(jī)學(xué)時(shí)\t學(xué)分\t開課學(xué)期"); while(NULL != point) { if(1 == point->is_exsit) { printf("\n%-14s ", point->name); if(1 == point->nature) { printf("必修課"); } else { printf("選修課"); } printf(" %d時(shí) %d時(shí) %d時(shí) %d分 %d時(shí)", point->total_period, point->teach_period, point->exper_period, point->score, point->start_time); } point = point->next; } getch(); } // 對照學(xué)生管理系統(tǒng)自行拓展 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 【選修課系統(tǒng)】"); if(1 == movie) { play("歡迎使用【選修課系統(tǒng)】", 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語言怎么實(shí)現(xiàn)一個(gè)學(xué)生選課系統(tǒng),小編相信有部分知識點(diǎn)可能是我們?nèi)粘9ぷ鲿姷交蛴玫降摹OM隳芡ㄟ^這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。