Ϊʲôֹͣ²»ÁË
/*Î÷ÄÏʯÓÍ´óѧ¼ÆËã»ú¿ÆѧѧԺ
¿Î³Ì£º³ÌÐòÉè¼Æ×ÛºÏʵ¼ù
½Ìʦ£ºÖÜÓÀ Áº×ÚÎÄ
±à³ÌÕߣºÐ¤³© ĸµ¤
±à³ÌÈÕÆÚ£º2017-07-08¡ª¡ª2017-07-15
³ÌÐò¹¦ÄÜ£ºÊµÏÖѧÉú³É¼¨µÄ¼È룬Ð޸ģ¬É¾³ý£¬²éѯ£¬ÅÅÐò
*/
//Í·Îļþ
#include<stdio.h>
#include<string.h>
#include<stdlib.h> //ʹÓÃexitº¯ÊýÒªÒýÈëµÄÍ·Îļþ >
#include<windows.h>
#include<conio.h>
//¼Ù¶¨Ö»´æ·ÅѧºÅ£¬ÐÕÃû£¬Êýѧ£¬Êý¾Ý½á¹¹£¬Ó¢Óï³É¼¨
struct Student
{
char ID;//12λµÄѧºÅ£¬¼Óһλ½áÊø·û
char Name;//×î¶à¿ÉÒÔ´æ·Å5¸öºº×Ö£¨10¸ö×Ö½Ú£©£¬¼Óһλ½áÊø·û
float fMath;
float fData_structure;
float fEnglish;
float Average;//ƽ¾ù³É¼¨
struct Student *next;
};
//º¯ÊýÉùÃ÷
void IO_ReadInfo();//½«Ñ§ÉúÐÅÏ¢´ÓÎļþ¶Á³ö
void IO_WriteInfo();//½«Ñ§ÉúÐÅϢдÈëÎļþ
int Student_SearchByIndex(char id[]);//ͨ¹ýѧºÅ·µ»ØÊý×éϱê
int Student_SearchByName(char name[]);//ͨ¹ýÐÕÃû·µ»ØÊý×éϱê
float Avg(struct Student stu);//Çóƽ¾ùÖµ
void Student_DisplaySingle(int index);//ÏÔʾµ¥ÌõѧÉú¼Ç¼
void Student_Insert();//²åÈëѧÉúÐÅÏ¢
void Student_Modify();//ÐÞ¸ÄѧÉúÐÅÏ¢
void Student_Delete();//ɾ³ýѧÉúÐÅÏ¢
void Student_SortByAverage();//°´Æ½¾ùÖµÅÅÐò
void Student_Display();//ÏÔʾѧÉúÐÅÏ¢
void Student_Select();//°´ÐÕÃû²éѯ
void acceptData();//½ÓÊÕÓû§ÊäÈëµÄÊý¾Ý
void showData();//ÏÔʾÓû§ÊäÈëµÄÊý¾Ý
void web();
/*ÉùÃ÷ѧÉúÊý×鼰ѧÉúÊýÁ¿*/
struct Student students; //ѧÉúÈËÊý×î¶àΪ1000
int num=0;//¶¨ÒåѧÉúÊýÁ¿
/*Çóƽ¾ùÖµ*/
float Avg(struct Student stu)
{
return (stu.fMath+stu.fData_structure+stu.fEnglish)/3;
}
/*ͨ¹ýѧºÅ·µ»ØÊý×éϱê*/
int Student_SearchByIndex(char ID[])
{
int i;
for (i=0;i<num;i++)
{
if (strcmp(students.ID,ID)==0)
//strcmpº¯Êý£º1.×Ö·û´®1СÓÚ×Ö·û´®2,strcmpº¯Êý·µ»ØÒ»¸ö¸ºÖµ;2.×Ö·û´®1µÈÓÚ×Ö·û´®2,strcmpº¯Êý·µ»ØÁã;3.×Ö·û´®1´óÓÚ×Ö·û´®2,strcmpº¯Êý·µ»ØÒ»¸öÕýÖµ
{
return i;
}
}
return -1;
}
/*ͨ¹ýÐÕÃû·µ»ØÊý×éϱê*/
int Student_SearchByName(char Name[])
{
int i;
for (i=0;i<num;i++)
{
if (strcmp(students.Name,Name)==0)
{
return i;
}
}
return -1;
}
/*ÏÔʾµ¥ÌõѧÉú¼Ç¼*/
void Student_DisplaySingle(int index)
{
printf("%10s%10s%16s%16s%16s%10s\n","ѧºÅ","ÐÕÃû","¸ßµÈÊýѧ³É¼¨","Êý¾Ý½á¹¹³É¼¨","´óѧӢÓï³É¼¨","ƽ¾ù³É¼¨");
printf("-------------------------------------------------------------\n");
printf("%10s%10s%16.2f%16.2f%16.2f%10.2f\n",students.ID,students.Name,
students.fMath,students.fData_structure,students.fEnglish,students.Average);
}
/*²åÈëѧÉúÐÅÏ¢*/
void Student_Insert()
{
while(1)
{
printf("ÇëÊäÈëѧºÅ:");
scanf("%s",&students.ID);
getchar();
/*scanfÓëgetchar()Á¬Óãº1.ÄǸö»Ø³µ·ûûÓаéËæ×ÅscanfÓï¾äµÄ½áÊø¶øÏûʧ£»
2.scanfÈÏΪ»Ø³µ·û£¬¿Õ¸ñ·ûÊÇ·Ö¸ô·û£¬»á×Ô¶¯Ìø¹ý£¬Òò¶ø²»»áÓ°ÏìÏÂÒ»¸öscanf¡£
3.getcharÊǶÁÈëÒ»¸ö×Ö·û£¬²»¹ÜÊDz»ÊÇ·Ö¸ô·û£¬¶¼²»»áÌø¹ý¡£*/
printf("ÇëÊäÈëÐÕÃû:");
scanf("%s",&students.Name);
getchar();
printf("ÇëÊäÈë¸ßµÈÊýѧ³É¼¨:");
scanf("%f",&students.fMath);
getchar();
printf("ÇëÊäÈëÊý¾Ý½á¹¹³É¼¨:");
scanf("%f",&students.fData_structure);
getchar();
printf("ÇëÊäÈë´óѧӢÓï³É¼¨:");
scanf("%f",&students.fEnglish);
getchar();
students.Average=Avg(students);
num++;
printf("ÊÇ·ñ¼ÌÐø?(y/n)");
if (getchar()=='n')
{
system("cls");
break;
}
}
}
/*ÐÞ¸ÄѧÉúÐÅÏ¢*/
void Student_Modify()
{
//float fMath,fData_structure,fEnglish;
while(1)
{
char ID;
int index;
printf("ÇëÊäÈëÒªÐ޸ĵÄѧÉúµÄѧºÅ:");
scanf("%s",&ID);
getchar();
index=Student_SearchByIndex(ID);
if (index==-1)
{
printf("ѧÉú²»´æÔÚ!\n");
}
else
{
printf("ÄãÒªÐ޸ĵÄѧÉúÐÅϢΪ:\n");
Student_DisplaySingle(index);//½«ÐèÒªÐ޸ĵÄѧÉúÐÅÏ¢´òÓ¡³öÀ´
printf("-- ÇëÊäÈëÐÂÖµ--\n");
printf("ÇëÊäÈëѧºÅ:");
scanf("%s",&students.ID);
getchar();
printf("ÇëÊäÈëÐÕÃû:");
scanf("%s",&students.Name);
getchar();
printf("ÇëÊäÈë¸ßÊý³É¼¨:");
scanf("%f",&students.fMath);
getchar();
printf("ÇëÊäÈëÊý¾Ý½á¹¹³É¼¨:");
scanf("%f",&students.fData_structure);
getchar();
printf("ÇëÊäÈë´óѧӢÓï³É¼¨:");
scanf("%f",&students.fEnglish);
getchar();
students.Average=Avg(students);
}
printf("ÊÇ·ñ¼ÌÐø?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*ɾ³ýѧÉúÐÅÏ¢*/
void Student_Delete()
{
int i;
while(1)
{
char ID;
int index;
printf("ÇëÊäÈëҪɾ³ýµÄѧÉúµÄѧºÅ:");
scanf("%s",&ID);
getchar();
index=Student_SearchByIndex(ID);
if (index==-1)
{
printf("ѧÉú²»´æÔÚ!\n");
}
else
{
printf("ÄãҪɾ³ýµÄѧÉúÐÅϢΪ:\n");
Student_DisplaySingle(index);
printf("ÊÇ·ñÕæµÄҪɾ³ý?(y/n)");
if (getchar()=='y')
{
for (i=index;i<num-1;i++)
{
students=students;//°Ñºó±ßµÄ¶ÔÏó¶¼ÏòÇ°Òƶ¯
}
num--;
}
getchar();
}
printf("ÊÇ·ñ¼ÌÐø?(y/n)");
if (getchar()=='n')
{
system("cls");
break;
}
}
}
/*°´ÐÕÃû²éѯ*/
void Student_Select()
{
while(1)
{
char Name;
int index;
printf("ÇëÊäÈëÒª²éѯµÄѧÉúµÄÐÕÃû:");
scanf("%s",&Name);
getchar();
index=Student_SearchByName(Name);
if (index==-1)
{
printf("ѧÉú²»´æÔÚ!\n");
}
else
{
printf("ÄãÒª²éѯµÄѧÉúÐÅϢΪ:\n");
Student_DisplaySingle(index);
}
printf("ÊÇ·ñ¼ÌÐø?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*°´Æ½¾ùÖµÅÅÐò*/
void Student_SortByAverage()
{
int i,j;
struct Student tmp;
for (i=0;i<num;i++)
{
for (j=1;j<num-i;j++)
{
if (students.Average<students.Average)
{
tmp=students;
students=students;
students=tmp;
}
}
}
}
/*ÏÔʾѧÉúÐÅÏ¢*/
void Student_Display()
{
int i;
printf("%12s%12s%12s%12s%12s%10s\n","ѧºÅ","ÐÕÃû","³É¼¨","³É¼¨","³É¼¨","ƽ¾ù³É¼¨");
printf("--------------------------------------------------------------------------------------------------------------------------------------------------------\n");
for (i=0;i<num;i++)
{
printf("%5s%5s%8.2f%8.2f%8.2f%8.2f\n",students.ID,students.Name,
students.fMath,students.fData_structure,students.fEnglish,students.Average);
}
}
/*½«Ñ§ÉúÐÅÏ¢´ÓÎļþ¶Á³ö*/
void IO_ReadInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","rb"))==NULL) //¶Á¶þ½øÖÆÎļþ
{
printf("²»ÄÜ´ò¿ªÎļþ!\n");
return;
}
if (fread(&num,sizeof(int),1,fp)!=1)
{
num=-1;
}
else
{
for(i=0;i<num;i++)
{
fread(&students,sizeof(struct Student),1,fp);
}
}
fclose(fp);
}
/*½«Ñ§ÉúÐÅϢдÈëÎļþ*/
void IO_WriteInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","wb"))==NULL)//д¶þ½øÖÆÎļþ
{
printf("²»ÄÜ´ò¿ªÎļþ!\n");
return;
}
if (fwrite(&num,sizeof(int),1,fp)!=1)
{
printf("дÈëÎļþ´íÎó!\n");
}
for (i=0;i<num;i++)
{
if (fwrite(&students,sizeof(struct Student),1,fp)!=1)
{
printf("дÈëÎļþ´íÎó!\n");
}
}
fclose(fp);
}
void web()
{
FILE *fh;
FILE *fp;
intiCounter=0,i;//½¨Òé×îºÃÄÚ´æÖУ¬ÓÐÒ»¸ö±äÁ¿£¬Ò»Ö±Î¬»¤¶þ½øÖÆÎļþÖеļǼÊý¡£ÃâµÃÿ´Îͳ¼Æ¡£
//¶ÁÈ¡Êý¾Ý
fp=fopen("Database.txt","ab+"); //´ò¿ªÊý¾ÝÎļþ
while(!feof(fp))
{
if (fread(&num,sizeof(int),1,fp)==1)
iCounter++;
}
fclose(fp);//¹Ø±ÕÊý¾ÝÎļþ
if(iCounter == 0)
{
printf("»¹Ã»ÓпÉÒÔµ¼³öµÄÊý¾Ý£¡");
return;
}
fh=fopen("export.html", "w");//ÒÔдµÄ·½Ê½´ò¿ªhtmlÎļþ
if (fh==NULL)
{
printf("µ¼³öÎļþʧ°Ü¡£Ç뽫µ±Ç°¿ÉÖ´ÐгÌÐò¿½±´µ½¾ßÓÐдȨÏ޵ĴÅÅÌλÖá£\n");
return;
}
//µÚÒ»²½£¬Ð´ÈëÍøÒ³µÄ¿ªÍ·²¿·Ö
fprintf(fh,"<!--°æȨËùÓÐ201631064204ÕÅÈôêØ 201631064206ÕÅÔÃÓ± -->\n");
fprintf(fh,"<html>\n");
fprintf(fh,"<head><title>ѧÉú³É¼¨ÐÅÏ¢µ¼³ö</title></head>\n"); //ä¯ÀÀÆ÷±êÌâÀ¸ÏÔʾµÄÎÄ×Ö
fprintf(fh,"<body>\n");
fprintf(fh,"<center><h2>ѧÉú³É¼¨ÐÅÏ¢</h2><hr></center>\n"); //ÍøÒ³ÕýÎÄÖеıêÌâÎÄ×Ö
fprintf(fh,"<div align=center>\n");
fprintf(fh,"<table border=1 width=80%%>\n");
//µÚ¶þ²½£¬Ð´Èë±í¸ñµÄ±íÍ·²¿·Ö¡£ÒªÐ´ÈëµÄÐÅÏ¢£¬ÔÚË«ÒýºÅÖС£
fprintf(fh,"<tr>\n");
fprintf(fh,"\t<td width=20%%><b>ѧºÅ</b></td>\n");
fprintf(fh,"\t<td width=10%%><b>ÐÕÃû</b></td>\n");
fprintf(fh,"\t<td width=20%%><b>¸ßµÈÊýѧ</b></td>\n");
fprintf(fh,"\t<td width=20%%><b>Êý¾Ý½á¹¹</b></td>\n");
fprintf(fh,"\t<td width=20%%><b>´óѧӢÓï</b></td>\n");
fprintf(fh,"\t<td width=10%%><b>ƽ¾ù³É¼¨</b></td>\n");
fprintf(fh,"</tr>\n");
//µÚÈý²½£¬Í¨¹ýÑ»·£¬Ð´Èë±í¸ñµÄÊý¾Ý²¿·Ö¡£
for(i=0;i<iCounter;i++)
{
fprintf(fh,"<tr>\n");
fprintf(fh,"\t<td width=25%%>%s</td>\n", students.ID);
fprintf(fh,"\t<td width=30%%>%s</td>\n",students.Name);
fprintf(fh,"\t<td width=15%%>%.1f</td>\n", students.fMath);
fprintf(fh,"\t<td width=15%%>%.1f</td>\n",students.fData_structure);
fprintf(fh,"\t<td width=15%%>%.1f</td>\n",students.fEnglish);
fprintf(fh,"\t<td width=15%%>%.1f</td>\n",students. Average);
fprintf(fh,"</tr>\n");
}
//µÚËIJ½£¬Ð´ÈëÍøÒ³µÄ½áÊø²¿·Ö¡£
fprintf(fh,"</table>\n");
fprintf(fh,"</div>\n");
fprintf(fh," <center><h5>201631024202Ф³©201631064205ĸµ¤ÓÚ201707¡¶³ÌÐòÉè¼Æ×ÛºÏʵ¼ù¡·ÊµÏÖµÄÍøÒ³µ¼³ö¹¦ÄÜ</h5><center>\n");
fprintf(fh,"</body></html>\n");
//¹Ø±ÕÎļþ
fclose(fh);
//´òÓ¡³É¹¦ÏûÏ¢
printf("³É¹¦µ¼³ö%dÊý¾Ýµ½µ±Ç°Ä¿Â¼ÏµÄexport.htmlÎļþÖÐ\n",iCounter);
printf("\a");//Ó÷äÃùÉùÌáÐÑ
}
/*Ö÷³ÌÐò*/
int main()
{
int choice;
system("color f6");
printf("\n\n\n\n");
printf("\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf("\t* Î÷ÄÏʯÓÍ´óѧ *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t*¡¾ÏîÄ¿Ãû³Æ¡¿£ºÑ§Éú³É¼¨¹ÜÀíϵͳ *\n");
printf("\t* *\n");
printf("\t*¡¾×¨Òµ°à¼¶¡¿£ºÎïÁªÍø¹¤³Ì1602 *\n");
printf("\t* *\n");
printf("\t*¡¾ÐÕÃû¡¿ Ф³© ĸµ¤ *\n");
printf("\t* *\n");
printf("\t*¡¾Ñ§ºÅ¡¿ 201631064202 201631064205 *\n");
printf("\t* *\n");
printf("\t*¡¾ÏîĿʱ¼ä¡¿£º2017Äê7ÔÂ8ÈÕÖÁ2017Äê7ÔÂ17ÈÕ *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \n");
Sleep(3000);//ÑÓ³ÙÈýÃë
system("cls");//ÇåÆÁ
//»¶Ó½çÃæ
printf("\n\n\n\n");
printf("\t-------------------------------WELCOME-------------------------------\n");
printf("\t------------------------- -------------------------\n");
printf("\t ------------------ ------------------ \n");
printf("\t ------------- ------------- \n");
printf("\t -------- ¼ÆËã»ú¿ÆѧѧԺ -------- \n");
printf("\t ---- ---- \n");
printf("\t -- -- \n");
printf("\t -- -- \n");
printf("\t -- ѧÉú³É¼¨¹ÜÀíϵͳ -- \n");
printf("\t ---- ---- \n");
printf("\t -------- -------- \n");
printf("\t ------------- ------------- \n");
printf("\t ------------------ ------------------ \n");
printf("\t----------------------- -----------------------\n");
printf("\t-------------------------------SYSTEM--------------------------------\n");
Sleep(2000);//ÑÓ³ÙÁ½Ãë
system("cls");//ÇåÆÁ
while(1)
{
/*Ö÷²Ëµ¥*/
printf("\n\n\n\n\n");
printf("\t--------------------------ѧÉú³É¼¨¹ÜÀíϵͳ-------------------------\n");
printf("\n");
printf("\t************************1. Ôö¼ÓѧÉú¼Ç¼************************\n");
printf("\n");
printf("\t************************2. ÐÞ¸ÄѧÉú¼Ç¼************************\n");
printf("\n");
printf("\t************************3. ɾ³ýѧÉú¼Ç¼************************\n");
printf("\n");
printf("\t*********************4. °´ÐÕÃû²éѯѧÉú¼Ç¼*********************\n");
printf("\n");
printf("\t***********************5. °´Æ½¾ù³É¼¨ÅÅÐò***********************\n");
printf("\n");
printf("\t***************************6. Í˳ö*****************************\n");
printf("\n");
printf("\t***************************7. ±£´æÊý¾Ýµ½ÍøÒ³*****************************\n");
printf("\n");
printf("\t---------s-----------w-----------------------p-----------u---------\n");
printf("ÇëÑ¡Ôñ(1-7),²¢°´»Ø³µ¼ü£º");
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;
case 7:
web();
break;
default:
break;
}
IO_WriteInfo();
IO_ReadInfo();
}
return 0;
} ±¾Ìû×îºóÓÉ ba21 ÓÚ 2017-7-13 23:09 ±à¼
Ï´ÎÏÈ°ÑÄÜÍê³ÉµÄ×Ô¼ºÍê³ÉÏ£¬Õâ´úÂ뻹ÓÐÕâô¶àÎÊÌ⣻ÏÂÃæÊǸĹýµÄ´úÂëºÍ¸Ä¹ýµÄµØ·½¡£
»¹ÓÐÒ»µãҪעÒâµÄÊÇ£¬ÕâÀï±£´æ³ÉhtmlÊÇ´ÓÎļþ¶ÁÈ¡ºóÔÙ±£´æ³Éhtml£¬²»ÊÇ´ÓÄÚ´æ¶ÁÈ¡£»Èç¹ûÒª´ÓÄÚ´æÖжÁÈ¡±£´æ£¬ÐÞ¸ÄһϾͺᣲ»¹ý×îÖØÒªµÄÊÇÒªÀíÇåÕûÌåµÄ˼·
/*
Î÷ÄÏʯÓÍ´óѧ¼ÆËã»ú¿ÆѧѧԺ
¿Î³Ì£º³ÌÐòÉè¼Æ×ÛºÏʵ¼ù
½Ìʦ£ºÖÜÓÀ Áº×ÚÎÄ
±à³ÌÕߣºÐ¤³© ĸµ¤
±à³ÌÈÕÆÚ£º2017-07-08¡ª¡ª2017-07-15
³ÌÐò¹¦ÄÜ£ºÊµÏÖѧÉú³É¼¨µÄ¼È룬Ð޸ģ¬É¾³ý£¬²éѯ£¬ÅÅÐò
*/
//Í·Îļþ
#include<stdio.h>
#include<string.h>
#include<stdlib.h> //ʹÓÃexitº¯ÊýÒªÒýÈëµÄÍ·Îļþ >
#include<windows.h>
#include<conio.h>
#define LEN sizeof(struct Student)
//¼Ù¶¨Ö»´æ·ÅѧºÅ£¬ÐÕÃû£¬Êýѧ£¬Êý¾Ý½á¹¹£¬Ó¢Óï³É¼¨
struct Student
{
char ID;//12λµÄѧºÅ£¬¼Óһλ½áÊø·û
char Name;//×î¶à¿ÉÒÔ´æ·Å5¸öºº×Ö£¨10¸ö×Ö½Ú£©£¬¼Óһλ½áÊø·û
float fMath;
float fData_structure;
float fEnglish;
float Average;//ƽ¾ù³É¼¨
struct Student *next;
};
//º¯ÊýÉùÃ÷
void IO_ReadInfo();//½«Ñ§ÉúÐÅÏ¢´ÓÎļþ¶Á³ö
void IO_WriteInfo();//½«Ñ§ÉúÐÅϢдÈëÎļþ
int Student_SearchByIndex(char id[]);//ͨ¹ýѧºÅ·µ»ØÊý×éϱê
int Student_SearchByName(char name[]);//ͨ¹ýÐÕÃû·µ»ØÊý×éϱê
float Avg(struct Student stu);//Çóƽ¾ùÖµ
void Student_DisplaySingle(int index);//ÏÔʾµ¥ÌõѧÉú¼Ç¼
void Student_Insert();//²åÈëѧÉúÐÅÏ¢
void Student_Modify();//ÐÞ¸ÄѧÉúÐÅÏ¢
void Student_Delete();//ɾ³ýѧÉúÐÅÏ¢
void Student_SortByAverage();//°´Æ½¾ùÖµÅÅÐò
void Student_Display();//ÏÔʾѧÉúÐÅÏ¢
void Student_Select();//°´ÐÕÃû²éѯ
void acceptData();//½ÓÊÕÓû§ÊäÈëµÄÊý¾Ý
void showData();//ÏÔʾÓû§ÊäÈëµÄÊý¾Ý
void web();
/*ÉùÃ÷ѧÉúÊý×鼰ѧÉúÊýÁ¿*/
struct Student students; //ѧÉúÈËÊý×î¶àΪ1000
int num=0;//¶¨ÒåѧÉúÊýÁ¿
/*Çóƽ¾ùÖµ*/
float Avg(struct Student stu)
{
return (stu.fMath+stu.fData_structure+stu.fEnglish)/3;
}
/*ͨ¹ýѧºÅ·µ»ØÊý×éϱê*/
int Student_SearchByIndex(char ID[])
{
int i;
for (i=0;i<num;i++)
{
if (strcmp(students.ID,ID)==0)
//strcmpº¯Êý£º1.×Ö·û´®1СÓÚ×Ö·û´®2,strcmpº¯Êý·µ»ØÒ»¸ö¸ºÖµ;2.×Ö·û´®1µÈÓÚ×Ö·û´®2,strcmpº¯Êý·µ»ØÁã;3.×Ö·û´®1´óÓÚ×Ö·û´®2,strcmpº¯Êý·µ»ØÒ»¸öÕýÖµ
{
return i;
}
}
return -1;
}
/*ͨ¹ýÐÕÃû·µ»ØÊý×éϱê*/
int Student_SearchByName(char Name[])
{
int i;
for (i=0;i<num;i++)
{
if (strcmp(students.Name,Name)==0)
{
return i;
}
}
return -1;
}
/*ÏÔʾµ¥ÌõѧÉú¼Ç¼*/
void Student_DisplaySingle(int index)
{
printf("%10s%10s%16s%16s%16s%10s\n","ѧºÅ","ÐÕÃû","¸ßµÈÊýѧ³É¼¨","Êý¾Ý½á¹¹³É¼¨","´óѧӢÓï³É¼¨","ƽ¾ù³É¼¨");
printf("-------------------------------------------------------------\n");
printf("%10s%10s%16.2f%16.2f%16.2f%10.2f\n",students.ID,students.Name,
students.fMath,students.fData_structure,students.fEnglish,students.Average);
}
/*²åÈëѧÉúÐÅÏ¢*/
void Student_Insert()
{
while(1)
{
printf("ÇëÊäÈëѧºÅ:");
scanf("%s",&students.ID);
getchar();
/*scanfÓëgetchar()Á¬Óãº1.ÄǸö»Ø³µ·ûûÓаéËæ×ÅscanfÓï¾äµÄ½áÊø¶øÏûʧ£»
2.scanfÈÏΪ»Ø³µ·û£¬¿Õ¸ñ·ûÊÇ·Ö¸ô·û£¬»á×Ô¶¯Ìø¹ý£¬Òò¶ø²»»áÓ°ÏìÏÂÒ»¸öscanf¡£
3.getcharÊǶÁÈëÒ»¸ö×Ö·û£¬²»¹ÜÊDz»ÊÇ·Ö¸ô·û£¬¶¼²»»áÌø¹ý¡£*/
printf("ÇëÊäÈëÐÕÃû:");
scanf("%s",&students.Name);
getchar();
printf("ÇëÊäÈë¸ßµÈÊýѧ³É¼¨:");
scanf("%f",&students.fMath);
getchar();
printf("ÇëÊäÈëÊý¾Ý½á¹¹³É¼¨:");
scanf("%f",&students.fData_structure);
getchar();
printf("ÇëÊäÈë´óѧӢÓï³É¼¨:");
scanf("%f",&students.fEnglish);
getchar();
students.Average=Avg(students);
num++;
printf("ÊÇ·ñ¼ÌÐø?(y/n)");
if (getchar()=='n')
{
system("cls");
break;
}
}
}
/*ÐÞ¸ÄѧÉúÐÅÏ¢*/
void Student_Modify()
{
//float fMath,fData_structure,fEnglish;
while(1)
{
char ID;
int index;
printf("ÇëÊäÈëÒªÐ޸ĵÄѧÉúµÄѧºÅ:");
scanf("%s",&ID);
getchar();
index=Student_SearchByIndex(ID);
if (index==-1)
{
printf("ѧÉú²»´æÔÚ!\n");
}
else
{
printf("ÄãÒªÐ޸ĵÄѧÉúÐÅϢΪ:\n");
Student_DisplaySingle(index);//½«ÐèÒªÐ޸ĵÄѧÉúÐÅÏ¢´òÓ¡³öÀ´
printf("-- ÇëÊäÈëÐÂÖµ--\n");
printf("ÇëÊäÈëѧºÅ:");
scanf("%s",&students.ID);
getchar();
printf("ÇëÊäÈëÐÕÃû:");
scanf("%s",&students.Name);
getchar();
printf("ÇëÊäÈë¸ßÊý³É¼¨:");
scanf("%f",&students.fMath);
getchar();
printf("ÇëÊäÈëÊý¾Ý½á¹¹³É¼¨:");
scanf("%f",&students.fData_structure);
getchar();
printf("ÇëÊäÈë´óѧӢÓï³É¼¨:");
scanf("%f",&students.fEnglish);
getchar();
students.Average=Avg(students);
}
printf("ÊÇ·ñ¼ÌÐø?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*ɾ³ýѧÉúÐÅÏ¢*/
void Student_Delete()
{
int i;
while(1)
{
char ID;
int index;
printf("ÇëÊäÈëҪɾ³ýµÄѧÉúµÄѧºÅ:");
scanf("%s",&ID);
getchar();
index=Student_SearchByIndex(ID);
if (index==-1)
{
printf("ѧÉú²»´æÔÚ!\n");
}
else
{
printf("ÄãҪɾ³ýµÄѧÉúÐÅϢΪ:\n");
Student_DisplaySingle(index);
printf("ÊÇ·ñÕæµÄҪɾ³ý?(y/n)");
if (getchar()=='y')
{
for (i=index;i<num-1;i++)
{
students=students;//°Ñºó±ßµÄ¶ÔÏó¶¼ÏòÇ°Òƶ¯
}
num--;
}
getchar();
}
printf("ÊÇ·ñ¼ÌÐø?(y/n)");
if (getchar()=='n')
{
system("cls");
break;
}
}
}
/*°´ÐÕÃû²éѯ*/
void Student_Select()
{
while(1)
{
char Name;
int index;
printf("ÇëÊäÈëÒª²éѯµÄѧÉúµÄÐÕÃû:");
scanf("%s",&Name);
getchar();
index=Student_SearchByName(Name);
if (index==-1)
{
printf("ѧÉú²»´æÔÚ!\n");
}
else
{
printf("ÄãÒª²éѯµÄѧÉúÐÅϢΪ:\n");
Student_DisplaySingle(index);
}
printf("ÊÇ·ñ¼ÌÐø?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*°´Æ½¾ùÖµÅÅÐò*/
void Student_SortByAverage()
{
int i,j;
struct Student tmp;
for (i=0;i<num;i++)
{
for (j=1;j<num-i;j++)
{
if (students.Average<students.Average)
{
tmp=students;
students=students;
students=tmp;
}
}
}
}
/*ÏÔʾѧÉúÐÅÏ¢*/
void Student_Display()
{
int i;
printf("%12s%12s%12s%12s%12s%10s\n","ѧºÅ","ÐÕÃû","³É¼¨","³É¼¨","³É¼¨","ƽ¾ù³É¼¨");
printf("--------------------------------------------------------------------------------------------------------------------------------------------------------\n");
for (i=0;i<num;i++)
{
printf("%5s%5s%8.2f%8.2f%8.2f%8.2f\n",students.ID,students.Name,
students.fMath,students.fData_structure,students.fEnglish,students.Average);
}
}
/*½«Ñ§ÉúÐÅÏ¢´ÓÎļþ¶Á³ö*/
void IO_ReadInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","rb"))==NULL) //¶Á¶þ½øÖÆÎļþ
{
printf("²»ÄÜ´ò¿ªÎļþ!\n");
return;
}
if (fread(&num,sizeof(int),1,fp)!=1)
{
num=-1;
}
else
{
for(i=0;i<num;i++)
{
fread(&students,sizeof(struct Student),1,fp);
}
}
fclose(fp);
}
/*½«Ñ§ÉúÐÅϢдÈëÎļþ*/
void IO_WriteInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","wb"))==NULL)//д¶þ½øÖÆÎļþ
{
printf("²»ÄÜ´ò¿ªÎļþ!\n");
return;
}
for (i=0;i<num;i++)
{
if (fwrite(&students,LEN,1,fp)!=1)
{
printf("дÈëÎļþ´íÎó!\n");
}
}
fclose(fp);
}
void web()
{
FILE *fh;
FILE *fp;
intiCounter=0,i;//½¨Òé×îºÃÄÚ´æÖУ¬ÓÐÒ»¸ö±äÁ¿£¬Ò»Ö±Î¬»¤¶þ½øÖÆÎļþÖеļǼÊý¡£ÃâµÃÿ´Îͳ¼Æ¡£
struct Student students; //¶¨Òå¸öÁÙʱ½á¹¹Êý×éÓÃÀ´´æ·Å´ÓÎļþ¶ÁÈ¡µÄѧÉú¼Ç¼
//¶ÁÈ¡Êý¾Ý
fp=fopen("Database.txt","ab+"); //´ò¿ªÊý¾ÝÎļþ
while(!feof(fp))
{
if (fread(&students,LEN,1,fp)==1)
iCounter++;
}
fclose(fp);//¹Ø±ÕÊý¾ÝÎļþ
if(iCounter == 0)
{
printf("»¹Ã»ÓпÉÒÔµ¼³öµÄÊý¾Ý£¡");
return;
}
fh=fopen("export.html", "w");//ÒÔдµÄ·½Ê½´ò¿ªhtmlÎļþ
if (fh==NULL)
{
printf("µ¼³öÎļþʧ°Ü¡£Ç뽫µ±Ç°¿ÉÖ´ÐгÌÐò¿½±´µ½¾ßÓÐдȨÏ޵ĴÅÅÌλÖá£\n");
return;
}
//µÚÒ»²½£¬Ð´ÈëÍøÒ³µÄ¿ªÍ·²¿·Ö
fprintf(fh,"<!--°æȨËùÓÐ201631064204ÕÅÈôêØ 201631064206ÕÅÔÃÓ± -->\n");
fprintf(fh,"<html>\n");
fprintf(fh,"<head><title>ѧÉú³É¼¨ÐÅÏ¢µ¼³ö</title></head>\n"); //ä¯ÀÀÆ÷±êÌâÀ¸ÏÔʾµÄÎÄ×Ö
fprintf(fh,"<body>\n");
fprintf(fh,"<center><h2>ѧÉú³É¼¨ÐÅÏ¢</h2><hr></center>\n"); //ÍøÒ³ÕýÎÄÖеıêÌâÎÄ×Ö
fprintf(fh,"<div align=center>\n");
fprintf(fh,"<table border=1 width=80%%>\n");
//µÚ¶þ²½£¬Ð´Èë±í¸ñµÄ±íÍ·²¿·Ö¡£ÒªÐ´ÈëµÄÐÅÏ¢£¬ÔÚË«ÒýºÅÖС£
fprintf(fh,"<tr>\n");
fprintf(fh,"\t<td width=20%%><b>ѧºÅ</b></td>\n");
fprintf(fh,"\t<td width=10%%><b>ÐÕÃû</b></td>\n");
fprintf(fh,"\t<td width=20%%><b>¸ßµÈÊýѧ</b></td>\n");
fprintf(fh,"\t<td width=20%%><b>Êý¾Ý½á¹¹</b></td>\n");
fprintf(fh,"\t<td width=20%%><b>´óѧӢÓï</b></td>\n");
fprintf(fh,"\t<td width=10%%><b>ƽ¾ù³É¼¨</b></td>\n");
fprintf(fh,"</tr>\n");
//µÚÈý²½£¬Í¨¹ýÑ»·£¬Ð´Èë±í¸ñµÄÊý¾Ý²¿·Ö¡£
for(i=0;i<iCounter;i++)
{
fprintf(fh,"<tr>\n");
fprintf(fh,"\t<td width=25%%>%s</td>\n", students.ID);
fprintf(fh,"\t<td width=30%%>%s</td>\n", students.Name);
fprintf(fh,"\t<td width=15%%>%.1f</td>\n", students.fMath);
fprintf(fh,"\t<td width=15%%>%.1f</td>\n", students.fData_structure);
fprintf(fh,"\t<td width=15%%>%.1f</td>\n", students.fEnglish);
fprintf(fh,"\t<td width=15%%>%.1f</td>\n", students.Average);
fprintf(fh,"</tr>\n");
}
//µÚËIJ½£¬Ð´ÈëÍøÒ³µÄ½áÊø²¿·Ö¡£
fprintf(fh,"</table>\n");
fprintf(fh,"</div>\n");
fprintf(fh," <center><h5>201631024202Ф³©201631064205ĸµ¤ÓÚ201707¡¶³ÌÐòÉè¼Æ×ÛºÏʵ¼ù¡·ÊµÏÖµÄÍøÒ³µ¼³ö¹¦ÄÜ</h5><center>\n");
fprintf(fh,"</body></html>\n");
//¹Ø±ÕÎļþ
fclose(fh);
//´òÓ¡³É¹¦ÏûÏ¢
printf("³É¹¦µ¼³ö%dÊý¾Ýµ½µ±Ç°Ä¿Â¼ÏµÄexport.htmlÎļþÖÐ\n",iCounter);
printf("\a");//Ó÷äÃùÉùÌáÐÑ
}
/*Ö÷³ÌÐò*/
int main()
{
int choice;
system("color f6");
printf("\n\n\n\n");
printf("\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf("\t* Î÷ÄÏʯÓÍ´óѧ *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t*¡¾ÏîÄ¿Ãû³Æ¡¿£ºÑ§Éú³É¼¨¹ÜÀíϵͳ *\n");
printf("\t* *\n");
printf("\t*¡¾×¨Òµ°à¼¶¡¿£ºÎïÁªÍø¹¤³Ì1602 *\n");
printf("\t* *\n");
printf("\t*¡¾ÐÕÃû¡¿ Ф³© ĸµ¤ *\n");
printf("\t* *\n");
printf("\t*¡¾Ñ§ºÅ¡¿ 201631064202 201631064205 *\n");
printf("\t* *\n");
printf("\t*¡¾ÏîĿʱ¼ä¡¿£º2017Äê7ÔÂ8ÈÕÖÁ2017Äê7ÔÂ17ÈÕ *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \n");
Sleep(3000);//ÑÓ³ÙÈýÃë
system("cls");//ÇåÆÁ
//»¶Ó½çÃæ
printf("\n\n\n\n");
printf("\t-------------------------------WELCOME-------------------------------\n");
printf("\t------------------------- -------------------------\n");
printf("\t ------------------ ------------------ \n");
printf("\t ------------- ------------- \n");
printf("\t -------- ¼ÆËã»ú¿ÆѧѧԺ -------- \n");
printf("\t ---- ---- \n");
printf("\t -- -- \n");
printf("\t -- -- \n");
printf("\t -- ѧÉú³É¼¨¹ÜÀíϵͳ -- \n");
printf("\t ---- ---- \n");
printf("\t -------- -------- \n");
printf("\t ------------- ------------- \n");
printf("\t ------------------ ------------------ \n");
printf("\t----------------------- -----------------------\n");
printf("\t-------------------------------SYSTEM--------------------------------\n");
Sleep(2000);//ÑÓ³ÙÁ½Ãë
system("cls");//ÇåÆÁ
while(1)
{
/*Ö÷²Ëµ¥*/
printf("\n\n\n\n\n");
printf("\t--------------------------ѧÉú³É¼¨¹ÜÀíϵͳ-------------------------\n");
printf("\n");
printf("\t************************1. Ôö¼ÓѧÉú¼Ç¼************************\n");
printf("\n");
printf("\t************************2. ÐÞ¸ÄѧÉú¼Ç¼************************\n");
printf("\n");
printf("\t************************3. ɾ³ýѧÉú¼Ç¼************************\n");
printf("\n");
printf("\t*********************4. °´ÐÕÃû²éѯѧÉú¼Ç¼*********************\n");
printf("\n");
printf("\t***********************5. °´Æ½¾ù³É¼¨ÅÅÐò***********************\n");
printf("\n");
printf("\t***************************6. Í˳ö*****************************\n");
printf("\n");
printf("\t***************************7. ±£´æÊý¾Ýµ½ÍøÒ³*****************************\n");
printf("\n");
printf("\t---------s-----------w-----------------------p-----------u---------\n");
printf("ÇëÑ¡Ôñ(1-7),²¢°´»Ø³µ¼ü£º");
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;
case 7:
web();
break;
default:
break;
}
IO_WriteInfo();
// IO_ReadInfo();
}
return 0;
}
ÕâÏÂÃæÊǸĹýµÄµØ·½£º
#define LEN sizeof(struct Student) //ºê¶¨Òå½á¹¹ÌåµÄ³¤¶È
void web()
{
FILE *fh;
FILE *fp;
intiCounter=0,i;//½¨Òé×îºÃÄÚ´æÖУ¬ÓÐÒ»¸ö±äÁ¿£¬Ò»Ö±Î¬»¤¶þ½øÖÆÎļþÖеļǼÊý¡£ÃâµÃÿ´Îͳ¼Æ¡£
struct Student students; //¶¨Òå¸öÁÙʱ½á¹¹Êý×éÓÃÀ´´æ·Å´ÓÎļþ¶ÁÈ¡µÄѧÉú¼Ç¼
//¶ÁÈ¡Êý¾Ý
fp=fopen("Database.txt","ab+"); //´ò¿ªÊý¾ÝÎļþ
while(!feof(fp))
{
if (fread(&students,LEN,1,fp)==1)
iCounter++;
}
fclose(fp);//¹Ø±ÕÊý¾ÝÎļþ
if(iCounter == 0)
{
printf("»¹Ã»ÓпÉÒÔµ¼³öµÄÊý¾Ý£¡");
return;
}
fh=fopen("export.html", "w");//ÒÔдµÄ·½Ê½´ò¿ªhtmlÎļþ
if (fh==NULL)
{
printf("µ¼³öÎļþʧ°Ü¡£Ç뽫µ±Ç°¿ÉÖ´ÐгÌÐò¿½±´µ½¾ßÓÐдȨÏ޵ĴÅÅÌλÖá£\n");
return;
}
//µÚÒ»²½£¬Ð´ÈëÍøÒ³µÄ¿ªÍ·²¿·Ö
fprintf(fh,"<!--°æȨËùÓÐ201631064204ÕÅÈôêØ 201631064206ÕÅÔÃÓ± -->\n");
fprintf(fh,"<html>\n");
fprintf(fh,"<head><title>ѧÉú³É¼¨ÐÅÏ¢µ¼³ö</title></head>\n"); //ä¯ÀÀÆ÷±êÌâÀ¸ÏÔʾµÄÎÄ×Ö
fprintf(fh,"<body>\n");
fprintf(fh,"<center><h2>ѧÉú³É¼¨ÐÅÏ¢</h2><hr></center>\n"); //ÍøÒ³ÕýÎÄÖеıêÌâÎÄ×Ö
fprintf(fh,"<div align=center>\n");
fprintf(fh,"<table border=1 width=80%%>\n");
//µÚ¶þ²½£¬Ð´Èë±í¸ñµÄ±íÍ·²¿·Ö¡£ÒªÐ´ÈëµÄÐÅÏ¢£¬ÔÚË«ÒýºÅÖС£
fprintf(fh,"<tr>\n");
fprintf(fh,"\t<td width=20%%><b>ѧºÅ</b></td>\n");
fprintf(fh,"\t<td width=10%%><b>ÐÕÃû</b></td>\n");
fprintf(fh,"\t<td width=20%%><b>¸ßµÈÊýѧ</b></td>\n");
fprintf(fh,"\t<td width=20%%><b>Êý¾Ý½á¹¹</b></td>\n");
fprintf(fh,"\t<td width=20%%><b>´óѧӢÓï</b></td>\n");
fprintf(fh,"\t<td width=10%%><b>ƽ¾ù³É¼¨</b></td>\n");
fprintf(fh,"</tr>\n");
//µÚÈý²½£¬Í¨¹ýÑ»·£¬Ð´Èë±í¸ñµÄÊý¾Ý²¿·Ö¡£
for(i=0;i<iCounter;i++)
{
fprintf(fh,"<tr>\n");
fprintf(fh,"\t<td width=25%%>%s</td>\n", students.ID);
fprintf(fh,"\t<td width=30%%>%s</td>\n", students.Name);
fprintf(fh,"\t<td width=15%%>%.1f</td>\n", students.fMath);
fprintf(fh,"\t<td width=15%%>%.1f</td>\n", students.fData_structure);
fprintf(fh,"\t<td width=15%%>%.1f</td>\n", students.fEnglish);
fprintf(fh,"\t<td width=15%%>%.1f</td>\n", students.Average);
fprintf(fh,"</tr>\n");
}
//µÚËIJ½£¬Ð´ÈëÍøÒ³µÄ½áÊø²¿·Ö¡£
fprintf(fh,"</table>\n");
fprintf(fh,"</div>\n");
fprintf(fh," <center><h5>201631024202Ф³©201631064205ĸµ¤ÓÚ201707¡¶³ÌÐòÉè¼Æ×ÛºÏʵ¼ù¡·ÊµÏÖµÄÍøÒ³µ¼³ö¹¦ÄÜ</h5><center>\n");
fprintf(fh,"</body></html>\n");
//¹Ø±ÕÎļþ
fclose(fh);
//´òÓ¡³É¹¦ÏûÏ¢
printf("³É¹¦µ¼³ö%dÊý¾Ýµ½µ±Ç°Ä¿Â¼ÏµÄexport.htmlÎļþÖÐ\n",iCounter);
printf("\a");//Ó÷äÃùÉùÌáÐÑ
}
/*½«Ñ§ÉúÐÅϢдÈëÎļþ*/
void IO_WriteInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","wb"))==NULL)//д¶þ½øÖÆÎļþ
{
printf("²»ÄÜ´ò¿ªÎļþ!\n");
return;
}
for (i=0;i<num;i++)
{
if (fwrite(&students,LEN,1,fp)!=1)
{
printf("дÈëÎļþ´íÎó!\n");
}
}
fclose(fp);
} ba21 ·¢±íÓÚ 2017-7-13 23:01
Ï´ÎÏÈ°ÑÄÜÍê³ÉµÄ×Ô¼ºÍê³ÉÏ£¬Õâ´úÂ뻹ÓÐÕâô¶àÎÊÌ⣻ÏÂÃæÊǸĹýµÄ´úÂëºÍ¸Ä¹ýµÄµØ·½¡£
»¹ÓÐÒ»µãҪע ...
ºÃµÄ £¬ÎÒÒÔºó×Ô¼º¶à˼¿¼
ba21 ·¢±íÓÚ 2017-7-13 23:01
Ï´ÎÏÈ°ÑÄÜÍê³ÉµÄ×Ô¼ºÍê³ÉÏ£¬Õâ´úÂ뻹ÓÐÕâô¶àÎÊÌ⣻ÏÂÃæÊǸĹýµÄ´úÂëºÍ¸Ä¹ýµÄµØ·½¡£
»¹ÓÐÒ»µãҪע ...
614µ½617ÐÐΪʲôÓÖ¶¨ÒåÁËÒ»¸öÎļþÖ¸Õëѽ£¿£¿ ÕÅÔÃÓ± ·¢±íÓÚ 2017-7-14 08:12
614µ½617ÐÐΪʲôÓÖ¶¨ÒåÁËÒ»¸öÎļþÖ¸Õëѽ£¿£¿
struct Student students; //¶¨Òå¸öÁÙʱ½á¹¹Êý×éÓÃÀ´´æ·Å´ÓÎļþ¶ÁÈ¡µÄѧÉú¼Ç¼
¾Ö²¿½á¹¹ÌåÊý×é¡£ÓÃÀ´´æ·Å´ÓÎļþ¶ÁÈ¡µÄѧÉú¼Ç¼£»±ÜÃ⸲¸ÇÈ«¾ÖÊý×é¡£ ba21 ·¢±íÓÚ 2017-7-14 09:32
struct Student students; //¶¨Òå¸öÁÙʱ½á¹¹Êý×éÓÃÀ´´æ·Å´ÓÎļþ¶ÁÈ¡µÄѧÉú¼Ç¼
¾Ö²¿½á¹¹ÌåÊý×é¡£ ...
ºÃµÄллÀ²
Ò³:
[1]