"C-Language student performance management system"

Source: Internet
Author: User
Tags fread strcmp

/* (staring at the first draw)
* Copyright Notice and version number of the program
* Copyright (c) 2011, Yantai University Students ' School of computer Science
* All rights reserved.
* File name: Student Performance Management System
* Author: Liujiangpo
* Completed Date: June 23, 2012
* Version number: v.623

* Descriptive narrative of tasks and solutions
* The gaze end of the program head
*/

#include "stdio.h" #include "string"/* Define student structure */struct student{Char id[20];     Char name[20];     float Mark1;     float MARK2;     float Mark3; Float average;};/ * Declare the student array and the number of students */struct Student Students[1000];int num=0; /* Averages */float AVG (struct Student stu) {return (Stu. Mark1+stu. Mark2+stu. MARK3)/3;}     /* Return array subscript */int Student_searchbyindex (char id[]) {int i by learning number;         for (i=0;i<num;i++) {if (strcmp (students[i].id,id) ==0) {return i; }} return-1;}     /* Returns array subscript */int Student_searchbyname (char name[]) by name {int i; for (i=0;i<num;i++) {if (strcmp (Students[i]).         Name,name) ==0) {return i; }} return-1;} /* Display a single student record */void student_displaysingle (int index) {printf ("%10s%10s%8s%8s%8s%10s\n", "Student Number", "name", "Score", "score", "Score", "     Average score ");     printf ("-------------------------------------------------------------\ n"); printf ("%10s%10s%8.2f%8.2f%8.2f%10.2f\n", Students[index].id,students[index]. Name, Students[index]. Mark1,students[index]. Mark2,students[index]. Mark3,students[index]. Average);}         /* Insert Student Information */void Student_insert () {while (1) {printf ("Please enter study number:");         scanf ("%s", &students[num].id);          GetChar ();         printf ("Please enter Name:"); scanf ("%s", &students[num].         Name);          GetChar ();         printf ("Please enter your score:"); scanf ("%f", &students[num].         MARK1);          GetChar ();         printf ("Please enter your score:"); scanf ("%f", &students[num].         MARK2);          GetChar ();         printf ("Please enter your score:"); scanf ("%f", &students[num].         MARK3);          GetChar (); Students[num].         Average=avg (Students[num]);          num++; printf ("Do you want to continue?"

(y/n) "); if (getchar () = = ' n ') {break; }}}/* Change student Information */void student_modify () {//float mark1,mark2,mark3; while (1) {char id[20]; int index; printf ("Please enter the student number for the change:"); scanf ("%s", &id); GetChar (); Index=student_searchbyindex (ID); if (index==-1) {printf ("Student does not exist!\n"); } else {printf ("The Student information you want to change is: \ n"); Student_displaysingle (index); printf ("--Please enter new value--\n"); printf ("Please enter the study number:"); scanf ("%s", &students[index].id); GetChar (); printf ("Please enter Name:"); scanf ("%s", &students[index]. Name); GetChar (); printf ("Please enter your score:"); scanf ("%f", &students[index]. MARK1); GetChar (); printf ("Please enter your score:"); scanf ("%f", &students[index]. MARK2); GetChar (); printf ("Please enter intoPerformance: "); scanf ("%f", &students[index]. MARK3); GetChar (); Students[index]. Average=avg (Students[index]); } printf ("Do you want to continue?" ( y/n) "); if (getchar () = = ' n ') {break; }}}/* Delete student information */void student_delete () {int i; while (1) {char id[20]; int index; printf ("Please enter the student number for deletion:"); scanf ("%s", &id); GetChar (); Index=student_searchbyindex (ID); if (index==-1) {printf ("Student does not exist!\n"); } else {printf ("The Student information you want to delete is: \ n"); Student_displaysingle (index); printf ("Are you sure you want to delete it?"

(y/n) "); if (getchar () = = ' Y ') {for (i=index;i<num-1;i++) { students[i]=students[i+1];//the back of the object to move forward} num--; } getchar (); } printf ("Do you want to continue?

(y/n) "); if (getchar () = = ' n ') {break; }}}/* Query by name */void Student_select () {while (1) {char name[20]; int index; printf ("Please enter the name of the student to be queried:"); scanf ("%s", &name); GetChar (); Index=student_searchbyname (name); if (index==-1) {printf ("Student does not exist!\n"); } else {printf ("The Student information you are inquiring about is: \ n"); Student_displaysingle (index); } printf ("Do you want to continue?" ( y/n) "); if (getchar () = = ' n ') {break; }}}/* Sorted by average */void student_sortbyaverage () {int i,j; struct Student tmp; for (i=0;i<num;i++) {for (j=1;j<num-i;j++) {if (students[j-1]. AVERAGE&LT;STUDENTS[J]. Average) {tmp=students[j-1]; STUDENTS[J-1]=STUDENTS[J]; students[j]=tmp; }}}}/* Display student information */void Student_Display () {int i; printf ("%10s%10s%8s%8s%8s%10s\n", "Learning number", "name", "Score", "Score", "achievement", "average score"); printf ("-------------------------------------------------------------\ n"); for (i=0;i<num;i++) {printf ("%10s%10s%8.2f%8.2f%8.2f%10.2f\n", Students[i].id,students[i]. Name, Students[i]. Mark1,students[i]. Mark2,students[i]. Mark3,students[i]. Average); }}/* Read the student information from the file */void io_readinfo () {file *fp; int i; if ((Fp=fopen ("Database.txt", "RB") ==null) {printf ("Cannot open file!\n"); Return } if (Fread (&num,sizeof (int), 1,FP)!=1) {num=-1; } else {for (i=0;i<num;i++) {fread (&students[i],sizeof (struct Student), 1,FP); }} fclose (FP);} /* Write student information to file */void Io_writeinfo () {file *fp; int i; if ((Fp=fopen ("Database.txt", "WB") ==null) {printf ("Cannot open file!\n"); Return } if (Fwrite (&num,sizeof (int), 1,FP)!=1) {PrinTF ("Write File Error!\n"); } for (i=0;i<num;i++) {if (fwrite (&students[i],sizeof (struct Student), 1,FP)!=1) { printf ("Write file Error!\n"); }} fclose (FP);} /* Main program */void main () {int choice; Io_readinfo (); while (1) {/* Main Menu */printf ("\ n------Student performance Management system------\ n"); printf ("1. Add student record \ n "); printf ("2. Change student record \ n "); printf ("3. Delete the student record \ n "); printf ("4. Check student records by name \ n "); printf ("5. Sort by average score \ n "); printf ("6. Exit \ n "); printf ("Please select (1-6):"); scanf ("%d", &choice); GetChar (); Switch (choice) {case 1:student_insert (); Break Case 2:student_modify (); Break Case 3:student_delete (); Break Case 4:student_select (); Break Case 5:student_sortbyaverage (); Student_display (); Break Case 6:exit (0); Break } io_writeinfo (); }}


"C-Language student performance management system"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.