911.cpp

来自「我学习C++ Primer Plus过程中写下的课后作业的编程代码」· C++ 代码 · 共 48 行

CPP
48
字号
//     How many 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

// pe5-6.cpp

    #include "iostream"
#include "string"
using namespace std;
struct car
{
   string sProducter;
   int iProYear;
};
int main()
{
 int size;
 cout<<"How many cars do you wish to catalog?";
 cin>>size;
 cin.get();
 car *pCar=new car[size];
 for (int i=0;i<size;i++)
 {
  cout<<"Car #"<<i+1<<endl;
  cout<<"Please enter the make:";
  //cin.get(pCar[i].sProducter,20);
  //cin.get();
  getline(cin,pCar[i].sProducter);
  //cin.get();
  cout<<"Please enter the year made:";
  cin>>pCar[i].iProYear;
  cin.get();
 }
 cout<<"Here is your collection:"<<endl;
 for (i=0;i<size;i++)
 {
  cout<<pCar[i].iProYear<<" "<<pCar[i].sProducter<<endl;
 }
 delete []pCar;
 return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?