#include <iostream>
#include <cstring>
double q1(double a, double b);
void q2();
int enter(double * arr, int size);
void show(double arr [], int size);
double mean(double * arr, int size);
struct box
{
char maker[40];
float height;
float width;
float length;
float volume;
};
void q3();
void showmem(box a);
void q3_b(box * a);
void q4();
long double probability(unsigned numbers, unsigned picks);
void q5();
long double multiply(int num);
void q6();
int Fill_array(double * arr, int size);
void Show_array(double * arr, int size);
void Reverse_array(double * arr, int size);
void q7();
double * fill_array(double * pa, double * pb);
void show_array(const double ar[], double * pd);
void revalue(double r, double ar[], double * pd);
void q8();
const int Seasons = 4;
const char * Snames[4] = {"Spring", "Summer", "Fall", "Winter"};
void fill(double arr[]);
void show(double arr[]);
struct q8_2{
double exp[Seasons];
};
void q9();
const int SLEN = 30;
struct student {
char fullname[SLEN];
char hobby[SLEN];
int ooplevel;
};
int getinfo(student pa[], int n);
void display1(student st);
void display2(const student * ps);
void display3(const student pa[], int n);
void q10();
double calculate(double a, double b, double (*f)(double x, double y));
double add(double x, double y);
double mul(double x, double y);
double div(double x, double y);
using namespace std;
int main()
{
/* q1
double a, b;
cout << "Enter two numbers: " << endl;
cin >> a >> b;
if (a * b != 0.0)
{
cout << "The answer is: " << q1(a, b) << endl;
cout << "Enter two numbers: " << endl;
cin >> a >> b;
}
else
cout << "End." << endl;
*/
q10();
return 0;
}
double q1(double a, double b)
{
return 2.0 * a * b/(a + b);
}
void q2()
{
const int arrsize = 10;
double * arr = new double[arrsize];
int size = enter (arr, arrsize);
show (arr, size);
cout << "The average score is: " << mean(arr, size);
delete [] arr;
return;
}
int enter(double * arr, int size)
{
int i = 0;

本文提供C++ Primer Plus第六版第七章的编程练习解答,包括q1到q10的详细实现,涉及函数调用、数组处理、结构体操作、概率计算、递归、数组反转等概念。通过示例代码展示如何计算两个数的商、输入与显示高尔夫分数、计算体积、概率计算、阶乘、数组填充与反转、动态内存分配以及学生信息管理等。
最低0.47元/天 解锁文章
504

被折叠的 条评论
为什么被折叠?



