subject_55379.htm

来自「vc」· HTM 代码 · 共 24 行

HTM
24
字号
<p>
序号:55379 发表者:小小书生 发表日期:2003-10-09 13:45:13
<br>主题:大家帮我看一下这道题!!!
<br>内容:设计一个名为car的结构,用它存储下述有关汽车的信息:生产商。生产年份。编写一个程序,向用户询问有多少辆汽车。随后,程序使用new创建一个由相应数量的car结构组成的动态数组。接下来,程序提示用户输入每辆车的生产商和年份信息。请注意,这需要特别小心,因为它将交替读取数值和字符串。最后程序将显示每个结构的内容?<BR><BR>How mony cars do your wish to catalog?2<BR>car#1:<BR>please enter the make:hudson hornet<BR>please enter the year made:1952<BR>car#2:<BR>please enter the make:kaiser<BR>please enter the year made:1951<BR>here is your collection:<BR>1952 hudson hornet<BR>1951 kaiser<BR><BR><BR>这里我想知道的是怎么定义一个动态数组结构???
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:cowbaby 回复日期:2003-10-09 15:55:31
<br>内容:同问:动态数组和静态数组有什么区别
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:大圣 回复日期:2003-10-09 17:51:42
<br>内容:#include&lt;iostream.h&gt;<BR>#include&lt;stdio.h&gt;<BR>#include&lt;string.h&gt;<BR>struct car<BR>{<BR>&nbsp;&nbsp;char make[20];<BR>&nbsp;&nbsp;int year;<BR> }; <BR>void main()<BR>{<BR>&nbsp;&nbsp; int carnum;<BR>&nbsp;&nbsp; cout&lt;&lt;&#34;How many cars do your wish to catalog?&#34;;<BR>&nbsp;&nbsp; cin&gt;&gt;carnum;<BR>&nbsp;&nbsp; cout&lt;&lt;endl;<BR>&nbsp;&nbsp; car *p=new car[carnum];<BR>&nbsp;&nbsp; for(int i=1;i&lt;=carnum;i++)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; cout&lt;&lt;&#34;car#&#34;&lt;&lt;i&lt;&lt;&#34;:&#34;&lt;&lt;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp; cout&lt;&lt;&#34;please enter the make:&#34;;<BR>&nbsp;&nbsp;&nbsp;&nbsp; gets(p[i-1].make);<BR>&nbsp;&nbsp;&nbsp;&nbsp; cout&lt;&lt;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp; cout&lt;&lt;&#34;please enter the year made:&#34;;<BR>&nbsp;&nbsp;&nbsp;&nbsp; cin&gt;&gt;p[i-1].year;<BR>&nbsp;&nbsp;&nbsp;&nbsp; cout&lt;&lt;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;for(int j=1;j&lt;=carnum;j++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;p[j-1].year&lt;&lt;&#34; &#34;;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts(p[j-1].make);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR>}<BR>以上程序仅供参考,有欠妥之处,还请指教。<BR>静态数组:&nbsp;&nbsp;例如:int a[10];<BR> 其数组元素个数已在定义时确定。<BR>动态数组: 例如:int *p;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&#34;Please input the number of array's member:&#34;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int num;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(&#34;%d&#34;,&amp;num);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p=new int[num];<BR>&nbsp;&nbsp; 其数组元素个数依用户需要,动态申请内存空间。<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp; 
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:小小书生 回复日期:2003-10-10 06:53:41
<br>内容:谢谢你!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?