首页 > 试题广场 >

下面是一个结构模板: struct box {

[问答题]
下面是一个结构模板:
struct box
{
       char maker[40];
       float height;
       float width;
       float length;
       float volume;
};

a. 请编写一个函数,它将box结构的引用作为形参,并显示每个成员的值。
b. 请编写一个函数,它将box结构的引用作为形参,并将volume成员设置为其他3边的乘积。
推荐
a. 该函数不应修改结构成员,所以使用const限定符。

void show_box(const box & container)
{
     cout << "Made-by " << container. maker << endl;
     cout << "Height - " << container.height << endl;
     cout << "Width - " << container.width << endl;
     cout << "Lenght - " << container.length << endl;
     cout << "Volume - " << container.volume << endl;
}
b. void set_volume(box & crate)
    {
         crate.volume - crate.height * crate.width * crate.length;
     }

发表于 2018-05-08 08:33:43 回复(0)