/ * Name: Mis_SIMS.C Author: X-bit Description: Simple Student Information Management System Date: 07-11-2004 * /
#include
Typedef struct {int MONTH, DAY, YEAR; / * Birthday * /} bt; typef struct {int number; / * Learn * / char name [13]; / * Name * / char sex [7]; / * Gender: Male or female * / bt birth; / * Birthday MM-DD-YY * / CHAR Addr [35]; / * Home address * /} ST;
STSDENT [MAX]; / * Define Student [MAX] for global variables * /
/ **************** Function declares ********************** / VOID MENU (); / * display Menu * / void menu_done (); / * menu response * / char get_menu_choice (); / * Get menu selection information * / file * file_operate (char * mode); / * File operation module * / void inf_add (file * fp) ; / * Add student information * / void inf_list (file * fp); / * Display student information * / void inf_Search (file * fp); / * Find students information * / void inf_change (file * fp); / * Modify students Information * / void inf_del (file * fp); / * Delete student information * / void file_backup (); / * file backup * / void psw_check (); / * Password verification mechanism * / void set_psw (); / * Set password * /
/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ --- * / int main () {system ("CLS"); psw_check (); menu_done (); return 0;} / * ------------------- ------ The main function ----------------------- * /
/ ************************************************** ****************** / / * menu * // ********************************* *********************************************************************** / VOID MENU () {PrintF "/ t // | /// / n"); Printf ("/ t ~~ ~~ // // // // // // // // // // // // // // // // // // // // // // // // // / n"); Printf ("/ t - ------ OOO --------- (_) ---------- OOOO ----- / n "); Printf (" / T | MIS- ---- SMIS | / N "); Printf (" / t | student management information system | / n "); Printf (" / t | ----------------- -------------------------- | / n "); Printf (" / t | 1. Input Data | 5. Delete Data | / N "); Printf (" / t | 2. Display Data | 6. Backup Data | / N "); Printf (" / T | 3. Search Data | 7. SET Password | / N "); Printf (" / T | 4. Change Data | 0. EXIT | / N "); Printf (" / T | ----------------------------- -------------- | / N "); Printf (" / T | X-bit (c) 2004. | / N " ); Printf ("/ t --------------------------------------- / N ");
/ ************************************************** ***************** / / * menu response module * // ******************************** ************************************************************** / VOID MENU_DOENE () { While (1) {menu (); switch (get_menu_choice ()) {case '1': inf_add (file_operate ("a"); system ("pause); system (" cls "); Break; Case '2 ': INF_LIST ("RB")); System ("Pause"); System ("CLS"); Break; Case' 3 ': INF_SEARCH ("RB"); System ("Pause"); System ("CLS"); Break; Case '4': INF_CHANGE ("RB")); System ("Pause"); System ("CAUS"); Break; Case '5': inf_del (File_Operate " R ")); System (" pause "); system (" cls "); break; case '6': file_backup (); system (" pause "); system (" cls "); break; casser); Break; Case '7' : Set_psw (); System ("pause"); System ("CLS"); Break; Case '0': Printf ("Thank You for Use"); System ("Pause"); System ("Pause"); System "CLS"); EXIT (1); / * Program normal exit * /}}} / ************************ ********************************************* * Receive menu selection * // ******************************************************** ******************* / CHAR GET_MENU_CHOICE () {char Menu_choice; do {fflush (stdin); Printf ("please choice:"); scanf ("% C" , & menu_choice); IF (Menu_choice <'0' || Menu_choice> '7') PUTS ("Input Error, Try Again);} while (menu_choice <'0' || menu_choice> '7'); Return Menu_Choice }
/ ************************************************** ***************** / / * file operation * // ************************ ***************************************************** / File * file_operate (char * {Char char choise; file * fp; do {fflush (stdin); if ((fp = fopen ("student.dat", Mode)) == null) / * Open file * / {PUTS ("File Operation Failure ");" TRY AGAIN (Y / N)? "); Scanf ("% c ", & choise);}} while (choise == 'y' || choise == 'y'); if (choise == 'N' || CHOISE == 'N') EXIT (0); / * Exit * / Return FP;} / ************************* ********************************************************* / / * Enter information * // *************************************************** ************************* / VOID INF_ADD (file * fp) {INT i = 0; / * Initialized index variable * / char kice = ' Y ';
DO {Printf ("No. (20040001):"); Scanf ("% D", & student [i] .Number); Printf ("Name (LESS THAN 12 Characters):" SCANF ("% s", Student [i] .name); Printf ("SEX (" Male or female): "Scanf ("% s ", student [i] .SEX); Printf (" birthday: / n "); Printf (" Year : "); Scanf ("% D ", & student [i] .birth.year); Printf (" Month: "); scanf ("% d ", & student [i] .birth.month); Printf (" DAY : "); Scanf ("% D ", & student [i] .birth.day); Printf (" Address: "); scanf ("% s ", student [i] .addr);
IF (& Student [I], SIZEOF (ST), 1, FP)! = 1) PUTS ("Data Write Error."); i ; fflush (stdin); printf ("Continue (Y / N)?" ); Scanf ("% c", & choice);} while ((choice == 'y' || choice == 'y')); fclose (fp);} / ********** *********************************************************** ******* // * Find information * // ****************************************** ********************************* / VOID INF_SEARCH (file * fp) {INT I, M; char search_name [20 ]; / * Find name variables * / char choic = 'y'; for (i = 0; Feof (fp) == 0; i ) / * read file * / {if (FREAD (& student [i], sizeof (ST), 1, FP)! = 1 && FeOf (fp) == 0) PUTS ("error");} m = i-1; / * m is assigned an array non-empty data maximum index value * / do {Fflush ("Enter the name for search:"); gets (search_name); for (i = 0; i Address:% S / N ", Student [i] .number, student [i] .name, student [i] .SEX, Student [i] .birth.month, student [i] .birth.day, student [i] .bpterh.year, student [i] .addr);}}}}}}} = 0) {PUTS ("Searching Done.");} PUTS ("Continue (Y / N)?"); Scanf ("% C", & cho);} while (choice == 'y' || choice = = 'Y'); fclose (fp);} / ******************************************* ***************************** / / * Display information * // ************ *********************************************************** ***** / void inf_list (file * fp) {INT i, m; for (i = 0; FeOf (fp) == 0; i ) {IF ((& student [i], sizeof (s) , 1, fp)! = 1 && FeOf (fp) == 0) {PUTS ("Error");}} m = I-1; Printf ("There% D Record: / N", M); Printf ("Number Name Sex Birth Address / N); for (i = 0; I / ************************************************** ****************** / / * Modify information * // ******************************** **************************************************** / VOID INF_CHANGE (file * fp ) {Int Number_temp; char kice; int i, m, j = 0; file * fp_update; For (i = 0; Feof (fp) == 0; i ) / * Read file * / if (FREAD (& Student [i], sizeof (st), 1, fp)! = 1 && Feof (fp) = = 0) PUTS ("error"); M = I-1; Do {fflush (stdin); Printf ("Enter Number for Change:"); Scanf ("% D", & Number_temp); for (i = 0; I Address:% S / N ", Student [i] .number, student [i] .name, student [i] .SEX, Student [i] .birth.month, student [i] .birth.day, student [i] .bpterh.year, student [i] .addr);} if (j == 0) { PUTS ("No this Record."); Break;} fflush (stdin); Printf ("Change Data% D (Y / N)?", Number_Temp); / * Modify confirmation * / scanf ("% c", & choice ); If (choice == 'n' || == 'n') / * Modify data * / continue; Printf ("no .:"); scanf ("% d", & student [j] .number) Printf ("Name:"); scanf ("% s", student [j] .name); Printf ("SEX:"); scanf ("% s", student [j] .sex); printf (" Birthday: / n "); Printf (" Year: "); scanf ("% D ", & student [j] .birth.year); Printf (" Month: "); scanf ("% d ", & student [J ] .BIRTH.MONTH); Printf ("day:"); scanf ("% d", & student [j] .birth.day); Printf ("address:"); scanf ("% s", student [J ] .addr); Fflush (stdin); Printf ("Continue (Y / N)?"); Scanf ("% C", & cho);} while (choice == 'y' || choice == 'y'); fp_update = file_operate ("w"); for (i = 0; I Address:% S / N ", Student [i] .number, student [i] .name, student [i] .sex, student [i] .bpterh.month, student [i] .birth.day, student [i] .bpterh.year, student [i] .addr); Fflush (stdin); Printf ("delete% d (y / n)?", number_temp); / * Delete confirmation * / scanf ("% c", & choice); if (choice == 'n' || choice = = 'N') Break; for (t = i; t Printf ("Enter the Backup File Name:"); scanf ("% s", filename); fp = file_operate ("rb"); fp_bak = fp; if ((fp_bak = fopen (FileName, "WB")) = = NULL) {PUTS ("Backup file error."); Exit (0);} while (! Feof (fp)) {ch = fgetc (fp); fputc (ch, fp_bak);} fclose (fp); fclose (FP_BAK); PUTS ("File Backup Success."); / ************************************************** ******************//* Password validation *//************************ ************************************************************** / VOID PSW_CHECK () {char PSW [8], PSW_TEMP [8]; INT I, LEAP; File * fp; IF ((fp = fopen ("sn.dat", "rb")) == null) / * read password, if it is unsuccessful Be Setting password * / {PUTS ("You Must Set Password First."); Menu_done ();} IF (((PSW, SizeOf (PSW), 1, FP))! = 1) PUTS ("Error." ); For (i = 0; i <8; i ) / * decryption * / psw [i] = ~ psw [i]; do {leap = 0; Printf ("Enter Password:"); for (i = 0 i <8; i ) {psw_temp [i] = getCH (); printf ("*"); if (psw_temp [i] == psw [i]) Leap;} if (leap! = 8) { PUTS ("/ Ninvalid Password!");} else printf ("/ n"); fclose (fp);} while (leap! = 8); / ************************************************** ******************//* set password *//************************ **************************************************************** / VOID SET_PSW () {char PSW [8], PSW_TEMP [8]; INT I = 0, Leap = 0; file * fp; Do {Printf ("Enter Password:"); / * Enter a password * / for (i = 0; I <8; i ) {fflush (stdin); PSW [i] = getCH (); printf ("*") PRINTF ("/ NCONFIRM Password:"); / * Enter a password * / for (i = 0; I <8; i ) {fflush (stdin); psw_temp [i] = getCH (); printf (" * ");} For (i = 0; i <8; i ) / * confirm password * / if (PSW [i]) Leap ; if (leap == 8) {Printf (" / Nset Password Success./N "); for (i = 0; i <8; i ) PSW [i] = ~ psw [i]; / * Password encryption * / if ((fp = fopen (" sn.dat " , "WB")) == NULL) / * Password storage * / PUTS ("Error."); IF ((FWRITE (PSW, SizeOf (PSW), 1, FP))! = 1) Puts ("Save Password Error. "); fclose (fp);} else printf (" / n ");} while (leap! = 8);