| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1147 人关注过本帖
标题:我用C做的学生成绩管理想在VC6.0中运行可...........大家来看看吧
取消只看楼主 加入收藏
zhfq
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-7-9
收藏
 问题点数:0 回复次数:1 
我用C做的学生成绩管理想在VC6.0中运行可...........大家来看看吧
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <conio.h>/*包含getch*/

typedef struct student
    {
    int position;/*序号*/
    char num[15];/*学号*/
    char name[20];/*姓名*/
    char sex;/*性别*/
    int chinese;/*语文成绩*/
    int math;/*数学*/
    int english;/*英语*/
    float ave;/*平均*/
    struct student *next;
    }stu;
stu* head;
char password[]="123";

void main()
{
    char choice;
    stu *p;
    char s[10];
    int flag=0,i,k=3;
    system("cls");

    while(k>0)
    {
        printf("\n\n\nenter password:(123):");
        scanf("%s",s);
        if(!strcmp(s,password))
        {
            printf("pass\n");
            flag=1;printf("press any key!");
            getch();
            getchar();
            system("cls");
            break;
        }
        else
        {
            printf("error enter again!\n");
            k--;
        }
     }

    if(!flag)
    {
        printf("you have enter 3 times!");
            getch();exit(0);
    }

printf("\n\n\n\n\t\twhether enter the systerm Yes or No?\n");
scanf("%c",&choice);
if(choice=='n'||choice=='N')
    exit(0);
system("cls");

while(1)
{       printf("===================\t\t\t  ===========================");
    printf("\t\t\t\t    wecome to the systerm\n");
    printf("\nauthor:zhao\tmajor:computer\tnum:2074020029\n\n\n");
    print();
    printf("\nenter choice(0-10):");
    scanf("%d",&i);
    /*system("cls");*/
if(i<0||i>10)
    {
    printf("enter number from 0 to 9\nplease inter again:");
    scanf("%d",&i);
    }
system("cls");
switch(i)
    {
    case  1: create();
        break;
    case  2: lookdata() ;
        break;
    case  3: insert();
        break;
    case  4: find();
        break;
    case  5: change();
        break;
    case  6: avesubject();
        break;
    case  7: save(head);
        break;
    case  8: delet();
        break;
    case  9: order();
        break;
    case 10: load();
        break;
    case  0: exit(0);
        break;
    }
printf("press any key to continue!\n");
getch();
system("cls");
}
}




/*typedef struct student stu ;*/
void create();/**建立人员数据*/
void lookdata();/**查看全部数据*/
void get(stu *p);/**输入每个学生的数据**/
void insert();/*插入数据*/
void find();/**查找*/
void change();/*修改*/
void avesubject();
void save (stu *p);/**保存数据**/
void lookone(stu* x);/**显示某个人的数据**/
void delet();
void order();
void load();
void cmeaverage();

void caverage();/**中文平均值**/

void maverage();/**数学平均值**/

void eaverage();/**平均值**/
void print();
void sort(stu *p1,stu *p2);
void ordera();
void orderc();
void orderm();
void ordere();
//===========================================================







void get(stu *p)/**输入每个学生的数据**/
{
float sum;
static int n=0;
printf("input num:");
gets(p->num);
while(1)
{
     ++n;
     if(n==1) break;
     else
     {
     
    stu *p2=head;
   
    while(strcmp(p2->num,p->num)&&p2!=NULL)
        p2=p2->next;
    if(p2==NULL) break;
    if(strcmp(p2->num,p->num)) break;
    else
    {
        printf("this number has existed please input agian!\n");
         gets(p->num);
    }
     }
}
printf("input name:");
gets(p->name);
for(p->sex='t';p->sex!='m'&&p->sex!='M'&&p->sex!='f'&&p->sex!='F';)
    {
        printf("input sex:");
        scanf("%c",&p->sex);
        getchar();
    }

printf("input chinese:");
scanf("%d",&p->chinese);
for(;p->chinese<0||p->chinese>100;)
{
printf("please input again:");
scanf("%d",&p->chinese);
}

printf("input math:");
scanf("%d",&p->math);
for(;p->math<0||p->math>100;)
{
printf("please input 输入again:");
scanf("%d",&p->math);
}
printf("input english:");
scanf("%d",&p->english);
for(;p->english<0||p->english>100;)
{
printf("please input again:");
scanf("%d",&p->english);
}
getchar();
sum=(float)(p->chinese+p->math+p->english);
p->ave=sum/3;
p->position=0;
}

void create()/**建立人员数据*/
{
int k=0;
char ch='y';
stu *p1,*p2;
p2=p1=(stu *)malloc(sizeof(stu));
while(ch!='n'&&ch!='N')
     {
     printf("if you want to enter the data 'y' or 'n'");
     scanf("%c",&ch);
     getchar();
     if(ch=='n'||ch=='N')
        break;

     get(p1);
     k++;
     if(k==1) head=p1;
     else
         p2->next=p1;
     p2=p1;
     p1=(stu *)malloc(sizeof(stu));
}
if(k==0) head=NULL;
p2->next=NULL;
}
void lookone(stu* x)/**显示某个人的数据**/
{

    printf("position is:%d\n",x->position);
    printf("num is:%s\n",x->num);
    printf("name is:%-s\n",x->name);
    printf("sex is:%c\n",x->sex);
    printf("chinese is:%d\n",x->chinese);
    printf("math is:%d\n",x->math);
    printf("english is:%d\n",x->english);
    printf("average score is:%5.1f\n",x->ave);
}
void find()/**查找*/
{   char n[15];
    stu *p=head;
    printf("input number:");
    scanf("%s",n);
    while(strcmp(p->num,n)&&p!=NULL)
        p=p->next;
    if(strcmp(p->num,n))
        printf("not foud\n");
    else
        lookone(p);
}
void change()/*修改*/
{
    char n[15];
    stu *p=head;
    printf("input number:");
    scanf("%s",n);
    getchar();
    while(strcmp(p->num,n)&&p!=NULL)
        p=p->next;
    if(strcmp(p->num,n))
        printf("not foud\n");
    else
    {
       printf("you can input the data you want to change\n\n");
       get(p);
    }
}

void insert()/*插入数据*/
{
    stu *p,*p1,*p2;
    p=(stu *)malloc(sizeof(stu));
    get(p);
    p2=p1=head;
    if(head==NULL)
        head=p;
    else
        while(p1!=NULL&&p1->num<p->num)
        {
            p2=p1;
            p1=p1->next;
        }
if(p1==head)
{
    head=p;
    p->next=p2;
}
else
{
    p2->next=p;
    p->next=p1 ;
}
}
void caverage()/**中文平均值**/
{
    int n=0;
    stu *p=head;
    int max=-32768,min=32767;
    float ave=0,sum=0;
    while(p!=NULL)
    {
        if(p->chinese>max)
            max=p->chinese;
        if(p->chinese<min)
            min=p->chinese;
        sum=sum+p->chinese;
        p=p->next;
        n++;
    }
    ave=sum/n;
    printf("chinese:\n");
    printf("max=%d\t",max);
    printf("min=%d\t",min);
    printf("average is:%5.1f\n\n",ave);
}
void maverage()/**数学平均值**/
{
    int n=0;
    stu *p=head;
    int max=-32768,min=32767;
    float ave=0,sum=0;
    while(p!=NULL)
    {
        if(p->math>max)
            max=p->math;
        if(p->math<min)
            min=p->math;
        sum=sum+p->math;
        p=p->next;
        n++;
    }
    ave=sum/n;
    printf("math:\n");
    printf("max=%d\t",max);
    printf("min=%d\t",min);
    printf("average is:%5.2f\n\n",ave);
}
void eaverage()/**平均值**/
{
    int n=0;
    stu *p=head;
    int max=-32768,min=32767;
    float ave=0,sum=0;
    while(p!=NULL)
    {
        if(p->english>max)
            max=p->english;
        if(p->english<min)
            min=p->english;
        sum=sum+p->english;
        p=p->next;
        n++;
    }
    ave=sum/n;
    printf("english:\n");
    printf("max=%d\t",max);
    printf("min=%d\t",min);
    printf("average is:%5.2f\n\n",ave);
}
void cmeaverage()
{

    caverage();

    maverage();

    eaverage();
}



void avesubject()
{
    int i=0;
    printf("<1>chinese avrage score\n\n");
    printf("<2>math average score\n\n");
    printf("<3>english average score\n\n");
    printf("<4>all subject average score\n\n");
    printf("<5>exit\n");
    printf("please enter your choice from 1 to 5 :");
    while(1)
        {
        scanf("%d",&i);
        if(i<1||i>5)
            printf("enter again\n");
        else
            break;
        }
    system("cls");
    switch(i)
    {
        case 1: caverage();break;
        case 2: maverage();break;
        case 3: eaverage();break;
        case 4: cmeaverage();break;
        case 5: return;
    }

}
void lookdata()/**查看全部数据*/
{
    stu *p=head;
    printf("the student's data is:\n");
    printf("position   number\tname\t\tsex\tchinese\tmath\tenglish\taverage\n");
    while(p!=NULL)
    {
        printf("NO.%d   ",p->position);
        printf("%10s\t",p->num);
        printf("%-15s",p->name);
        printf("  %c\t",p->sex);
        printf("%d\t%d\t%d\t%5.1f\n\n",p->chinese,p->math,p->english,p->ave);
        p=p->next;
    }
}
void save (stu *p)/**保存数据**/
{
    FILE *fp;
    char file[10];
    printf("enter file name:");
    scanf("%s",file);
    if((fp=fopen(file,"wb"))==NULL)
    {
        printf("cant open this file\n");
        return;
    }
    while(p!=NULL)
    {
        fwrite(p,sizeof(stu),1,fp);
        p=p->next;
    }
    fclose(fp);
}
void print()
{
    printf("< 1>enter the data\n\n");
    printf("< 2>display the data\n\n");
    printf("< 3>insert data\n\n");
    printf("< 4>fing someone\n\n");
    printf("< 5>modify the data\n\n");
    printf("< 6>look average score in every subject\n\n");
    printf("< 7>save the data\n\n");
    printf("< 8>delete one data\n\n");
    printf("< 9>order the data\n\n");
    printf("<10>load the data\n\n");
    printf("< 0>exit");
}
void delet()
{
char n[15];
stu *p1,*p2;
char k;
printf("please input the number:");
scanf("%s",n);
getchar();
printf("Do you really want to delete this student 'y' or 'n'\n");
k=getchar();
if(k=='n'||k=='N') return;
while(k!='y'&&k!='Y')
{
    printf("please chose 'y' or 'n' ");
    k=getchar();
}
p2=p1=head;
if(head==NULL)
    {
    printf("have not found\n");
    getch();
    return;
    }
if(strcmp(p1->num,n)==0)
{
    head=p1->next;
    return;
}
while(strcmp(p1->num,n)&&p1!=NULL)
    {
    p2=p1;
    p1=p1->next;
    }
if(p1==NULL)
    {
    printf("have not found");
    return;
    }
else
    p2->next=p1->next;
printf("successfully delete this student\n");
return  ;
}


void load()
{
FILE *fp;
stu *p1,*p2;
int m=0;
char filename[20];
printf("please input the file name:");
scanf("%s",filename);

if((fp=fopen(filename,"rb"))==NULL)
    {
    printf("cannot open this file\n");

    return;
    }

p2=p1=(stu *)malloc(sizeof(stu));
while(fread(p1,sizeof(stu),1,fp)==1)
    {m++;

    if(m==1)
        head=p1;
    else
        {p2->next=p1;
        p2=p1;
        }
    p1=(stu*)malloc(sizeof(stu));
    }

p2->next=NULL;
fclose(fp);
}

void sort(stu *p1,stu *p2)
{
    char s[20];char n[20];char x;
    float c,m,e;
    float f;
    strcpy(s,p1->num);strcpy(p1->num,p2->num);strcpy(p2->num,s);
    /*s=p1->num;p1->num=p2->num;p2->num=s;*/
    strcpy(n,p1->name);strcpy(p1->name,p2->name);strcpy(p2->name,n);
    x=p1->sex;p1->sex=p2->sex;p2->sex=x;
    c=p1->chinese;p1->chinese=p2->chinese;p2->chinese=c;
    m=p1->math;p1->math=p2->math;p2->math=m;
    e=p1->english;p1->english=p2->english;p2->english=e;
    f=p1->ave;p1->ave=p2->ave;p2->ave=f;


}

void ordera()
{
    stu * p1,* p2;
    int i=1;
    if(head==NULL) return;
else
    {
    for(p1=head;p1!=NULL;p1=p1->next,++i)
        for(p2=p1->next,p1->position=i;p2!=NULL;p2=p2->next)
            if((p1->ave)<(p2->ave))
            {
                sort(p1,p2) ;
            p2->position=i;
            }
    }
}
void ordern()/*按学号排序*/
{
    stu * p1,* p2;
    int i=1;
    if(head==NULL) return;
else
    {
    for(p1=head;p1!=NULL;p1=p1->next,++i)
        for(p2=p1->next,p1->position=i;p2!=NULL;p2=p2->next)
            if(strcmp(p1->num,p2->num)>0)
            {
                sort(p1,p2) ;
                 p2->position=i;
            }
    }
}
void orderc()
{
    stu * p1,* p2;
    int i=1;
    if(head==NULL) return;
else
    {
    for(p1=head;p1!=NULL;p1=p1->next,++i)
        for(p2=p1->next,p1->position=i;p2!=NULL;p2=p2->next)
            if((p1->chinese)<(p2->chinese))
            {
                sort(p1,p2) ;
                p2->position=i;
            }
    }
}
void orderm()
{
    stu * p1,* p2;
    int i=1;
    if(head==NULL) return;
else
    {
    for(p1=head;p1!=NULL;p1=p1->next,++i)
        for(p2=p1->next,p1->position=i;p2!=NULL;p2=p2->next)
            if((p1->math)<(p2->math))
            {
                sort(p1,p2) ;
                p2->position=i;
            }
    }
}
void ordere()
{
    stu * p1,* p2;
    int i=1;
    if(head==NULL) return;
else
    {
    for(p1=head;p1!=NULL;p1=p1->next,++i)
        for(p2=p1->next,p1->position=i;p2!=NULL;p2=p2->next)
            if((p1->english)<(p2->english))
            {
                sort(p1,p2) ;
                p2->position=i;
            }
    }
}
void order()
{
    int i;
    printf("\n\n<1>order the data according to the number of student\n\n");
    printf("<2>order the data according to the average score\n\n");
    printf("<3>order the data according to the chinese score\n\n");
    printf("<4>order the data according to the math score\n\n");
    printf("<5>order the data according to the english score\n\n");
    printf("<6>exit\n");
printf("enter the choice frome 1 to 6 :");
    scanf("%d",&i);
    if(i<0||i>6)
        {
        printf("please enter choice again:");
        scanf("%d",&i);
        }
    switch(i)
    {
    case 1 :ordern();break;
    case 2 :ordera();break;
    case 3 :orderc();break;
    case 4 :orderm();break;
    case 5 :ordere();break;
    case 6 :return;

    }
system("cls");
}
    -------------Configuration: A - Win32 Debug--------------------
Compiling...
A.C
D:\A.C(31) : error C2065: 'password' : undeclared identifier
D:\A.C(31) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
D:\A.C(31) : warning C4024: 'strcmp' : different types for formal and actual parameter 2
D:\A.C(63) : warning C4013: 'print' undefined; assuming extern returning int
D:\A.C(75) : warning C4013: 'create' undefined; assuming extern returning int
D:\A.C(77) : warning C4013: 'lookdata' undefined; assuming extern returning int
D:\A.C(79) : warning C4013: 'insert' undefined; assuming extern returning int
D:\A.C(81) : warning C4013: 'find' undefined; assuming extern returning int
D:\A.C(83) : warning C4013: 'change' undefined; assuming extern returning int
D:\A.C(85) : warning C4013: 'avesubject' undefined; assuming extern returning int
D:\A.C(87) : warning C4013: 'save' undefined; assuming extern returning int
D:\A.C(89) : warning C4013: 'delet' undefined; assuming extern returning int
D:\A.C(91) : warning C4013: 'order' undefined; assuming extern returning int
D:\A.C(93) : warning C4013: 'load' undefined; assuming extern returning int
D:\A.C(108) : error C2371: 'create' : redefinition; different basic types
D:\A.C(111) : error C2371: 'insert' : redefinition; different basic types
D:\A.C(112) : error C2371: 'find' : redefinition; different basic types
D:\A.C(117) : error C2371: 'delet' : redefinition; different basic types
D:\A.C(118) : error C2371: 'order' : redefinition; different basic types
D:\A.C(119) : error C2371: 'load' : redefinition; different basic types
D:\A.C(127) : error C2371: 'print' : redefinition; different basic types
D:\A.C(230) : error C2371: 'create' : redefinition; different basic types
D:\A.C(232) : error C2065: 'x' : undeclared identifier
D:\A.C(232) : error C2223: left of '->position' must point to struct/union
D:\A.C(233) : error C2223: left of '->num' must point to struct/union
D:\A.C(234) : error C2223: left of '->name' must point to struct/union
D:\A.C(235) : error C2223: left of '->sex' must point to struct/union
D:\A.C(236) : error C2223: left of '->chinese' must point to struct/union
D:\A.C(237) : error C2223: left of '->math' must point to struct/union
D:\A.C(238) : error C2223: left of '->english' must point to struct/union
D:\A.C(239) : error C2223: left of '->ave' must point to struct/union
D:\A.C(297) : error C2371: 'find' : redefinition; different basic types
D:\A.C(375) : error C2371: 'avesubject' : redefinition; different basic types
D:\A.C(418) : error C2371: 'lookdata' : redefinition; different basic types
D:\A.C(428) : error C2065: 'p' : undeclared identifier
D:\A.C(428) : warning C4047: '!=' : 'int ' differs in levels of indirection from 'void *'
D:\A.C(430) : warning C4022: 'fwrite' : pointer mismatch for actual parameter 1
D:\A.C(431) : error C2223: left of '->next' must point to struct/union
D:\A.C(436) : error C2371: 'print' : redefinition; different basic types
D:\A.C(450) : error C2371: 'delet' : redefinition; different basic types
D:\A.C(495) : error C2371: 'load' : redefinition; different basic types
D:\A.C(536) : warning C4244: '=' : conversion from 'int ' to 'float ', possible loss of data
D:\A.C(536) : warning C4244: '=' : conversion from 'float ' to 'int ', possible loss of data
D:\A.C(537) : warning C4244: '=' : conversion from 'int ' to 'float ', possible loss of data
D:\A.C(537) : warning C4244: '=' : conversion from 'float ' to 'int ', possible loss of data
D:\A.C(538) : warning C4244: '=' : conversion from 'int ' to 'float ', possible loss of data
D:\A.C(538) : warning C4244: '=' : conversion from 'float ' to 'int ', possible loss of data
D:\A.C(625) : error C2371: 'order' : redefinition; different basic types
D:\A.C(652) : error C2040: 'password' : 'char []' differs in levels of indirection from 'int '
Error executing cl.exe.

A.exe - 28 error(s), 21 warning(s)
搜索更多相关主题的帖子: 管理 学生 运行 
2008-10-20 21:02
zhfq
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-7-9
收藏
得分:0 
程序能在TC20中运行但在C++中就不行了老出错希望那位能帮帮忙
2008-10-21 18:49
快速回复:我用C做的学生成绩管理想在VC6.0中运行可...........大家来看看吧
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.044640 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved