您的位置:首页 > 编程语言 > C语言/C++

c++ primer plus 习题5.7(使用new为结构创建动态数组)

2015-01-14 13:24 483 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: