设计一个名为car的结构,存储下列信息:生产商,年份数.向用户询问有多少辆车.随后,new创建一个相应数量的car结构的动态数组.然后,程序提示用户输入每辆车的生产商何年份.最后程序显示每个结构内容.运行情况如下:
How much cars do you wish to catalog? 2
car #1:
Please enter the make: Hudson Hornet
Please enter the year made: 1952
car 2#;
please enter the make: Kaiser
please enter the year made: 1951
Here is your collection:
1952 Hudson Hornet
1951 Kaiser
===============================================================================
#include<iostream>
using namespace std;
struct cartag{
int year;
char make[80];
};
int main()
{
int n;
cout<<"How much cars do you wish to catalog?"<<endl;
cin>>n;
cartag *array=new cartag[n];
int i=0;
while(i<n)
{
cout<<"car #"<<i+1<<":"<<endl;
cout<<"Please enter the make:";
cin>>array[i].make;
cout<<"Please enter the year made:";
cin>>array[i].year;
i++;
}
i=0;
while(i<n)
{
cout<<array[i].year<<" "<<array[i].make<<endl;
i++;
}
delete array;
system("PAUSE");
return 0;
}