CAR的问题

设计一个名为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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值