#define NULL 0
#define LEN sizeof (struct student)
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
Define the structure body
struct student
{
Char stuid[20];
Char coursecode[20];
Char coursename[20];
float credit;
float Usualresult;
float Shiyanresult;
float Juanmianresult;
float Zongheresult;
float Shidecredit;
struct student *next;
};
struct student *head;
void Menu ();
struct student *create ();
void Save ();
void Sort ();
void Serch ();
void Delete ();
struct student *delete ();
void Display ();
/************ Main function *******************/
int main ()
{
System ("Color 0D");
int choice;
Char yes_no;
Todo
{
System ("CLS");
Menu ();
printf ("Please enter your choice in the 0~6: \ n");
scanf ("%d", &choice);
printf ("\ n");
Switch (choice)
{
Case 1:create (); Break
Case 2:sort (); Break
Case 3:serch (); Break
Case 4:delete (); Break
Case 5:save (); Break
Case 6:display (); Break
Case 0:printf ("Thank you for your use!"); Exit (0); Break
default:printf ("Input Error"). Please enter the number between 0~6 ");
}
printf (\ n continue typing?) y/n: ");
Todo
{
scanf ("%c", &yes_no);
}while ((yes_no!= ' y ') && (yes_no!= ' y ') && (yes_no!= ' n ') && (yes_no!= ' n '));
}while ((Yes_no = = ' Y ') | | (Yes_no = = ' y '));
return 0;
}
/************ Menu Function *****************/
void Menu ()
{
printf ("\ n \ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf ("|"); printf ("\t\t\t welcome into the student management system"); printf ("\t\t\t|");
printf ("\ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf ("|"); printf ("\t\t\t 1. Input student Information"); printf ("\t\t\t|\n");
printf ("|"); printf ("\t\t\t 2. Sort student Information"); printf ("\t\t\t|\n");
printf ("|"); printf ("\t\t\t 3. Find student Information"); printf ("\t\t\t|\n");
printf ("|"); printf ("\t\t\t 4. Delete Student Information"); printf ("\t\t\t|\n");
printf ("|"); printf ("\t\t\t 5. Save student Information"); printf ("\t\t\t|\n");
printf ("|"); printf ("\t\t\t 6. Display student Information"); printf ("\t\t\t|\n");
printf ("|"); printf ("\t\t\t 0. Exit management system"); printf ("\t\t\t|\n");
printf ("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
}
/************ create a linked list and input data **************/
struct Student *create ()
{
struct student *p,*q;
int i,m;
printf ("Please enter the number of nodes you want to establish:");
scanf ("%d", &m);
for (i = 1; I <= m + +)
{
p= (struct student *) malloc (LEN);
printf ("Please enter information for%d students: \ n", i);
printf ("Please enter the school number:");
scanf ("%s", p->stuid);
printf (\ n Please enter course number:);
&NBSP;&NBSP;&NBSP;SCANF ("%s", P->coursecode);
printf (Please enter course name: ");
scanf ("%s", p->coursename);
printf ("Please enter credits:");
scanf ("%f", &p->credit);
printf ("Please enter the usual score:");
scanf ("%f", &p->usualresult);
printf ("Please enter experimental results:");
scanf ("%f", &p->shiyanresult);
printf ("Please enter scaled score:");
scanf ("%f", &p->juanmianresult);
if (p-> Shiyanresult) = = = 1)
{
p->zongheresult = p->usualresult*30/ MB + p->juanmianresult*70/100;
printf ("Comprehensive score =%f\n", p->zongheresult);
}
else
{
p->zongheresult = p-> usualresult*15/100 + p->juanmianresult*70/100 + p->shiyanresult*0.15/100;
printf ("Comprehensive score =%f\n", p->zongheresult);
}
int Zhresult = (p->zongheresult)/10;
switch (Zhresult)
{
case:
case 9:p->shidecredit = P >Credit*100/100;
printf ("Real credits =%f\n", p->shidecredit);
case 8:p->shidecredit = p->credit*80/100;
printf ("Real credits =%f\n", p->shidecredit);
case 7:p->shidecredit=p->credit*75/100;
printf ("Real credits =%f\n", p->shidecredit);
case 6:p->shidecredit = p->credit*60/100;
printf ("Real credits =%f\n", p->shidecredit);
default:p->shidecredit = 0; printf ("Real credits =%f\n", p->shidecredit);
}
P->next = NULL;
if (head = = NULL)
{
head = p;
Q = p;
}
Q->next = p;
Q = p;
}
return head;
}
/*************** sort function *******************/
void Sort ()
{
int choice;
struct student *p1,*p2;
Char stuid[20];
Char coucode[20];
Char couname[20];
float credit;
float Usualres;
float Syres;
float Jmres;
float Zhres;
float Sdcre;
printf ("\ n");
printf ("1 comprehensive results in descending order: \ n");
printf ("2 credits in ascending order: \ n");
printf ("Please enter the selection:");
scanf ("%d", &choice);
printf ("\ n");
Switch (choice)
{
Case 1:for (p1 = head; P1!= NULL; p1 = p1->next)
{
for (P2 = p1->next; p2!= NULL; p2 = p2->next)//Selection method, select the smallest row to the header each time
{
if (P1->zongheresult<p2->zongheresult)
{
Zhres = p2->zongheresult;
P2->zongheresult = p1->zongheresult;
P1->zongheresult = Zhres;
Credit = p2->credit;
P2->credit = p1->credit;
P1->credit = p2->credit;
Usualres = p2->usualresult;
P2->usualresult = p1->usualresult;
P1->usualresult = usualres;
Syres = p2->shiyanresult;
P2->shiyanresult = p1->shiyanresult;
P1->shiyanresult = Syres;
Jmres = p2->juanmianresult;
P2->juanmianresult = p1->juanmianresult;
P1->juanmianresult = jmres;
Sdcre = p2->shidecredit;
P2->shidecredit = p1->shidecredit;
P1->shidecredit = Sdcre;
strcpy (STUID,P2->STUID);
strcpy (P2->STUID,P1->STUID);
strcpy (p1->stuid,stuid);
strcpy (Coucode,p2->coursecode);
strcpy (P2->coursecode,p1->coursecode);
strcpy (P1->coursecode,coucode);
strcpy (Couname,p2->coursename);
strcpy (P2->coursename,p1->coursename);
strcpy (P1->coursename,couname);
}
}
}
Display ();
Break
Case 2:for (p1 = head; P1!= NULL; p1 = p1->next)
{
for (P2 = p1->next; p2!= NULL; p2 = p2->next)//Selection method, select the smallest row to the header each time
{
if (P1->shidecredit<p2->shidecredit)
{
Sdcre = p2->shidecredit;
P2->shidecredit = p1->shidecredit;
P1->shidecredit = Sdcre;
Zhres = p2->zongheresult;
P2->zongheresult = p1->zongheresult;
P1->zongheresult = zhres;
Credit = p2->credit;
P2->credit = p1->credit;
P1->credit = p2->credit;
Usualres = p2->usualresult;
P2->usualresult = p1->usualresult;
P1->usualresult = usualres;
syres= p2->shiyanresult;
P2->shiyanresult = p1->shiyanresult;
P1->shiyanresult = Syres;
Jmres = p2->juanmianresult;
P2->juanmianresult = p1->juanmianresult;
P1->juanmianresult = jmres;
strcpy (STUID,P2->STUID);
strcpy (P2->STUID,P1->STUID);
strcpy (p1->stuid,stuid);
strcpy (Coucode,p2->coursecode);
strcpy (P2->coursecode,p1->coursecode);
strcpy (P1->coursecode,coucode);
strcpy (Couname,p2->coursename);
strcpy (P2->coursename,p1->coursename);
strcpy (P1->coursename,couname);
}
}
}
Display ();
break;
}
Return
}
/******** score Query Function **************/
void Serch ()
{
struct student *p;
Char stuid[20];
if (head = = NULL)
{
printf ("\nlist null!\n");
Return
}
printf ("Please enter the number you want to query: \ n");
scanf ("%s", &stuid);
for (p = head; p!= NULL; p = p->next)
{
if (strcmp (p->stuid,stuid) = = 0)
{
printf ("School Number:");
printf ("s%\n", P->stuid);
printf ("Course number \ t course name \ t comprehensive score \ t solid score \ n");
printf ("%4s\t\t%4s\t\t%4.1f\t\t%4.1f", P->coursecode,p->coursename,p->zongheresult,p->shidecredit);
}
else if (P->next = NULL)
printf ("\ n no found");
}
}
/********* Delete function ***************/
struct Student *delete ()
{
struct student *p1,*p2;
Char stuid[20];
printf ("Please enter the number you want to delete:");
scanf ("%s", Stuid);
if (head = = NULL)
printf ("\ n-list is empty");
Else
{
P1 = P2 = head;
while ((strcmp (p1->stuid,stuid)!=0) && (p1->next)!= NULL)
{
P2 = p1;
P1 = p1->next;
}
if ((strcmp (p1->stuid,stuid) = = 0))
{
if (P1 = = head)
Head = p1->next;
Else
P2->next = p1->next;
printf ("\ n This information has been deleted");
Free (p1);
}
Else
printf ("not been found!! \ n ");
}
return head;
}
/************* save function ****************/
void Save ()
{
file *fp;
struct student *p;
if ((fp = fopen ("B.txt", "w") = = NULL)
{
printf ("Can ' t open!\n") ;
exit (0);
}
for (p = head; p!= NULL; p = p->next)
fprintf (FP, "%c,%c,%f,%f%f%f%f\n", p ->stuid,p->coursecode,p->coursename,
p->StuID,p->UsualResult,p-> Shiyanresult,p->juanmianresult,
p->zongheresult,p->shidecredit);
fclose (FP);
printf ("Information has been saved");
}
/********* Display Records ***********/
void Display ()
{
struct student *p;
if (head = = NULL)
{
printf ("\ n list null");
Return
}
printf ("School Number course number course name credits in peacetime results of the test results scaled scores of credit");
for (p = head; p!= NULL; p = p->next)
printf ("%2s%4s%10s%8.1f%6.1f%6.1f%10.1f%10.1f%6.1f\n", P->stuid,p->coursecode,p->coursename,
P->credit,p->usualresult,p->shiyanresult,p->juanmianresult,p->zongheresult,p->shidecredit);
}