2009年1月4日 星期日

函式》函式與結構 (C++)

struct box
{
char maker[40];
float height;
float width;
float length;
float volume;
};
a.寫一個函數,傳遞box結構之值並顯示每個成員之值。
b.寫一個函數,傳遞box結構的位址,並將成員 volume 設為其他三個成員的乘績。
C.最後寫一個程式使用以上兩個函數

1 則留言:

匿名 提到...

#include < iostream >
struct box
{
char maker[40];
float height;
float width;
float length;
float volume;
};
float find_volume(box *pst);
void show_value(box b);
int main()
{
using namespace std;
box b1 = {"box1", 10, 10, 10};
find_volume(&b1);
show_value(b1);
return 0;
}
float find_volume(box *pst)
{
using namespace std;
pst->volume = pst->height * pst->length * pst->width;
//cout << pst->volume;
return pst->volume;
}
void show_value(box b)
{
using namespace std;
cout << b.maker << "\n"
<< b.height << "\n"
<< b.width << "\n"
<< b.length << "\n"
<< b.volume << "\n";
}