C++Primer Plus(第六版)第七章编程练习
2019-03-02 11:30
274 查看
好几道题没做,返回指针的函数写之前的写过就没再写一次了
#include <iostream> using namespace std; /* struct box { char maker[40]; float height; float width; float length; float volume; }; double harmonic_mean(double a,double b); int input(double *a);*/ int Fill_array(double *a,int size); void Show_array(double *a, int size); void Reverse_array(double *a,int size); /*void display(double *a,int size); double ave(double *a,int size); void display(box a); void do_the_math(box *a); int factorial(int a);*/ int main() { /*cout << "No.1"<<endl; double i,j; while(1) { cout << "input two numbers not '0':"<<endl; cin >> i; cin >> j; if(i==0 || j==0) { cout << "end the loop"; break; } cout << "The harmonic mean =" <<harmonic_mean(i,j)<<endl; } cout << "No.2"<<endl; double golf[10]; int size; size = input(golf); display(golf,size); cout << "No.3"<<endl; box one = { "Bone",10,10,10,50 }; display(one); do_the_math(&one); display(one); cout << "No.5"<<endl; int i; while(1) {cin >> i; if(cin.fail()) { cin.clear(); cout << "invalid input"<<endl; break; } cout << "factorial "<<i<< "! = "<<factorial(i)<<endl; } cout << "No.6"<< endl; double *a; int size = 10; size = Fill_array(a,size); Reverse_array(a,size); Show_array(a,size);*/ cout << "No.10" <<endl; return 0; } /* int factorial(int a) { if(a==0 || a == 1) return 1; else { return a*factorial(a-1); } } double harmonic_mean(double a,double b) { double temp; temp = 2.0*a*b/(a+b); return temp; }*/ /*int Fill_array(double *a,int size) { for(int i = 0; i<size ; i++) { cin >> a[i]; if(!cin) { cin.clear(); cout << "input failed"<<endl; int s = i; return s; } } return size; } void Show_array(double *a,int size) { for(int i = 0; i<size ; i++) { cout << a[i]<<endl; } } void Reverse_array(double *a,int size) { double * b = new double[size]; for(int i=0; i<size ;i++) { b[i] = a[size - i - 1]; } for(int i = 0; i < size ; i++) { a[i] = b[i]; } delete [] b; }*/ /*int input(double *a) { cout << "input score of golf match:"<< endl; for(int i = 0; i<10 ; i++) { cin >> a[i]; if(!cin) { cin.clear(); cout << "input failed"<<endl; int size = i; return size; } } return 10; }*/ /* void display(double *a,int size) { for(int i = 0; i<size ; i++) { cout << a[i]<<endl; } cout << "average of score:" <<ave(a,size); } double ave(double *a,int size) { double temp = 0; for(int i = 0 ; i<size ; i++) { temp += a[i]; } temp /= size; return temp; } void display(box a) { cout << a.maker<< endl; cout << a.height<< endl; cout << a.width << endl; cout << a.length<< endl; cout << a.volume<< endl; } void do_the_math(box *a) { a->volume = a->height * a->length * a->width; } */
相关文章推荐
- C++ Primer Plus 第六版 学习笔记 第七章 编程练习答案
- C++ primer Plus(第六版)中文版 第七章 函数——C++的编程模块 编程练习答案
- C++ PRIMER PLUS (第六版) 中文版 第七章编程练习答案
- 【学习C++】C++ Primer Plus (第六版)第七章编程练习6-10
- C++ Primer Plus第六版 第七章 编程练习答案
- C++Primer Plus(第六版)第九章编程练习:
- C++ primer plus第六版课后编程练习答案:7.2
- C++ Primer Plus第六版编程练习11.2解答
- C++primer plus第六版课后编程练习答案3.4
- C++primer plus第六版课后编程练习答案5.8
- C++ primer plus第六版课后编程练习答案:8.4
- C++primer plus第六版课后编程练习答案8.7
- C++primer plus第六版课后编程练习答案10.7
- C++ Primer Plus第六版编程练习10.4解答
- C++ Primer Plus第六版 第十六章 编程练习答案
- C++ Primer Plus第六版 第十七章 编程练习答案(完结篇...木有18章)
- C++primer plus第六版课后编程练习答案2.4
- C++primer plus第六版课后编程练习答案10.8
- C++primer plus第六版课后编程练习答案12.1
- C++ Primer Plus第六版 第十章 编程练习答案