| 发表于:2007-08-31 17:19:15 楼主 |
//以下是我的程序,怎样修改caculate函数,使他按地址传递? #include <iostream> using namespace std; const int size=20; struct box { char maker[40]; float height; float width; float length; float volume; }; void output(box x[],int m); double caculate(box p[],int lim); int main() { int n; cout < < "how many records do you want to enter:\n "; cin> > n; box market[size]; for(int i=0;i <n;i++) { cout < < "maker: "; cin> > market[i].maker; cout < < "height: "; cin> > market[i].height; cout < < "width: "; cin> > market[i].width; cout < < "length: "; cin> > market[i].length; cout < <endl; } market[i].volume=caculate(market,n); output(market,n); cout < < "done!\n "; return 0; } void output(box x[],int m) { for(int i=0;i <m;i++) { cout < < "maker: " < <x[i].maker < <endl; cout < < "height: " < <x[i].height < <endl; cout < < "width: " < <x[i].width < <endl; cout < < "length: " < <x[i].length < <endl; cout < < "volume: " < <x[i].volume < <endl; cout < <endl; } } double caculate(box p[],int lim) { for(int i=0;i <lim;i++) p[i].volume=p[i].length*p[i].width*p[i].height; return p[i].volume; } |
|
|
|
|