1

物联网204-03-曹永凯 发表于2020年12月22日
<p>#include &lt;stdio.h&gt;<br >#include &lt;windows.h&gt;<br >#define N 10</p><p>struct Date{<br >&nbsp;&nbsp;int year;<br >&nbsp;&nbsp;int month;<br >&nbsp;&nbsp;int day;<br >};</p><p>struct Student {<br >&nbsp;&nbsp;int num;<br >&nbsp;&nbsp;char name[10];<br >&nbsp;&nbsp;char id[19];<br >&nbsp;&nbsp;Date brithday;<br >&nbsp;&nbsp;char sex;//sex为性别,需用char字符定义<br >&nbsp;&nbsp;int age;<br >&nbsp;&nbsp;double score[5];//分数有小数,需用双精度浮点型<br >&nbsp;&nbsp;char addr[100];<br >&nbsp;&nbsp;char tel[12];<br >&nbsp;&nbsp;char email[20];<br >}s; //s是struct结构体的变量</p><p>void display(struct Student *s,int count){<br >&nbsp;for(int i=0;i&lt;count;i++){<br >&nbsp;&nbsp;system(&quot;color B0&quot;);<br >&nbsp;&nbsp;&nbsp;printf(&quot;\n\n&quot;);<br >&nbsp;&nbsp;&nbsp;printf(&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 学生信息系统\n&quot;);<br >&nbsp;&nbsp;&nbsp;printf(&quot; ------------------------------------\n&quot;);<br >&nbsp;&nbsp;&nbsp;printf(&quot; 学号:%d\n\n&quot;,(*(s+i)).num);<br >&nbsp;&nbsp;&nbsp;printf(&quot; 姓名:%s\n\n&quot;,(*(s+i)).name);<br >&nbsp;&nbsp;&nbsp;printf(&quot; ID号:%s\n\n&quot;,(*(s+i)).id);<br >&nbsp;&nbsp;&nbsp;printf(&quot; 出生日期:%d-%d-%d\n\n&quot;,(*(s+i)).brithday.year,(*(s+i)).brithday.month,(*(s+i)).brithday.day);<br >&nbsp;&nbsp;&nbsp;printf(&quot; 性别:%c\n\n&quot;,(*(s+i)).sex);<br >&nbsp;&nbsp;&nbsp;printf(&quot; 年龄:%d\n\n&quot;,(*(s+i)).age);<br >&nbsp;&nbsp;&nbsp;printf(&quot; 成绩:%.0f,%.0f,%.0f,%.0f,%.0f\n\n&quot;,(*(s+i)).score[0],(*(s+i)).score[1],(*(s+i)).score[2],(*(s+i)).score[3],(*(s+i)).score[4]);<br >&nbsp;&nbsp;&nbsp;printf(&quot; 家庭地址:%s\n\n&quot;,(*(s+i)).addr);<br >&nbsp;&nbsp;&nbsp;printf(&quot; 联系方式:%s\n\n&quot;,(*(s+i)).tel);<br >&nbsp;&nbsp;&nbsp;printf(&quot; QQ邮箱:%s\n\n&quot;,(*(s+i)).email);<br >&nbsp;&nbsp;&nbsp;printf(&quot; ------------------------------------\n\n&quot;);<br >&nbsp;}<br >}</p><p>int addOneStudent(struct Student *s,int count){<br >&nbsp;if(count+1&gt;N){<br >&nbsp;&nbsp;printf(&quot;存储空间不足!&quot;);<br >&nbsp;&nbsp;return 0; <br >&nbsp;}else {<br >&nbsp;&nbsp;int i;<br >&nbsp;&nbsp;system(&quot;color B0&quot;);<br >&nbsp;&nbsp;&nbsp;printf(&quot;\n\n&quot;);<br >&nbsp;&nbsp;&nbsp;printf(&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 学生信息系统\n&quot;);<br >&nbsp;&nbsp;&nbsp;printf(&quot; ------------------------------------\n&quot;);&nbsp;&nbsp;<br >&nbsp;&nbsp;&nbsp;printf(&quot; 学号:&quot;);<br >&nbsp;&nbsp;&nbsp;scanf(&quot;%d&quot;,&amp;((*(s+i)).num));<br >&nbsp;&nbsp;&nbsp;getchar();<br >&nbsp;&nbsp;&nbsp;printf(&quot; 姓名:&quot;);<br >&nbsp;&nbsp;&nbsp;scanf(&quot;%s&quot;,(*(s+i)).name);<br >&nbsp;&nbsp;&nbsp;getchar();<br >&nbsp;&nbsp;&nbsp;printf(&quot; ID号:&quot;);<br >&nbsp;&nbsp;&nbsp;scanf(&quot;%s&quot;,(*(s+i)).id);<br >&nbsp;&nbsp;&nbsp;getchar();<br >&nbsp;&nbsp;&nbsp;printf(&quot; 出生日期:&quot;);<br >&nbsp;&nbsp;&nbsp;scanf(&quot;%d-%d-%d&quot;,&amp;((*(s+i)).brithday.year),&amp;((*(s+i)).brithday.month),&amp;((*(s+i)).brithday.day));<br >&nbsp;&nbsp;&nbsp;getchar();<br >&nbsp;&nbsp;printf(&quot; 性别:&quot;);<br >&nbsp;&nbsp;scanf(&quot;%c&quot;,&amp;((*(s+i)).sex));<br >&nbsp;&nbsp;&nbsp;getchar();<br >&nbsp;&nbsp;&nbsp;printf(&quot; 年龄:&quot;);<br >&nbsp;&nbsp;&nbsp;scanf(&quot;%d&quot;,&amp;((*(s+i)).age));<br >&nbsp;&nbsp;&nbsp;getchar();<br >&nbsp;&nbsp;&nbsp;printf(&quot; 成绩:&quot;);<br >&nbsp;&nbsp;&nbsp;scanf(&quot;%lf,%lf,%lf,%lf,%lf&quot;,&amp;((*(s+i)).score[0]),&amp;((*(s+i)).score[1]),&amp;((*(s+i)).score[2]),&amp;((*(s+i)).score[3]),&amp;((*(s+i)).score[4]));<br >&nbsp;&nbsp;&nbsp;getchar();<br >&nbsp;&nbsp;printf(&quot; 家庭地址:&quot;);<br >&nbsp;&nbsp;scanf(&quot;%s&quot;,(*(s+i)).addr);<br >&nbsp;&nbsp;&nbsp;getchar();<br >&nbsp;&nbsp;&nbsp;printf(&quot; 联系方式:&quot;);<br >&nbsp;&nbsp;&nbsp;scanf(&quot;%s&quot;,(*(s+i)).tel);<br >&nbsp;&nbsp;&nbsp;getchar();<br >&nbsp;&nbsp;&nbsp;printf(&quot; QQ邮箱:&quot;);<br >&nbsp;&nbsp;&nbsp;scanf(&quot;%s&quot;,(*(s+i)).email);<br >&nbsp;&nbsp;&nbsp;getchar();<br >&nbsp;&nbsp;&nbsp;printf(&quot; ------------------------------------\n\n&quot;);<br >&nbsp;&nbsp;return 1;<br >&nbsp;}<br >&nbsp;<br >}</p><p>int main(){<br >&nbsp;//Student s;调用struct结构体时,可以只调用结构体的名字 <br >&nbsp;&nbsp; Student s[N]={<br >&nbsp; &nbsp;{1,<br >&nbsp; &nbsp;&quot;曹永凯&quot;,<br >&nbsp; &nbsp;&quot;411626200310095018&quot;,<br >&nbsp; &nbsp;{2002,10,9},<br >&nbsp; &nbsp;'M',<br >&nbsp; &nbsp;18,<br >&nbsp; &nbsp;{96,97,98,99,100},<br >&nbsp; &nbsp;&quot;河南省周口市淮阳区&quot;,<br >&nbsp; &nbsp;&quot;15061885350&quot;,<br >&nbsp; &nbsp;&quot;3096586943@qq.com&quot;},<br >&nbsp; &nbsp;{2,<br >&nbsp; &nbsp;&quot;彭飞翔&quot;,<br >&nbsp; &nbsp;&quot;222222222222&quot;,<br >&nbsp; &nbsp;{2222,2,2},<br >&nbsp; &nbsp;'M',<br >&nbsp; &nbsp;18,<br >&nbsp; &nbsp;{96,97,98,99,100},<br >&nbsp; &nbsp;&quot;河南省周口市淮阳区&quot;,<br >&nbsp; &nbsp;&quot;15061885350&quot;,<br >&nbsp; &nbsp;&quot;3096586943@qq.com&quot;},<br >&nbsp; &nbsp;{3,<br >&nbsp; &nbsp;&quot;曹永凯&quot;,<br >&nbsp; &nbsp;&quot;411626200310095018&quot;,<br >&nbsp; &nbsp;{2002,10,9},<br >&nbsp; &nbsp;'M',<br >&nbsp; &nbsp;18,<br >&nbsp; &nbsp;{96,97,98,99,100},<br >&nbsp; &nbsp;&quot;河南省周口市淮阳区&quot;,<br >&nbsp; &nbsp;&quot;15061885350&quot;,<br >&nbsp; &nbsp;&quot;3096586943@qq.com&quot;},<br >&nbsp; &nbsp;{4,<br >&nbsp; &nbsp;&quot;曹永凯&quot;,<br >&nbsp; &nbsp;&quot;411626200310095018&quot;,<br >&nbsp; &nbsp;{2002,10,9},<br >&nbsp; &nbsp;'M',<br >&nbsp; &nbsp;18,<br >&nbsp; &nbsp;{96,97,98,99,100},<br >&nbsp; &nbsp;&quot;河南省周口市淮阳区&quot;,<br >&nbsp; &nbsp;&quot;15061885350&quot;,<br >&nbsp; &nbsp;&quot;3096586943@qq.com&quot;},<br >&nbsp; &nbsp;{5,<br >&nbsp; &nbsp;&quot;曹永凯&quot;,<br >&nbsp; &nbsp;&quot;411626200310095018&quot;,<br >&nbsp; &nbsp;{2002,10,9},<br >&nbsp; &nbsp;'M',<br >&nbsp; &nbsp;18,<br >&nbsp; &nbsp;{96,97,98,99,100},<br >&nbsp; &nbsp;&quot;河南省周口市淮阳区&quot;,<br >&nbsp; &nbsp;&quot;15061885350&quot;,<br >&nbsp; &nbsp;&quot;3096586943@qq.com&quot;}<br >&nbsp;&nbsp;&nbsp; <br >&nbsp;};<br >&nbsp;int count = 5;<br >&nbsp;display(s,count);<br >&nbsp;if(addOneStudent(&amp;s[count],count)){<br >&nbsp;&nbsp;&nbsp; &nbsp;count++;<br >&nbsp;&nbsp;&nbsp; }<br >display(s,count);<br >&nbsp;return 0;<br >}</p><p><br ></p>
2 回复

    1楼

  • 物联网204-03-曹永凯 发表于2020年12月25日
    0 | 0 | 举报
    <p>#include &lt;stdio.h&gt;</p><p>#include &lt;windows.h&gt;</p><p>#define N 10</p><p><br ></p><p>struct Date{</p><p>&nbsp; int year;</p><p>&nbsp; int month;</p><p>&nbsp; int day;</p><p>};</p><p><br ></p><p>struct Student {</p><p>&nbsp; int num;</p><p>&nbsp; char name[10];</p><p>&nbsp; char id[19];</p><p>&nbsp; Date brithday;</p><p>&nbsp; char sex;//sex为性别,需用char字符定义</p><p>&nbsp; int age;</p><p>&nbsp; double score[5];//分数有小数,需用双精度浮点型</p><p>&nbsp; char addr[100];</p><p>&nbsp; char tel[12];</p><p>&nbsp; char email[20];</p><p>}s; //s是struct结构体的变量</p><p><br ></p><p>void display(struct Student *s,int count){</p><p>&nbsp;for(int i=0;i&lt;count;i++){</p><p>&nbsp; system(&quot;color B0&quot;);</p><p>&nbsp; &nbsp;printf(&quot;\n\n&quot;);</p><p>&nbsp; &nbsp;printf(&quot;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 学生信息系统\n&quot;);</p><p>&nbsp; &nbsp;printf(&quot; ------------------------------------\n&quot;);</p><p>&nbsp; &nbsp;printf(&quot; 学号:%d\n\n&quot;,(*(s+i)).num);</p><p>&nbsp; &nbsp;printf(&quot; 姓名:%s\n\n&quot;,(*(s+i)).name);</p><p>&nbsp; &nbsp;printf(&quot; ID号:%s\n\n&quot;,(*(s+i)).id);</p><p>&nbsp; &nbsp;printf(&quot; 出生日期:%d-%d-%d\n\n&quot;,(*(s+i)).brithday.year,(*(s+i)).brithday.month,(*(s+i)).brithday.day);</p><p>&nbsp; &nbsp;printf(&quot; 性别:%c\n\n&quot;,(*(s+i)).sex);</p><p>&nbsp; &nbsp;printf(&quot; 年龄:%d\n\n&quot;,(*(s+i)).age);</p><p>&nbsp; &nbsp;printf(&quot; 成绩:%.0f,%.0f,%.0f,%.0f,%.0f\n\n&quot;,(*(s+i)).score[0],(*(s+i)).score[1],(*(s+i)).score[2],(*(s+i)).score[3],(*(s+i)).score[4]);</p><p>&nbsp; &nbsp;printf(&quot; 家庭地址:%s\n\n&quot;,(*(s+i)).addr);</p><p>&nbsp; &nbsp;printf(&quot; 联系方式:%s\n\n&quot;,(*(s+i)).tel);</p><p>&nbsp; &nbsp;printf(&quot; QQ邮箱:%s\n\n&quot;,(*(s+i)).email);</p><p>&nbsp; &nbsp;printf(&quot; ------------------------------------\n\n&quot;);</p><p>&nbsp;}</p><p>}</p><p><br ></p><p>int addOneStudent(struct Student *s,int count){</p><p>&nbsp;if(count+1&gt;N){</p><p>&nbsp; printf(&quot;存储空间不足!&quot;);</p><p>&nbsp; return 0;&nbsp;</p><p>&nbsp;}else {</p><p>&nbsp; int i;</p><p>&nbsp; &nbsp; system(&quot;color B0&quot;);</p><p>&nbsp; &nbsp; printf(&quot;\n\n&quot;);</p><p>&nbsp; &nbsp; printf(&quot;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 学生信息系统\n&quot;);</p><p>&nbsp; &nbsp; printf(&quot; ------------------------------------\n&quot;);&nbsp;&nbsp;</p><p>&nbsp; &nbsp; printf(&quot; 学号:&quot;);</p><p>&nbsp; &nbsp; scanf(&quot;%d&quot;,&amp;((*(s+i)).num));</p><p>&nbsp; &nbsp; getchar();</p><p>&nbsp; &nbsp; printf(&quot; 姓名:&quot;);</p><p>&nbsp; &nbsp; scanf(&quot;%s&quot;,(*(s+i)).name);</p><p>&nbsp; &nbsp; getchar();</p><p>&nbsp; &nbsp; printf(&quot; ID号:&quot;);</p><p>&nbsp; &nbsp; scanf(&quot;%s&quot;,(*(s+i)).id);</p><p>&nbsp; &nbsp; getchar();</p><p>&nbsp; &nbsp; printf(&quot; 出生日期:&quot;);</p><p>&nbsp; &nbsp; scanf(&quot;%d-%d-%d&quot;,&amp;((*(s+i)).brithday.year),&amp;((*(s+i)).brithday.month),&amp;((*(s+i)).brithday.day));</p><p>&nbsp; &nbsp; getchar();</p><p>&nbsp; &nbsp; printf(&quot; 性别:&quot;);</p><p>&nbsp; &nbsp; scanf(&quot;%c&quot;,&amp;((*(s+i)).sex));</p><p>&nbsp; &nbsp; getchar();</p><p>&nbsp; &nbsp; printf(&quot; 年龄:&quot;);</p><p>&nbsp; &nbsp; scanf(&quot;%d&quot;,&amp;((*(s+i)).age));</p><p>&nbsp; &nbsp; getchar();</p><p>&nbsp; &nbsp; printf(&quot; 成绩:&quot;);</p><p>&nbsp; &nbsp; scanf(&quot;%lf,%lf,%lf,%lf,%lf&quot;,&amp;((*(s+i)).score[0]),&amp;((*(s+i)).score[1]),&amp;((*(s+i)).score[2]),&amp;((*(s+i)).score[3]),&amp;((*(s+i)).score[4]));</p><p>&nbsp; &nbsp; getchar();</p><p>&nbsp; printf(&quot; 家庭地址:&quot;);</p><p>&nbsp; scanf(&quot;%s&quot;,(*(s+i)).addr);</p><p>&nbsp; &nbsp; getchar();</p><p>&nbsp; &nbsp; printf(&quot; 联系方式:&quot;);</p><p>&nbsp; &nbsp; scanf(&quot;%s&quot;,(*(s+i)).tel);</p><p>&nbsp; &nbsp; getchar();</p><p>&nbsp; &nbsp; printf(&quot; QQ邮箱:&quot;);</p><p>&nbsp; &nbsp; scanf(&quot;%s&quot;,(*(s+i)).email);</p><p>&nbsp; &nbsp; getchar();</p><p>&nbsp; &nbsp; printf(&quot; ------------------------------------\n\n&quot;);</p><p>&nbsp; &nbsp; return 1;</p><p>&nbsp;}</p><p>}</p><p><br ></p><p>void delastudentBy(struct Student *s,int *count,int num){</p><p> int i;</p><p> for(i=0;i&lt;*count;i++){</p><p> if(s[i].num==num){</p><p> break;</p><p> }</p><p> }</p><p> if(i==*count){</p><p> printf(&quot;该学生信息不在此系统内!\n&quot;);</p><p> }else{</p><p> for(;i+1&lt;*count;i++){</p><p> s[i]=s[i+1];&nbsp;</p><p> }&nbsp;</p><p> }</p><p> (*count)--;&nbsp;</p><p>}</p><p><br ></p><p>void updateastudentByNUB(struct Student *s,int *count,int num){</p><p> int i;</p><p> for(i=0;i&lt;*count;i++){</p><p> if(s[i].num==num){</p><p> break;</p><p> }</p><p> }</p><p> if(i==*count){</p><p> printf(&quot;该学生信息无法更新!\n&quot;);</p><p> }else{</p><p> addOneStudent(&amp;s[i],*count);</p><p> }&nbsp;</p><p>}</p><p><br ></p><p><br ></p><p>int main(){</p><p>&nbsp;//Student s;调用struct结构体时,可以只调用结构体的名字&nbsp;</p><p>&nbsp; &nbsp;Student s[N]={</p><p>&nbsp; &nbsp;{1,</p><p>&nbsp; &nbsp;&quot;曹永凯&quot;,</p><p>&nbsp; &nbsp;&quot;411626200310095018&quot;,</p><p>&nbsp; &nbsp;{2002,10,9},</p><p>&nbsp; &nbsp;'M',</p><p>&nbsp; &nbsp;18,</p><p>&nbsp; &nbsp;{96,97,98,99,100},</p><p>&nbsp; &nbsp;&quot;河南省周口市淮阳区&quot;,</p><p>&nbsp; &nbsp;&quot;15061885350&quot;,</p><p>&nbsp; &nbsp;&quot;3096586943@qq.com&quot;},</p><p>&nbsp; &nbsp;{2,</p><p>&nbsp; &nbsp;&quot;彭飞翔&quot;,</p><p>&nbsp; &nbsp;&quot;222222222222&quot;,</p><p>&nbsp; &nbsp;{2222,2,2},</p><p>&nbsp; &nbsp;'M',</p><p>&nbsp; &nbsp;18,</p><p>&nbsp; &nbsp;{96,97,98,99,100},</p><p>&nbsp; &nbsp;&quot;河南省周口市淮阳区&quot;,</p><p>&nbsp; &nbsp;&quot;15061885350&quot;,</p><p>&nbsp; &nbsp;&quot;3096586943@qq.com&quot;},</p><p>&nbsp; &nbsp;{3,</p><p>&nbsp; &nbsp;&quot;曹永凯&quot;,</p><p>&nbsp; &nbsp;&quot;411626200310095018&quot;,</p><p>&nbsp; &nbsp;{2002,10,9},</p><p>&nbsp; &nbsp;'M',</p><p>&nbsp; &nbsp;18,</p><p>&nbsp; &nbsp;{96,97,98,99,100},</p><p>&nbsp; &nbsp;&quot;河南省周口市淮阳区&quot;,</p><p>&nbsp; &nbsp;&quot;15061885350&quot;,</p><p>&nbsp; &nbsp;&quot;3096586943@qq.com&quot;},</p><p>&nbsp; &nbsp;{4,</p><p>&nbsp; &nbsp;&quot;曹永凯&quot;,</p><p>&nbsp; &nbsp;&quot;411626200310095018&quot;,</p><p>&nbsp; &nbsp;{2002,10,9},</p><p>&nbsp; &nbsp;'M',</p><p>&nbsp; &nbsp;18,</p><p>&nbsp; &nbsp;{96,97,98,99,100},</p><p>&nbsp; &nbsp;&quot;河南省周口市淮阳区&quot;,</p><p>&nbsp; &nbsp;&quot;15061885350&quot;,</p><p>&nbsp; &nbsp;&quot;3096586943@qq.com&quot;},</p><p>&nbsp; &nbsp;{5,</p><p>&nbsp; &nbsp;&quot;曹永凯&quot;,</p><p>&nbsp; &nbsp;&quot;411626200310095018&quot;,</p><p>&nbsp; &nbsp;{2002,10,9},</p><p>&nbsp; &nbsp;'M',</p><p>&nbsp; &nbsp;18,</p><p>&nbsp; &nbsp;{96,97,98,99,100},</p><p>&nbsp; &nbsp;&quot;河南省周口市淮阳区&quot;,</p><p>&nbsp; &nbsp;&quot;15061885350&quot;,</p><p>&nbsp; &nbsp;&quot;3096586943@qq.com&quot;}</p><p>&nbsp; &nbsp;&nbsp;</p><p>&nbsp;};</p><p>&nbsp;int count = 5;</p><p>&nbsp;display(s,count);//打印学生信息&nbsp;</p><p>&nbsp;/*if(addOneStudent(&amp;s[count],count)){</p><p>&nbsp; &nbsp; &nbsp;count++;</p><p>&nbsp; &nbsp; }//增加一个学生信息&nbsp;</p><p>display(s,count);*/</p><p>//count=3;</p><p>//delastudentBy(s,&amp;count,3);//删除一个学生信息&nbsp; &nbsp; (为什么在前面定义count=3会删掉count=3之后的所有信息)&nbsp;</p><p>updateastudentByNUB(s,&amp;count,3);//更新一个学生信息&nbsp;</p><p>display(s,count);</p><p>&nbsp;return 0;</p><p>}</p><p><br ></p>
    物联网204-03-曹永凯 发表于2020年12月25日
    添加评论
  • 2楼

  • 物联网204-03-曹永凯 发表于2020年12月28日
    0 | 0 | 举报
    <p>#include &lt;stdio.h&gt;</p><p><br ></p><p>#include &lt;windows.h&gt;</p><p><br ></p><p>#define N 10</p><p><br ></p><p><br ></p><p><br ></p><p>struct Date{</p><p><br ></p><p>&nbsp; int year;</p><p><br ></p><p>&nbsp; int month;</p><p><br ></p><p>&nbsp; int day;</p><p><br ></p><p>};</p><p><br ></p><p><br ></p><p><br ></p><p>struct Student {</p><p><br ></p><p>&nbsp; int num;</p><p><br ></p><p>&nbsp; char name[10];</p><p><br ></p><p>&nbsp; char id[19];</p><p><br ></p><p>&nbsp; Date brithday;</p><p><br ></p><p>&nbsp; char sex;//sex为性别,需用char字符定义</p><p><br ></p><p>&nbsp; int age;</p><p><br ></p><p>&nbsp; double score[5];//分数有小数,需用双精度浮点型</p><p><br ></p><p>&nbsp; char addr[100];</p><p><br ></p><p>&nbsp; char tel[12];</p><p><br ></p><p>&nbsp; char email[20];</p><p><br ></p><p>}s; //s是struct结构体的变量</p><p><br ></p><p><br ></p><p><br ></p><p>void display(struct Student *s,int count){</p><p><br ></p><p>&nbsp;for(int i=0;i&lt;count;i++){</p><p><br ></p><p>&nbsp; system(&quot;color B0&quot;);</p><p><br ></p><p>&nbsp; &nbsp;printf(&quot;\n\n&quot;);</p><p><br ></p><p>&nbsp; &nbsp;printf(&quot;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 学生信息系统\n&quot;);</p><p><br ></p><p>&nbsp; &nbsp;printf(&quot; ------------------------------------\n&quot;);</p><p><br ></p><p>&nbsp; &nbsp;printf(&quot; 学号:%d\n\n&quot;,(*(s+i)).num);</p><p><br ></p><p>&nbsp; &nbsp;printf(&quot; 姓名:%s\n\n&quot;,(*(s+i)).name);</p><p><br ></p><p>&nbsp; &nbsp;printf(&quot; ID号:%s\n\n&quot;,(*(s+i)).id);</p><p><br ></p><p>&nbsp; &nbsp;printf(&quot; 出生日期:%d-%d-%d\n\n&quot;,(*(s+i)).brithday.year,(*(s+i)).brithday.month,(*(s+i)).brithday.day);</p><p><br ></p><p>&nbsp; &nbsp;printf(&quot; 性别:%c\n\n&quot;,(*(s+i)).sex);</p><p><br ></p><p>&nbsp; &nbsp;printf(&quot; 年龄:%d\n\n&quot;,(*(s+i)).age);</p><p><br ></p><p>&nbsp; &nbsp;printf(&quot; 成绩:%.0f,%.0f,%.0f,%.0f,%.0f\n\n&quot;,(*(s+i)).score[0],(*(s+i)).score[1],(*(s+i)).score[2],(*(s+i)).score[3],(*(s</p><p><br ></p><p>+i)).score[4]);</p><p><br ></p><p>&nbsp; &nbsp;printf(&quot; 家庭地址:%s\n\n&quot;,(*(s+i)).addr);</p><p><br ></p><p>&nbsp; &nbsp;printf(&quot; 联系方式:%s\n\n&quot;,(*(s+i)).tel);</p><p><br ></p><p>&nbsp; &nbsp;printf(&quot; QQ邮箱:%s\n\n&quot;,(*(s+i)).email);</p><p><br ></p><p>&nbsp; &nbsp;printf(&quot; ------------------------------------\n\n&quot;);</p><p><br ></p><p>&nbsp;}</p><p><br ></p><p>}</p><p><br ></p><p><br ></p><p><br ></p><p>int addOneStudent(struct Student *s,int count){</p><p><br ></p><p>&nbsp;if(count+1&gt;N){</p><p><br ></p><p>&nbsp; printf(&quot;存储空间不足!&quot;);</p><p><br ></p><p>&nbsp; return 0;&nbsp;</p><p><br ></p><p>&nbsp;}else {</p><p><br ></p><p>&nbsp; int i;</p><p><br ></p><p>&nbsp; &nbsp; system(&quot;color B0&quot;);</p><p><br ></p><p>&nbsp; &nbsp; printf(&quot;\n\n&quot;);</p><p><br ></p><p>&nbsp; &nbsp; printf(&quot;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 学生信息系统\n&quot;);</p><p><br ></p><p>&nbsp; &nbsp; printf(&quot; ------------------------------------\n&quot;);&nbsp;&nbsp;</p><p><br ></p><p>&nbsp; &nbsp; printf(&quot; 学号:&quot;);</p><p><br ></p><p>&nbsp; &nbsp; scanf(&quot;%d&quot;,&amp;((*(s+i)).num));</p><p><br ></p><p>&nbsp; &nbsp; getchar();</p><p><br ></p><p>&nbsp; &nbsp; printf(&quot; 姓名:&quot;);</p><p><br ></p><p>&nbsp; &nbsp; scanf(&quot;%s&quot;,(*(s+i)).name);</p><p><br ></p><p>&nbsp; &nbsp; getchar();</p><p><br ></p><p>&nbsp; &nbsp; printf(&quot; ID号:&quot;);</p><p><br ></p><p>&nbsp; &nbsp; scanf(&quot;%s&quot;,(*(s+i)).id);</p><p><br ></p><p>&nbsp; &nbsp; getchar();</p><p><br ></p><p>&nbsp; &nbsp; printf(&quot; 出生日期:&quot;);</p><p><br ></p><p>&nbsp; &nbsp; scanf(&quot;%d-%d-%d&quot;,&amp;((*(s+i)).brithday.year),&amp;((*(s+i)).brithday.month),&amp;((*(s+i)).brithday.day));</p><p><br ></p><p>&nbsp; &nbsp; getchar();</p><p><br ></p><p>&nbsp; &nbsp; printf(&quot; 性别:&quot;);</p><p><br ></p><p>&nbsp; &nbsp; scanf(&quot;%c&quot;,&amp;((*(s+i)).sex));</p><p><br ></p><p>&nbsp; &nbsp; getchar();</p><p><br ></p><p>&nbsp; &nbsp; printf(&quot; 年龄:&quot;);</p><p><br ></p><p>&nbsp; &nbsp; scanf(&quot;%d&quot;,&amp;((*(s+i)).age));</p><p><br ></p><p>&nbsp; &nbsp; getchar();</p><p><br ></p><p>&nbsp; &nbsp; printf(&quot; 成绩:&quot;);</p><p><br ></p><p>&nbsp; &nbsp; scanf(&quot;%lf,%lf,%lf,%lf,%lf&quot;,&amp;((*(s+i)).score[0]),&amp;((*(s+i)).score[1]),&amp;((*(s+i)).score[2]),&amp;((*(s+i)).score[3]),&amp;((*(s</p><p><br ></p><p>+i)).score[4]));</p><p><br ></p><p>&nbsp; &nbsp; getchar();</p><p><br ></p><p>&nbsp; printf(&quot; 家庭地址:&quot;);</p><p><br ></p><p>&nbsp; scanf(&quot;%s&quot;,(*(s+i)).addr);</p><p><br ></p><p>&nbsp; &nbsp; getchar();</p><p><br ></p><p>&nbsp; &nbsp; printf(&quot; 联系方式:&quot;);</p><p><br ></p><p>&nbsp; &nbsp; scanf(&quot;%s&quot;,(*(s+i)).tel);</p><p><br ></p><p>&nbsp; &nbsp; getchar();</p><p><br ></p><p>&nbsp; &nbsp; printf(&quot; QQ邮箱:&quot;);</p><p><br ></p><p>&nbsp; &nbsp; scanf(&quot;%s&quot;,(*(s+i)).email);</p><p><br ></p><p>&nbsp; &nbsp; getchar();</p><p><br ></p><p>&nbsp; &nbsp; printf(&quot; ------------------------------------\n\n&quot;);</p><p><br ></p><p>&nbsp; &nbsp; return 1;</p><p><br ></p><p>&nbsp;}</p><p><br ></p><p>}</p><p><br ></p><p><br ></p><p><br ></p><p>void delastudentBy(struct Student *s,int *count,int num){</p><p><br ></p><p> int i;</p><p><br ></p><p> for(i=0;i&lt;*count;i++){</p><p><br ></p><p> if(s[i].num==num){</p><p><br ></p><p> break;</p><p><br ></p><p> }</p><p><br ></p><p> }</p><p><br ></p><p> if(i==*count){</p><p><br ></p><p> printf(&quot;该学生信息不在此系统内!\n&quot;);</p><p><br ></p><p> }else{</p><p><br ></p><p> for(;i+1&lt;*count;i++){</p><p><br ></p><p> s[i]=s[i+1];&nbsp;</p><p><br ></p><p> }&nbsp;</p><p><br ></p><p> }</p><p><br ></p><p> (*count)--;&nbsp;</p><p><br ></p><p>}</p><p><br ></p><p><br ></p><p><br ></p><p>void updateastudentByNUB(struct Student *s,int *count,int num){</p><p><br ></p><p> int i;</p><p><br ></p><p> for(i=0;i&lt;*count;i++){</p><p><br ></p><p> if(s[i].num==num){</p><p><br ></p><p> break;</p><p><br ></p><p> }</p><p><br ></p><p> }</p><p><br ></p><p> if(i==*count){</p><p><br ></p><p> printf(&quot;该学生信息无法更新!\n&quot;);</p><p><br ></p><p> }else{</p><p><br ></p><p> addOneStudent(&amp;s[i],*count);</p><p><br ></p><p> }&nbsp;</p><p><br ></p><p>}</p><p><br ></p><p><br ></p><p>void writeALLStudent(struct Student *s,int count){</p><p> FILE*fp;</p><p> if((fp=fopen(&quot;D:\\学生\\file信息.dat&quot;,&quot;wb&quot;))==NULL){</p><p> printf(&quot;无法打开此文件\n&quot;);</p><p> </p><p> }</p><p> fwrite(s,sizeof(struct Student),count,fp);</p><p> fclose(fp);</p><p>}</p><p><br ></p><p><br ></p><p>void readALLStudent(struct Student *s,int count){</p><p> FILE*fp;</p><p> if((fp=fopen(&quot;D:\\学生\\file信息.dat&quot;,&quot;wb&quot;))==NULL){</p><p> printf(&quot;无法打开此文件\n&quot;);</p><p> </p><p> }</p><p> fread(s,sizeof(struct Student),count,fp);</p><p> fclose(fp);</p><p>}</p><p><br ></p><p><br ></p><p>int main(){</p><p><br ></p><p>&nbsp;//Student s;调用struct结构体时,可以只调用结构体的名字&nbsp;</p><p><br ></p><p>&nbsp; &nbsp;struct Student s[N]={};</p><p><br ></p><p>&nbsp; int count = 5;</p><p><br ></p><p>&nbsp;</p><p>writeALLStudent(s,count);&nbsp;</p><p>display(s,count);//打印学生信息</p><p><br ></p><p>//readALLStudent(s,count);</p><p>//display(s,count);</p><p><br ></p><p><br ></p><p>&nbsp;/*if(addOneStudent(&amp;s[count],count)){</p><p>&nbsp; &nbsp; &nbsp;count++;</p><p>&nbsp; &nbsp; }//增加一个学生信息&nbsp;</p><p>display(s,count);*/</p><p><br ></p><p><br ></p><p>//count=3;</p><p>//delastudentBy(s,&amp;count,3);//删除一个学生信息&nbsp; &nbsp; (为什么在前面定义count=3会删掉count=3之后的所有信息)&nbsp;</p><p><br ></p><p><br ></p><p>//updateastudentByNUB(s,&amp;count,3);//更新一个学生信息&nbsp;</p><p>//display(s,count);</p><p><br ></p><p>&nbsp;return 0;</p><p><br ></p><p>}</p><p><br ></p>
    物联网204-03-曹永凯 发表于2020年12月28日
    添加评论