C primer plusplus :struct结构体

//

//  main.cpp

//  structChapter

//

//  Created by 炒饭 on 2019/4/14.

//  Copyright © 2019 炒饭. All rights reserved.

//

 

#include <iostream>

//外部声明,可以被其他函数调用,放在main函数之前

struct inflatable

{

    char name[20];

    float volume;

    double price;

    

};

//定义结构同时创建结构体变量

struct perks

{

    int key_number;

    char car[12];

    

} mr_smith , ms_jones;

 

struct perkss

{

    int key_numer;

    char cars[12];

} mr_glitez =

{

    7,

    "package"

};

 

int main()

{

    // insert code here...

    using namespace std;

    inflatable guest =

    {   //初始化成员用逗号隔开

        "Glorious Gloria",

        1.88,

        29.99

    };

    inflatable pal

    {

        "Audacious Arthur",

        3.12,

        32.99

    };

    cout << "expand your guest list with "<< guest.name;

    cout << " and "<< pal.name << "!\n";

    cout << "You can have both for $";

    cout << guest.price + pal.price <<"!\n";

    //定义结构体数组

    inflatable gifts[100];

    cin >>gifts[0].volume;

    inflatable guests[2]=

    {

        {"Bambi",0.4,21.22},

        {"Godzilla",2000,456.22}

    };

    std::cout << "Hello, World!\n";

    return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值