C语言问题

作者在 2011-05-29 22:10:22 发布以下内容
 编写几个函数:()输入10个职工的姓名和职工号;()按职工号由小到大顺序排序,姓名顺序也随之调整;()要求输入一个职工号,找出该职工的姓名,从主函数输入要查找的职工号,输出该职工姓名。
谁会写这个程序啊,用c语言写
默认分类 | 阅读 1661 次
文章评论,共6条
烟雾中的迷茫
2011-05-29 22:38
1
好像写过<img src="image/face/1.gif" class="face">
宇智波曌(作者)
2011-05-30 12:19
2
<div class="quote"><span class="q"><b>烟雾中的迷茫</b>: 好像写过<img src="image/face/1.gif" class="face"></span></div>能帮我写一下吗?用c语言。<img src="image/face/2.gif" class="face">
烟雾中的迷茫
2011-05-30 12:53
3
唉 我写了 不过好像有点问题等调试好了再供你参考吧
kemoo
2011-06-04 11:14
4
用那个结构体好像可以
blackbansy
2011-06-07 00:05
5
//编写几个函数:(1)输入10个职工的姓名和职工号;(2)按职工号由小到大顺序排序,姓名顺序也随之调整;<br />
//(3)要求输入一个职工号,找出该职工的姓名,从主函数输入要查找的职工号,输出该职工姓名。<br />
#include&lt;stdio.h&gt;<br />
#include&lt;string.h&gt;<br />
#include&lt;conio.h&gt;<br />
int compare(char *no1,char *no2);<br />
void InputData(struct worker person[],int n);<br />
void SortData(struct worker person[],int n);<br />
void SearchData(struct worker person[],int n);<br />
void print(struct worker person[],int n);<br />
struct worker<br />
{<br />
char name[20];<br />
char no[10];<br />
}ps[20];<br />
void main()<br />
{<br />
//输入数据<br />
&nbsp; &nbsp; &nbsp; &nbsp; int n;<br />
 printf(&quot;你想输入多少个职工的数据\n&quot;);<br />
 scanf(&quot;%d&quot;,&amp;n);<br />
 InputData(ps,n);<br />
 //排序<br />
 SortData(ps,n);<br />
 print(ps,n);<br />
 //查找<br />
SearchData(ps,n);<br />
<br />
}<br />
//输入数据&nbsp; &nbsp; &nbsp; &nbsp; <br />
void InputData(struct worker person[],int n)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
int c;<br />
printf(&quot;请你输入%d员工的资料\n&quot;,n);<br />
int i;<br />
getchar(c);<br />
for(i=0;i&lt;n;i++)<br />
{<br />
printf(&quot;职工号:&quot;);<br />
gets(person<i>.no);<br />
printf(&quot;姓名:&quot;);<br />
gets(person<i>.name);<br />
}<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
//排序<br />
void SortData(struct worker person[],int n)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;\n排序结果:&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; int i,j;<br />
&nbsp; &nbsp; &nbsp; &nbsp; struct worker t;<br />
&nbsp; &nbsp; &nbsp; &nbsp; for(i=0;i&lt;n-1;i++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(j=0;j&lt;n-i-1;j++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(compare(person<i>.no,person[i+1].no)&gt;0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t=person<i>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; person<i>=person[i+1];<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; person[i+1]=t;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
//查找<br />
void SearchData(struct worker person[],int n)<br />
{<br />
int i;<br />
char no[10];<br />
printf(&quot;\n请你输入一个职工号\n&quot;);<br />
gets(no);<br />
for(i=0;i&lt;n;i++)<br />
if(!strcmp(no,person<i>.no))<br />
{<br />
printf(&quot;\n可找到相符的数据&quot;);<br />
printf(&quot;\n学号: %s&quot;,person<i>.no);<br />
printf(&quot;\n姓名: %s\n&quot;,person<i>.name);<br />
break;<br />
}<br />
if(i==n)<br />
printf(&quot;\n找不到相符的数据&quot;);<br />
}<br />
//输出<br />
void print(struct worker person[],int n)<br />
{<br />
int i;<br />
for(i=0;i&lt;n;i++)<br />
{<br />
printf(&quot;\n学号: %s&quot;,person<i>.no);<br />
printf(&quot;\n姓名: %s&quot;,person<i>.name);<br />
}<br />
<br />
<br />
<br />
}<br />
//职工号比较<br />
int compare(char *no1,char *no2)<br />
{<br />
int i=0,j=0;<br />
long a=0,b=0;<br />
while(no1<i>!='\0')<br />
{<br />
a=a*10;<br />
a=a+no1<i>;<br />
i++;<br />
}<br />
while(no2[j]!='\0')<br />
{<br />
b=b*10;<br />
b=b+no1[j];<br />
j++;<br />
}<br />
if(a&gt;b)<br />
return 1;<br />
else return 0;<br />
<br />
}
gao812qiang
2011-06-10 13:57
6
c:\users\gq\documents\c语言\程序\cpp1.cpp(38) : error C2228: left of '.no' must have class/struct/union type<br />
c:\users\gq\documents\c语言\程序\cpp1.cpp(40) : error C2228: left of '.name' must have class/struct/union type<br />
c:\users\gq\documents\c语言\程序\cpp1.cpp(52) : error C2228: left of '.no' must have class/struct/union type<br />
c:\users\gq\documents\c语言\程序\cpp1.cpp(54) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct worker []' (or there is no acceptable conversion)<br />
c:\users\gq\documents\c语言\程序\cpp1.cpp(55) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct worker' (or there is no acceptable conversion)<br />
c:\users\gq\documents\c语言\程序\cpp1.cpp(68) : error C2228: left of '.no' must have class/struct/union type<br />
c:\users\gq\documents\c语言\程序\cpp1.cpp(71) : error C2228: left of '.no' must have class/struct/union type<br />
c:\users\gq\documents\c语言\程序\cpp1.cpp(72) : error C2228: left of '.name' must have class/struct/union type<br />
c:\users\gq\documents\c语言\程序\cpp1.cpp(84) : error C2228: left of '.no' must have class/struct/union type<br />
c:\users\gq\documents\c语言\程序\cpp1.cpp(85) : error C2228: left of '.name' must have class/struct/union type<br />
c:\users\gq\documents\c语言\程序\cpp1.cpp(99) : error C2440: '=' : cannot convert from 'char *' to 'long'<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;This conversion requires a reinterpret_cast, a C-style cast or function-style cast<br />
执行 cl.exe 时出错.
游客请输入验证码
文章分类
文章归档