#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爲結構創建動態數組)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.