C++ Primer Plus 第六版 第七章编程练习答案

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

#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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值