#include<iostream>
using namespace std;
struct car{
string brand;
int year;
};
int main(){
int num,i;
cout<<"How many cars do you wish to catalog?";
cin>>num;
car *pz= new car[num] ;
for(i=1;i<=num;i++){
cout<<"Car #"<<i<<"\n";
cout<<"Please enter the make:";
cin>>pz[i-1].brand;
cout<<"Please enter the year made:";
cin>>pz[i-1].year;
}
cout<<"Here is your collection:\n";
for(i=0;i<num;i++){
cout<<pz[i].brand<<"\t"<<pz[i].year<<"\n";
}
delete [] pz;
}
c++ primer plus 习题5.7(使用new为结构创建动态数组)
最新推荐文章于 2021-12-23 14:45:33 发布