C++ primer plus第六版课后编程练习答案:7.3

#define  _CRT_SECURE_NO_WARNINGS 
#include <iostream>

struct box
{
    char maker[40];
    float height;
    float width;
    float length;
    float volume;
};
void value_box(box maker1);
void address_box(box* maker2);

int main()
{
    using namespace std;
    box maker1;
    cout << "Ener the maker's name: ";
    cin.getline(maker1.maker, 40);
    cout << "Ener the height,width,length,volume: ";
    cin >> maker1.height >> maker1.width >> maker1.length >> maker1.volume;
    box maker2;
    cout << "Now we use value to transmit struct." << endl;
    cout << "______________________________________________" << endl;
    value_box(maker1);
    cout << "Now we use address to transmit struct." << endl;
    cout << "______________________________________________" << endl;
    address_box(&maker2);
    return 0;
}

void value_box(box maker1)
{
    using namespace std;

    cout << "The makes name is: " << maker1.maker << ", and the height is: " << maker1.height
        << ",width is " << maker1.width << ",length is " << maker1.length << ",volume is " << maker1.volume<< endl;
    cin.get();
}

void address_box(box* maker2)
{
    using namespace std;
    cout << "Enter the maker's name: ";
    cin.getline(maker2->maker, 40);
    cout << "Ener the height,width,length,volume: ";
    cin >> maker2->height >> maker2->width >> maker2->length;
    maker2->volume = maker2->height*maker2->length*maker2->width;
    cout << "The maker's name is: " << maker2->maker << ", and the height is: " << maker2->height
        << ",width is " << maker2->width << ",length is " << maker2->length << ",volume is " << maker2->volume << endl;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值