| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1306 人关注过本帖
标题:[求助]如何把这个C++程序改为c语言
只看楼主 加入收藏
lw817
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-1-7
收藏
 问题点数:0 回复次数:2 
[求助]如何把这个C++程序改为c语言

求助 帮我把这个C++程序改为c语言的吧 谢谢!!

#include<stdio.h>
#include<malloc.h>
#include<iostream.h>
#include<string.h>
#define len sizeof(struct school)
#define len1 sizeof(struct statitcs)
struct school
{int num;
int project_num;
char name[20];
int score;
//int no;
struct school *next;
};
struct school *insert(void)
{ cout<<"********************************\n";
cout<<"特别提示:\n";
cout<<"如果想退出,请在学校编号输入0\n";
cout<<"********************************\n";
struct school *head,*rear,*p;
head=NULL;rear=NULL;
p=(struct school *)malloc(len);
cout<<"请输入学校编号\n";cin>>p->num;
cout<<"请输入项目\n";cin>>p->project_num;
cout<<"请输入姓名\n";cin>>p->name;
cout<<"请输入成绩\n";cin>>p->score;
if(p->num==0)
return NULL;
while(p->num!=0)
{if(head==NULL)
{head=p;rear=p;}
else
{rear->next=p;
rear=p;
}
p=(struct school *)malloc(len);
cout<<"请输入学校编号\n";cin>>p->num;
cout<<"请输入项目\n";cin>>p->project_num;
cout<<"请输入姓名\n";cin>>p->name;
cout<<"请输入成绩\n";cin>>p->score;
}
rear->next=NULL;
return head;
}
struct school *add(struct school *t)
{
struct school *s,*p;
p=(struct school *)malloc(len);
cout<<"请输入学校编号\n";cin>>p->num;
cout<<"请输入项目\n";cin>>p->project_num;
cout<<"请输入姓名\n";cin>>p->name;
cout<<"请输入成绩\n";cin>>p->score;
s=t;
if(s==NULL)
{ p->next=s;
s=p;
return s;}
else
{while(s->next!=NULL)
{s=s->next;}
s->next=p;
p->next=NULL;
return t;}
}

void print(struct school *t)
{struct school *p;
p=t;
cout<<"学校编号\t项目\t姓名\t成绩\n";
while(p!=NULL)
{cout<<p->num<<"\t\t"<<p->project_num<<"\t"<<p->name<<"\t"<<p->score<<endl;
p=p->next;
}
}

void display(struct school *t,int n)
{struct school *p;
p=t;
while(p!=NULL)
{if(p->num==n)
cout<<p->project_num<<"\t"<<p->name<<"\t"<<p->score<<endl;
p=p->next;
}
}

struct school *deletes(struct school *t)
{struct school *p,*k,*k_head;int flag=0;
p=(struct school *)malloc(len);
cout<<"请输入要删除的信息\n";
cout<<"请输入学校编号\n";cin>>p->num;
cout<<"请输入项目\n";cin>>p->project_num;
cout<<"请输入姓名\n";cin>>p->name;
cout<<"请输入成绩\n";cin>>p->score;
k=t;
while(k!=NULL)
{if((p->num==k->num)&&(k->project_num==p->project_num)&&!strcmp(p->name,k->name)&&(p->score==k->score))
{flag=1;
if(k==t)
{t=t->next;}
else
k_head->next=k->next;
}
else
k_head=k;
k=k->next;
}
if(k==NULL&&flag==0)
cout<<"无法找到你要删除的信息\n";
return t;
}
void find(struct school *t)
{struct school *p;
p=t;
cout<<"学校编号\t项目\t姓名\t成绩\n";
while(p!=NULL)
{cout<<p->num<<"\t\t"<<p->project_num<<"\t"<<p->name<<"\t"<<p->score<<endl;
p=p->next;
}
}

void find1(struct school *t)
{struct school *k;int flag=0;int num;
cout<<"请输入要查找的信息\n";
cout<<"请输入学校编号\n";cin>>num;
cout<<"学校编号\t项目\t姓名\t成绩\n";
k=t;
while(k!=NULL)
{if(num==k->num)
{flag=1;cout<<k->num<<"\t\t"<<k->project_num<<"\t"<<k->name<<"\t"<<k->score<<endl;}
k=k->next;
}
if(k==NULL&&flag==0)
cout<<"无法找到你要的信息\n";
}
void find2(struct school *t)
{struct school *k;int flag=0;int num;

cout<<"请输入要查找的信息\n";
cout<<"请输入项目号\n";cin>>num;
cout<<"学校编号\t项目\t姓名\t成绩\n";
k=t;
while(k!=NULL)
{if(num==k->project_num)
{flag=1;cout<<k->num<<"\t\t"<<k->project_num<<"\t"<<k->name<<"\t"<<k->score<<endl;}
k=k->next;
}
if(k==NULL&&flag==0)
cout<<"无法找到你要的信息\n";
}
void find3(struct school *t)
{struct school *k;int flag=0;char name[20];

cout<<"请输入要查找的信息\n";
cout<<"请输入姓名\n";cin>>name;
cout<<"学校编号\t项目\t姓名\t成绩\n";
k=t;
while(k!=NULL)
{if(!strcmp(name,k->name))
{flag=1;cout<<k->num<<"\t\t"<<k->project_num<<"\t"<<k->name<<"\t"<<k->score<<endl;}
k=k->next;
}
if(k==NULL&&flag==0)
cout<<"无法找到你要的信息\n";
}

struct school *deletes1(struct school *t)
{struct school *k,*k_head;int flag=0;int num;
cout<<"请输入要删除的信息\n";
cout<<"请输入学校编号\n";cin>>num;
k=t;
while(k!=NULL)
{if(k->num==num)
{flag=1;
if(k==t)
{t=t->next;}
else
k_head->next=k->next;
}
else
k_head=k;
k=k->next;
}
if(k==NULL&&flag==0)
cout<<"无法找到你要删除的信息\n";
return t;
}

struct school *deletes2(struct school *t)
{struct school *k,*k_head;int flag=0;int num;
cout<<"请输入要删除的信息\n";
cout<<"请输入项目号\n";cin>>num;
k=t;
while(k!=NULL)
{if(k->project_num==num)
{flag=1;
if(k==t)
{t=t->next;}
else
k_head->next=k->next;
}
else
k_head=k;
k=k->next;
}
if(k==NULL&&flag==0)
cout<<"无法找到你要删除的信息\n";
return t;
}

struct school *deletes3(struct school *t)
{struct school *k,*k_head;int flag=0;char name[20];
cout<<"请输入要删除的信息\n";
cout<<"请输入姓名\n";cin>>name;
k=t;
while(k!=NULL)
{if(!strcmp(k->name,name))
{flag=1;
if(k==t)
{t=t->next;}
else
k_head->next=k->next;
}
else
k_head=k;
k=k->next;
}
if(k==NULL&&flag==0)
cout<<"无法找到你要删除的信息\n";
return t;
}

struct statitcs
{
int flag;
int total;
int no;
struct statitcs *next;
};

int total1(struct school *t,int n)
{struct school *p;
p=t;
int sum=0;
while(p!=NULL)
{if(p->num==n)
sum+=p->score;
p=p->next;
}
return sum;
}

void swap(struct statitcs *t1,struct statitcs *t2)
{struct statitcs *t;
t=(struct statitcs *)malloc(len1);
t->flag=t1->flag;t1->flag=t2->flag;t2->flag=t->flag;
t->total=t1->total;t1->total=t2->total;t2->total=t->total;
}

struct statitcs *set_place(struct statitcs *t)
{int i=1;
struct statitcs *p,*q;
p=t;
if(p==NULL)return t;
else
{p->no=1;
while(p->next!=NULL)
{q=p->next;

a:if((q->total==p->total))
{q->no=p->no;q=q->next;
if(q==NULL) return t;
goto a;}
if(q==NULL) return t;
else{p=q;i++;p->no=i;}
}
}
return t;
}

struct statitcs * sort( struct statitcs *t)
{struct statitcs *p1,*p2;
p1=t;
while(p1!=NULL)
{ p2=p1->next;

while(p2!=NULL)
{if((p1->total)<(p2->total))
swap(p1,p2);
p2=p2->next;
}
p1=p1->next;
}
return t;
}

void show(struct statitcs *t,struct school *t1)
{struct statitcs *p;
p=t;
while(p!=NULL)
{
cout<<"\n学校编号"<<p->flag<<endl;
cout<<"项目\t"<<"姓名\t"<<"成绩"<<endl;
display(t1,p->flag);
cout<<"\t总成绩"<<p->total<<"\t总名次:"<<p->no<<endl;
p=p->next;
}
}

struct statitcs *creat(struct school *t)
{int a[100];int i=0;int flag1;
struct statitcs *head,*rear,*p;
struct school *k;k=t;
head=NULL;if(k==NULL)return NULL;
p=(struct statitcs *)malloc(len1);
p->flag=k->num;
p->total=total1(t,p->flag);
if(head==NULL)
head=p;rear=p;
k=k->next;
a=p->flag;
while(k!=NULL)
{flag1=1;
for(int m=0;m<=i;m++)
if(a[m]==k->num)
flag1=0;
if(flag1)
{p=(struct statitcs *)malloc(len1);
p->flag=k->num; i++;a=p->flag;
p->total=total1(t,p->flag);
rear->next=p;rear=p;}
k=k->next;
}
rear->next=NULL;
return head;
}
void swap1(struct school *t1, struct school *t2)
{struct school *t;
t=(struct school *)malloc(len);
t->num=t1->num;t1->num=t2->num;t2->num=t->num;
t->score=t1->score;t1->score=t2->score;t2->score=t->score;
strcmp(t->name,t1->name);strcmp(t1->name,t2->name);strcmp(t2->name,t->name);
}
struct school * sort1( struct school *t,int n)
{struct school *p1,*p2;
p1=t;
while(p1!=NULL)
{ p2=p1->next;

while(p2!=NULL&&p1->project_num==n&&p2->project_num==n)
{if((p1->score)<(p2->score))
swap1(p1,p2);
p2=p2->next;
}
p1=p1->next;
}
return t;
}
/*struct school *setplace1(struct school *t,int n)
{int i=1;
struct school *p,*q;
p=t;
if(p==NULL)return t;
else
{if(p->project_num==n)
p->no=1;
while(p->next!=NULL)
{q=p->next;
a:if((q->score==p->score)&&p->project_num==n&&q->project_num==n)
{q->no=p->no;q=q->next;
if(q==NULL) return t;
goto a;}
if(q==NULL) return t;
else{p=q;
if((q->score==p->score)&&p->project_num==n&&q->project_num==n)
{i++;p->no=i;}}
}
}
return t;
}
*/
void show1(struct school *t,int n)
{struct school *p;
p=t;
cout<<"项目:"<<n<<"\n学校编号\t"<<"姓名\t"<<"成绩\t"<<endl;
while(p!=NULL)
{if(p->project_num==n)
cout<<p->num<<"\t\t"<<p->name<<"\t"<<p->score<<"\t"<<endl;
p=p->next;
}
}

void sort_display(struct school *t)
{int a[100];int i=0;int flag1;
struct school *k;k=t;
if(k==NULL)cout<< "NULL\n";
a=k->project_num;
k=k->next;
while(k!=NULL)
{flag1=1;
for(int m=0;m<=i;m++)
if(a[m]==k->project_num)
flag1=0;
if(flag1)
{i++;a=k->project_num;}
k=k->next;
}
for(int m=0;m<=i;m++)
{t=sort1(t,a[m]);
//setplace1(t,a[m]);
show1(t,a[m]);
}
}

void main()
{struct school *t;struct statitcs *s;char a;int flag=1,flag1=1,flag2=1;
t=NULL;
cout<<"\t\t***************************************************\n";
cout<<" \t\t *请勿盗版*\t *请勿盗版*\t *请勿盗版*\n ";
cout<<"\t\t\t\t产品信息:\n\t\t\t\t学号:020410107\n\t\t\t\t姓名:胡小勇\n\t\t\t\t电子邮件:huxiaoyong1983@163.com\n\t\t\t\t电话:0631-5696421\n";
cout<<" \t\t\t\t使用有问题 请与我联系\n\t\t *请勿盗版*\t *请勿盗版*\t *请勿盗版*\n ";
cout<<"\t\t***************************************************\n";
cout<<"\t\t***************************************************\n";
cout<<"\t\t\t 运动会信息管理系统\n\t\t\t\t1:创建信息\n\t\t\t\t2:添加信息\n\t\t\t\t3:删除信息\n\t\t\t\t4:查找信息\n\t\t\t\t5:排序并显示\n\t\t\t\t6:退出\n";
cout<<"\t\t***************************************************\n";
cin>>a;
while(a!='6')
{switch(a)
{case'1':flag=0;flag1=0;flag2=0;
t=insert();
cout<<"你输入的所有信息\n";
print(t);break;
case'2':cout<<"*****************\n1:添加一条信息\n2:退出\n*****************\n";
cin>>a;
while(a!='2')
{switch(a)
{case'1':t=add(t);break;
default:cout<<"\n请正确输入\n";break;
}
cout<<"*****************\n1:添加一条信息\n2:退出\n*****************\n";
cin>>a;
}
print(t);
break;
case'3':if(flag==1)
{cout<<"\t\t请先输入数据\n";break;}
cout<<"\t\t***************************************************\n";
cout<<"\t\t\t1:删除某一学校某一项目某一姓名某一成绩的信息\n\t\t\t2:删除某一学校的信息\n\t\t\t3:删除某一项目的信息\n\t\t\t4:删除某一姓名的信息\n\t\t\t5:退出\n";
cout<<"\t\t***************************************************\n";
cin>>a;
while(a!='5')
{switch(a)
{case'1':t=deletes(t); cout<<"删除后的信息\n";print(t);break;
case'2':t=deletes1(t);cout<<"删除后的信息\n"; print(t);break;
case'3':t=deletes2(t); cout<<"删除后的信息\n"; print(t);break;
case'4':t=deletes3(t); cout<<"删除后的信息\n";print(t);break;
default:cout<<"请正确输入\n";break;
}
cout<<"\t\t***************************************************\n";
cout<<"\t\t\t1:删除某一学校某一项目某一姓名某一成绩的信息\n\t\t\t2:删除某一学校的信息\n\t\t\t3:删除某一项目的信息\n\t\t\t4:删除某一姓名的信息\n\t\t\t5:退出\n";
cout<<"\t\t***************************************************\n";
cin>>a;
}
break;
case'4':if(flag2==1)
{cout<<"\t\t请先输入数据\n";break;}
cout<<"\t\t***************************************************\n";
cout<<"\t\t\t1:查找所有信息\n\t\t\t2:查找某一学校的信息\n\t\t\t3:查找某一项目的信息\n\t\t\t4:查找某一姓名的信息\n\t\t\t5:退出\n";
cout<<"\t\t***************************************************\n";
cin>>a;
while(a!='5')
{switch(a)
{case'1':find(t);break;
case'2':find1(t);break;
case'3':find2(t);break;
case'4':find3(t);break;
default:cout<<"请正确输入\n";break;
}
cout<<"\t\t***************************************************\n";
cout<<"\t\t\t1:查找所有信息\n\t\t\t2:查找某一学校的信息\n\t\t\t3:查找某一项目的信息\n\t\t\t4:查找某一姓名的信息\n\t\t\t5:退出\n";
cout<<"\t\t***************************************************\n";
cin>>a;
}
break;
case'5':if(flag1==1)
{cout<<"\t\t请先输入数据\n";break;}
cout<<"\t\t*************************************\n";
cout<<"\t\t1:按学校总成绩排序\n\t\t2:按每个项目的成绩高低排序\n\t\t3:退出\n";
cout<<"\t\t*************************************\n";
cin>>a;
while(a!='3')
{switch(a)
{case'1':s=creat(t);s=sort(s);s=set_place(s);show(s,t);break;
case'2':sort_display(t);break;
default:cout<<"请正确输入\n";break;
}
cout<<"\t\t*************************************\n";
cout<<"\t\t1:按学校总成绩排序\n\t\t2:按每个项目的成绩高低排序\n\t\t3:退出\n";
cout<<"\t\t*************************************\n";
cin>>a;
}
break;
default:cout<<"请正确输入\n";
}
cout<<"\t\t***************************************************\n";
cout<<"\t\t\t 运动会成绩信息系统\n\t\t\t\t1:创建信息\n\t\t\t\t2:添加信息\n\t\t\t\t3:删除信息\n\t\t\t\t4:查找信息\n\t\t\t\t5:排序并显示\n\t\t\t\t6:退出\n";
cout<<"\t\t***************************************************\n";
cin>>a;
}
cout<<"谢谢使用\n";
}


搜索更多相关主题的帖子: c语言 
2006-01-08 12:59
woodhead
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:1124
专家分:0
注 册:2005-7-18
收藏
得分:0 
找个cfront

2006-01-08 22:14
rayer
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-1-13
收藏
得分:0 

...怎么感觉这个就是C语言啊....
STRUCT漫天飞~
而且没有对象...

改下输出和输入就好了...汗.....


/*冬日阳光*/ 选择你,对吗??
2006-01-13 02:15
快速回复:[求助]如何把这个C++程序改为c语言
数据加载中...
 
   



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

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