当前位置:首页 > C++PrimerPlus第六版课后题第七章
1.
#include
usingnamespacestd;
doubleave(double x, double y); //调和平均数
intmain() {
doublei, j;
cout<<\; cin>>i>>j ;
double value = ave(i, j); //调用调和平均数
cout<<\<< value < doubleave(double x, double y) { double sum = 0.0; double a, b; if ((x == 0) || (y == 0)) cout<<\< sum = (2.0) * x * y / (x + y); cout<<\; cin>> a >> b; } return (sum); } 2. #include usingnamespacestd; constintArSize = 10; intinput(int arr1[], int max); 1 void show (int arr2[], int n); doubleave (int arr3[], int m); intmain() { int score[ArSize]; int size = input(score, ArSize); show(score,size); double average = ave (score,size); cout<<\<< average < return 0; } intinput(int arr1[], int max) { inti = 0; int temp; for( i = 0; i< max; i++) { cout<<\< cin.clear(); while (cin.get() != '\\n') continue; break; } elseif (temp < 0) break; arr1[i] = temp; } returni; } void show (int arr2[], int n) { for (inti = 0; i< n; i++) cout<<\< 2 doubleave (int arr3[], int m) { int ava = 0; for (inti = 0 ; i< m; i++) ava = ( ava + arr3[i] ) / m ; return (ava); } 3. a) #include usingnamespacestd; struct box { char maker[40]; float height; float width; float length; float volume; }; void show(box b); int main() { box boxx = {\, 23.9, 54354, 54.2, 4535.6 }; show(boxx); return 0; } void show(box b) { cout<<\< 3 b) #include usingnamespacestd; struct box { char maker[40]; float height; float width; float length; float volume; }; void show(box *b); int main() { box boxx = {\, 10.2, 10.0, 10.0}; show( &boxx); return 0; } void show(box *b) { b->volume = b->height * b->width * b->length ; cout<<\< cout<<\<< b->maker < c) #include usingnamespacestd; struct box { char maker[40]; float height; 4
共分享92篇相关文档