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<iostream.h><BR>#include<stdio.h><BR>#include<string.h><BR>struct car<BR>{<BR> char make[20];<BR> int year;<BR> }; <BR>void main()<BR>{<BR> int carnum;<BR> cout<<"How many cars do your wish to catalog?";<BR> cin>>carnum;<BR> cout<<endl;<BR> car *p=new car[carnum];<BR> for(int i=1;i<=carnum;i++)<BR> {<BR> cout<<"car#"<<i<<":"<<endl;<BR> cout<<"please enter the make:";<BR> gets(p[i-1].make);<BR> cout<<endl;<BR> cout<<"please enter the year made:";<BR> cin>>p[i-1].year;<BR> cout<<endl;<BR> }<BR> for(int j=1;j<=carnum;j++)<BR> {<BR> cout<<p[j-1].year<<" ";<BR> puts(p[j-1].make);<BR> cout<<endl;<BR> }<BR>}<BR>以上程序仅供参考,有欠妥之处,还请指教。<BR>静态数组: 例如:int a[10];<BR> 其数组元素个数已在定义时确定。<BR>动态数组: 例如:int *p;<BR> printf("Please input the number of array's member:");<BR> int num;<BR> scanf("%d",&num);<BR> p=new int[num];<BR> 其数组元素个数依用户需要,动态申请内存空间。<BR> <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>
回复者:小小书生 回复日期: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 + -
显示快捷键?