《C++ Primer Plus》(第6版)第7章编程练习

C++ Primer Plus 第6版 第7章 编程练习答案 1. 编写一个程序,不断要求用户输入两个数,直到其中一个为0。对于每两个数,程序将使用一个函数来计算它们的调和平均数,并将结果返回给main(),而后者将报告结果。调和平均数指的是倒数平均值的倒数,计算公式如下: ... 阅读详情

《C++ Primer Plus》(第6版)第7章编程练习

1. 调和平均数

编写一个程序,不断要求用户输入两个数,直到其中的一个为0。对于每两个数,程序将使用一个函数来计算它们的调和平均数,并将结果返回给main(),而后者将报告结果。调和平均数指的是倒数平均值的倒数,计算公式如下:
调和平均数=2.0 * x * y / (x+ y)

代码:

#include <iostream>
using namespace std;

double cal_harmonic_mean(double, double);

int main()
{
    int a, b;

    cout << "Enter two numbers, I will calculate their harmonic average.\n";
    while (1)
    {
        cout << "a:";
        cin >> a;
        cout << "b:";
        cin >> b;
        if (!a | !b)
            break;
        cout << "The harmonic mean of a and b is " << cal_harmonic_mean(a, b) << ".\n";
    }
    cout << "Done!\n";

    system("pause");
    return 0;
}
double cal_harmonic_mean(double x, double y)
{
    return 2.0 * x * y / (x + y);
}

运行结果:

在这里插入图片描述

2. 高尔夫成绩

编写一个程序,要求用户输入最多10个高尔夫成绩,并将其存储在一个数组中。程序允许用户提早结束输入,并在一行上显示所有成绩,然后报告平均成绩。请使用3个数组处理函数来分别进行输入、显示和计算平均成绩。

代码:

#include <iostream>
using namespace std;

#define ArrSize 10

int elem = 0;

void input_score(double *);
void display_score(double *);
double cal_mean_score(double *);

int main()
{
    double golfScore[ArrSize];

    cout << "Enter golf scores(enter non number to quit)\n";
    input_score(golfScore);
    cout << "All golf score:\n";
    display_score(golfScore);
    cout << "Average golf score:" << cal_mean_score(golfScore) << endl;

    system("pause");
    return 0;
}
void input_score(double *arr)
{
    for (int i = 0; i < ArrSize; i++)
    {
        cout << "Input the " << i + 1
             << "-th golf score: ";
        if (cin >> arr[i])
        {
        }
        else
        {
            elem = i;
            break;
        }
        elem = i;
    }
}
void display_score(double *arr)
{
    for (int i = 0; i < elem; i++)
        cout << arr[i] << " ";
    cout << endl;
}
double cal_mean_score(double *arr)
{
    double average = 0.0;

    for (int i = 0; i < elem; i++)
        average += arr[i];

    return average / (double)elem;
}

运行结果:

在这里插入图片描述

3. box

下面是一个结构声明:

struct box
{
    char maker[40];
    float height;
    float width;
    float length;
    float volume;
};

a.编写一个函数,按值传递box结构,并显示每个成员的值。
b.编写一个函数,传递box结构的地址,并将volume成员设置为其他三维长度的乘积。
c.编写一个使用这两个函数的简单程序。

代码:

#include <iostream>
using namespace std;

struct box
{
    char maker[40];
    float height;
    float width;
    float length;
    float volume;
};

void display_box(box);
void cal_volume(box *);

int main()
{
    box example;

    cout << "Enter the name of maker:";
    cin.getline(example.maker, 40);
    cout << "Enter the height:";
    cin >> example.height;
    cout << "Enter the width:";
    cin >> example.width;
    cout << "Enter the length:";
    cin >> example.length;

    cal_volume(&example);
    display_box(example);

    system("pause");
    return 0;
}

void display_box(box b)
{
    cout << "maker:  " << b.maker << endl;
    cout << "height:  " << b.height << endl;
    cout << "width:  " << b.width << endl;
    cout << "length:  " << b.length << endl;
    cout << "volume:  " << b.volume << endl;
}

void cal_volume(box *b)
{
    b->volume = b->length * b->width * b->height;
}

运行结果:

在这里插入图片描述

4. 彩票

许多州的彩票发行机构都使用如程序清单7.4所示的简单彩票玩法的变体。在这些玩法中,玩家从一组被称为域号码(field number)的号码中选择几个。例如,可以从域号码1 ~ 47中选择5个号码;还可以从第二个区间(如1~27)选择一个号码(称为特选号码)。要赢得头奖,必须正确猜中所有的号码。中头奖的几率是选中所有域号码的几率与选中特选号码几率的乘积。例如,在这个例子中,中头奖的几率是从47个号码中正确选取5个号码的几率与从27个号码中正确选择1个号码的几率的乘积。请修改程序清单7.4,以计算中得这种彩票头奖的几率。

代码:

#include <iostream>
using namespace std;

long double probability(unsigned, unsigned);

int main()
{
    double field_total = 47, field_choices = 5;
    double special_total = 27, special_choices = 1;

    cout << "You have one chance in ";
    cout << probability(field_total, field_choices) * probability(special_total, special_choices);
    cout << " of winning.\n";

    system("pause");
    return 0;
}

long double probability(unsigned numbers, unsigned picks)
{
    long double result = 1.0;
    long double n;
    unsigned p;

    for (n = numbers, p = picks; p > 0; n--, p--)
    {
        result = result * n / p;
    }
    return result;
}

运行结果:

在这里插入图片描述

5. 阶乘

定义一个递归函数,接受一个整数参数,并返回该参数的阶乘。前面讲过,3的阶乘写作3!,等于32!,依此类推;而0!被定义为1。通用的计算公式是,如果n大于零,则n!=n(n-l)!。在程序中对该函数进行测试,程序使用循环让用户输入不同的值,程序将报告这些值的阶乘。

代码:

#include <iostream>
using namespace std;
long Factorial(int);
int main()
{

    int n;

    cout << "Enter a number n(n>0)(q to quit):";
    while (cin >> n)
    {
        cout << n << "! = " << Factorial(n) << endl;
        cout << "Next number(q to quit): ";
    }
    cout << "Done!\n";
    
    system("pause");
    return 0;
}

long Factorial(int n)
{
    if (n > 0)
        return n * Factorial(n - 1);
    return 1;
}

运行结果:

在这里插入图片描述

6. 数组操作

编写一个程序,它使用下列函数:
Fill_array()将一个double数组的名称和长度作为参数。它提示用户输入double值,并将这些值存储到数组中。当数组被填满或用户输入了非数字时,输入将停止,并返回实际输入了多少个数字。
Show_array()将一个double数组的名称和长度作为参数,并显示该数组的内容。
Reverse_array()将一个double数组的名称和长度作为参数,并将存储在数组中的值的顺序反转。程序将使用这些函数来填充数组,然后显示数组;反转数组,然后显示数组;反转数组中除第一个和最后一个元素之外的所有元素,然后显示数组。

代码:

#include <iostream>
using namespace std;

const unsigned int ArrSize = 20;

int Fill_array(double *, unsigned int);
void Show_array(const double array[], int length);
void Reverse_array(double Array[], int length);

int main()
{
    double arr[ArrSize];
    int arrLen = 0;

    cout << "Enter numbers(q to quit):" << endl;
    arrLen = Fill_array(arr, ArrSize);
    Show_array(arr, arrLen);
    Reverse_array(arr, arrLen);
    Show_array(arr, arrLen);

    system("pause");
    return 0;
}

int Fill_array(double array[], unsigned int ArrSize)
{
    int len = 0;

    while (cin >> array[len] && len < ArrSize)
        len++;

    return len;
}

void Show_array(const double array[], int length)
{
    if (length == 0)
    {
        cout << "The array is empty.\n";
        return;
    }
    cout << "Array content:\n";
    for (int i = 0; i < length; i++)
        cout << array[i] << " ";
    cout << endl;
}

void Reverse_array(double *Array, int length)
{
    if (length == 0)
    {
        cout << "The array is empty.\n";
        return;
    }
    cout << "Reverse all elements in the array except the first and last\n";
    for (int i = 0; i < length / 2; i++)
    {
        if (i == 0)
            continue;
        else
        {
            double temp = Array[i];
            Array[i] = Array[length - i - 1];
            Array[length - i - 1] = temp;
        }
    }
}

运行结果:

在这里插入图片描述

7. 数组处理函数

修改程序清单7.7中的3个数组处理函数,使之使用两个指针参数来表示区间。fill_array()函数不返回实际读取了多少个数字,而是返回一个指针,该指针指向最后被填充的位置;其他的函数可以将该指针作为第二个参数,以标识数据结尾。

代码:

#include <iostream>
using namespace std;

const int Max = 5;

double *fill_array(double *, double *);
void show_array(const double *, const double *);
void revalue(double, double *, double *);

int main()
{
    double properties[Max];
    double *end = fill_array(properties, properties + Max);

    show_array(properties, end);
    if (end != properties)
    {
        cout << "Enter revaluation factor: ";
        double factor;
        while (!(cin >> factor))
        {
            cin.clear();
            while (cin.get() != '\n')
            {
                continue;
            }
            cout << "Bad input; Please enter a number: ";
        }
        revalue(factor, properties, end);
        show_array(properties, end);
    }
    cout << "Done!\n";

    system("pause");
    return 0;
}

double *fill_array(double *begin, double *end)
{
    double *temp = begin;
    int i = 0;

    for (; temp != end; temp++)
    {
        cout << "Enter value #" << (i + 1) << ":";
        cin >> *temp;
        if (!cin)
        {
            cin.clear();
            while (cin.get() != '\n')
                continue;

            cout << "Bad input;Please enter a number:";
            break;
        }
        else if (*temp < 0)
            break;
        i++;
    }

    return temp;
}

void show_array(const double *begin, const double *end)
{
    int i = 0;

    for (; begin != end; begin++)
    {
        cout << "Property #" << (i + 1) << ": $";
        cout << *begin << endl;
        i++;
    }
}

void revalue(double r, double *begin, double *end)
{
    for (double *temp = begin; temp != end; temp++)
        *temp *= r;
}

运行结果:

在这里插入图片描述

在这里插入图片描述

8. 开支

在不使用array类的情况下完成程序清单7.15所做的工作。编写两个这样的版本:

a.使用const char * 数组存储表示季度名称的字符串,并使用double数组存储开支。
b.使用const char* 数组存储表示季度名称的字符串,并使用一个结构,该结构只有一个成员———个用于存储开支的double数组。这种设计与使用array类的基本设计类似。

a.

代码:

#include <iostream>
#include <string>
using namespace std;

const int Seasons = 4;
const string Snames[Seasons] = {"Spring", "Summer", "Fall", "Winter"};

void fill(double *);
void show(const double *);

int main()
{
    double expenses[Seasons];

    fill(expenses);
    show(expenses);

    system("pause");
    return 0;
}

void fill(double expenses[])
{
    for (int i = 0; i < Seasons; i++)
    {
        cout << "Enter " << Snames[i] << " expenses: ";
        cin >> expenses[i];
    }
}

void show(const double expenses[])
{
    double total = 0.0;

    cout << "\nEXPENSES\n";
    for (int i = 0; i < Seasons; i++)
    {
        cout << Snames[i] << ": $" << expenses[i] << endl;
        total += expenses[i];
    }
    cout << "Total Expenses: $" << total << endl;
}

运行结果:

在这里插入图片描述

b.

代码:

#include <iostream>
#include <string>
using namespace std;

const int Seasons = 4;
const string Snames[Seasons] = {"Spring", "Summer", "Fall", "Winter"};

typedef struct Expenses
{
    double expenses[Seasons];
} Expenses;

void fill(Expenses *e);
void show(const Expenses *e);

int main()
{
    struct Expenses e;

    fill(&e);
    show(&e);

    system("pause");
    return 0;
}

void fill(Expenses *e)
{
    for (int i = 0; i < Seasons; i++)
    {
        cout << "Enter " << Snames[i] << " expenses: ";
        cin >> e->expenses[i];
    }
}

void show(const Expenses *e)
{
    double total = 0.0;

    cout << "\nEXPENSES\n";
    for (int i = 0; i < Seasons; i++)
    {
        cout << Snames[i] << ": $" << e->expenses[i] << endl;
        total += e->expenses[i];
    }
    cout << "Total Expenses: $" << total << endl;
}

运行结果:

在这里插入图片描述

9. student

这个练习让您编写处理数组和结构的函数。下面是程序的框架,请提供其中描述的函数,以完成该程序。

#include <iostream>
using namespace std;

const int SLEN = 30;

struct student
{
    char fullname[SLEN];
    char hobby[SLEN];
    int ooplevel;
};
// getinfo () has two arguments: a pointer to the first element of
// an array of student structures and an int representing the
// number of elements of the array. The function solicits and
// stores data about students. It terminates input upon filling
// the array or upon encountering a blank line for the student
// name.The function returns the actual number of array elements
// filled.
int getinfo(student pa[], int n);
// display1 ( ) takes a student structure as an argument
// and displays its contents
void display1(student st);
// display2 () takes the address of student structure as an
// argument and displays the structure's contents
void display2(const student *ps);
// display3 () takes the address of the first element of an array
// of student structures and the number of array elements as
// arguments and displays the contents of the structures
void display3(const student pa[], int n);

int main()
{
    cout << "Enter class size: ";

    int class_size;
    cin >> class_size;

    while (cin.get  != '\n')
        continue;
    student *ptr_stu = new student[class_size];
    int entered = getinfo(ptr_stu, class_size);

    for (int i = 0; i < entered; i++)

    {
        display1(ptr_stu[i]);

        display2(&ptr_stu[i]);
    }
    display3(ptr - stu, entered);

    delete[] ptr_stu;
    cout << "Done\n";
    return 0;
}

代码:

#include <iostream>
using namespace std;

const int SLEN = 30;

struct student
{
    char fullname[SLEN];
    char hobby[SLEN];
    int ooplevel;
};
// getinfo () has two arguments: a pointer to the first element of
// an array of student structures and an int representing the
// number of elements of the array. The function solicits and
// stores data about students. It terminates input upon filling
// the array or upon encountering a blank line for the student
// name.The function returns the actual number of array elements
// filled.
int getinfo(student pa[], int n);
// display1 ( ) takes a student structure as an argument
// and displays its contents
void display1(student st);
// display2 () takes the address of student structure as an
// argument and displays the structure's contents
void display2(const student *ps);
// display3 () takes the address of the first element of an array
// of student structures and the number of array elements as
// arguments and displays the contents of the structures
void display3(const student pa[], int n);

int main()
{
    cout << "Enter class size: ";
    int class_size;
    cin >> class_size;
    while (cin.get() != '\n')
        continue;

    student *ptr_stu = new student[class_size];
    int entered = getinfo(ptr_stu, class_size);
    for (int i = 0; i < entered; i++)
    {
        display1(ptr_stu[i]);
        display2(&ptr_stu[i]);
    }
    display3(ptr_stu, entered);
    delete[] ptr_stu;
    cout << "Done\n";

    system("pause");
    return 0;
}

int getinfo(student pa[], int n)
{
    int i;

    cout << "Please input the students information:" << endl;
    for (i = 0; i < n; i++)
    {
        cout << "Student #" << i + 1 << ": " << endl;
        cout << "Fullname: ";
        cin.getline(pa[i].fullname, SLEN);
        if (pa[i].fullname[0] == '\0')
            break;
        cout << "Hobby: ";
        if (pa[i].hobby[0] == '\0')
            break;
        cin.getline(pa[i].hobby, SLEN);
        cout << "Ooplevel: ";
        if (!(cin >> pa[i].ooplevel))
            break;
        cin.get();
    }
    cout << "Enter End!" << endl;
    return i;
}

void display1(student st)
{
    cout << "fullname:" << st.fullname << "     hobby:" << st.hobby << "    opplevel:" << st.ooplevel << endl;
}

void display2(const student *ps)
{
    cout << "fullname:" << ps->fullname << "     hobby:" << ps->hobby << "    opplevel:" << ps->ooplevel << endl;
}

void display3(const student pa[], int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << "Student #" << i + 1 << endl;
        cout << "fullname:" << pa[i].fullname << "     hobby:" << pa[i].hobby << "    opplevel:" << pa[i].ooplevel << endl;
    }
}

运行结果:

在这里插入图片描述

10. calculate()

设计一个名为calculate()的函数,它接受两个double值和一个指向函数的指针,而被指向的函数接受两个double参数,并返回一个double 值。calculate()函数的类型也是double,并返回被指向的函数使用calculate()的两个double参数计算得到的值。例如,假设add()函数的定义如下:

double add (double x, double y)
{
	return x+ y;
}

则下述代码中的函数调用将导致calculate()把2.5和10.4传递给add( )函数,并返回add()的返回值(12.9):

double q = calculate(2.5, 10.4,  add);

请编写一个程序,它调用上述两个函数和至少另一个与add()类似的函数。该程序使用循环来让用户成对地输入数字。对于每对数字,程序都使用calculate( )来调用add( )和至少一个其他的函数。如果读者爱冒险,可以尝试创建一个指针数组,其中的指针指向add()样式的函数,并编写一个循环,使用这些指针连续让 calculate()调用这些函数。提示:下面是声明这种指针数组的方式,其中包含三个指针:

double (*pf [3]) (double, double);

可以采用数组初始化语法,并将函数名作为地址来初始化这样的数组。

代码:

#include <iostream>
using namespace std;

double add(double, double);
double subtract(double, double);
double multiply(double, double);
double calculate(double, double, double (*func)(double, double));

int main(void)
{
    double x, y;
    double (*pf[3])(double, double) = {add, subtract, multiply};

    cout << "Enter two numbers(q to quit):";
    while (cin >> x >> y)
    {
        for (int i = 0; i < 3; i++)
        {
            switch (i)
            {
            case 0:
                cout << x << "+" << y << "=" << calculate(x, y, pf[i]) << endl;
                break;
            case 1:
                cout << x << "-" << y << "=" << calculate(x, y, pf[i]) << endl;
                break;
            case 2:
                cout << x << "*" << y << "=" << calculate(x, y, pf[i]) << endl;
                break;
            }
        }
        cout << "Enter two numbers(q to quit):";
    }
    cout << "Done!\n";

    system("pause");
    return 0;
}

double add(double x, double y)
{
    return x + y;
}

double subtract(double x, double y)
{
    return x - y;
}

double multiply(double x, double y)
{
    return x * y;
}

double calculate(double x, double y, double (*func)(double, double))
{
    return (*func)(x, y);
}

运行结果:

在这里插入图片描述

C++ Primer Plus(第六版)编程练习答案 所有章节汇总 本博客汇总了本人历时一年学完《C++ Primer Plus (第6版)》所做的所有编程练习的答案,供大家学习参考和交流。 以下附上各章节的答案详解博客地址,以及源码工程下载地址。 PS:源码下载大部分都是需要积分的,当时设置的时候好像有点乱,有的是1积分,有的是3积分,最难的第12章和第13章我设置的是不要积分,大家都可以下载下来自己运行一下看看结果。 第 2 章 开始学习C++: ... 阅读详情

相关推荐

C++ Primer Plus(第六版)编程练习答案 第7章 函数——C++的编程模块

本章所有编程练习的工程源码可在此处下载(点击打开下载链接),供大家参考交流!   1. 编写一个程序,不断要求用户输入两个数,直到其中的一个为0。对于每两个数,程序将使用一个函数来计算它们的调和平均数,并将结果返回给main(),而后者将报告结果。调和平均数指的是倒数平均值的倒数,计算公式如下: 调和平均数=2.0*x*y/(x+y) 本题要求编写一个函数,该函数接受的输入参数为两个int...

清水河C罗——Leonardo-Liu 6781

C Primer Plus 第6版 第7章编程题-11题全

1.编写一个程序读取输入,读到#字符停止,然后报告读取的空格数、换行符数和所有其他字符的数量。 #include <stdio.h> #include <ctype.h> ​ int main(void ){ char ch = 0 ; int spaces = 0; int lines = 0; int charactors = 0; while((ch = getchar()) != '#'){ if(ch == ' '...

Litbai_zhang 1330

C++ Primer Plus(第六版)编程练习答案 第3章 处理数据

本章所有编程练习的工程源码可在此处下载(点击打开下载链接),供大家参考交流!   1. 编写一个小程序,要求用户使用一个整数指出自己的身高(单位为英寸),然后将身高转换为英尺和英寸,该程序使用下划线字符来指示输入位置。另外,使用一个const符号常量来表示转换因子。 本题要求将输入数据转换为不同的表达方式,使用不同的单位。而从单位为英寸,转换为英单位是尺和英寸,就是将原值除以转换比例之间,得...

清水河C罗——Leonardo-Liu 7499

C++ primer plus(第六版)第七章练习题

/********************************************************************************************************************************************************/ C++ primer plus(第六版)第七章 第一题 /***************

hongye_05的专栏 1151

orangepi 5 plus ubuntu24.04上安装redroid

OrangePi 5 Plus运行reDroid云手机方案总结 在RK3588+Ubuntu 24.04上部署reDroid(Android容器化方案)的关键步骤: 内核要求:确保启用binderfs(无需ashmem,新版reDroid使用memfd替代); 安装流程: 安装Docker并配置代理加速镜像拉取; 拉取reDroid镜像(推荐Android 12/13 ARM64版本); 通过挂载binderfs启动容器,指定分辨率与DPI参数; 多实例管理: 脚本化创建多个容器(如8个实例),分配独立端口

babytiger的专栏 2308

在UI界面中播放视频_unity基础开发教程

之前我写过一篇在场景中播放视频的文章,但是在开发中有时候也会在UI的界面中播放视频,这期我们做一下在UI的界面中播放视频。操作步骤比较简单,到这里就完成了,如果有问题的话可以在评论区留言,下期见,拜拜!

为者常成,行者常至! 2032

c primer plus 第六版 第七章编程练习

(编译环境 Microsoft Visual Studio 2019) 1. /*1.*/ #include<stdio.h> int main(void) { char ch; unsigned int s_count = 0; unsigned int l_count = 0; unsigned int o_count = 0; ...

lnjoy 2480

国科大作业考试资料《人工智能原理与算法》2024新编-第二次作业整理

1、对于下列活动,分别给出任务环境的PEAS描述, 并按2.3.2节列出的性质进行分析: 3、为图2.2中描述的吸尘器世界实现一个可以进行性能度量的环境模拟器。你的实现是必须是模块化的,以使传感器、执行器和环境特征(大小、形状、灰尘放置等)便于修改。 4、实现上述题目真空吸尘器环境中的简单反射Agent。用所有可能的初始灰尘分布和Agent位置,运行环境模拟器和Agent。记录Agent在每种情况下的性能评分和总体平均评分。

MatsumotoChrikk 1195

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

1.编写一个程序,不断要求用户输入两个数,直到其中一个为0。对于每两个数,程序将使用一个函数来计算它们的 调和平均数,并将结果返回给main(),而后者将报告结果。调和平均数指的是倒数平均值的倒数,计算公式如下: 调和平均数 = 2.0 * x * y / (x + y) #include double average ( double x, double y ) { return 2 *

Fire_Sky_Ho的博客 2912

新能源汽车电池及充电原理详解

本文详细介绍了新能源汽车的电池包结构、铅酸电池充放电原理,以及交流和直流充电的工作原理和优缺点。内容涵盖电池串联并联原因、充电设备如车载充电机、交流充电桩和直流充电桩的介绍,以及不同充电模式的连接方式。通过对充电过程的深入探讨,有助于读者理解新能源汽车的充电技术。

让你爱上电路设计 4538

12.工具高级参数CogCalibNPointToNPointTool

CogCalibNPointToNPointTool是一种多点2D坐标校正工具,用于将图像像素坐标转换为物理世界坐标。该工具通过两组点(图像坐标点和物理坐标点)计算最佳转换关系,并将结果保存供后续使用。操作步骤包括获取图像、添加坐标点对、计算转换参数。校正结果会显示平移、缩放、旋转等参数及RMS误差值,较大的误差可能表明点位置不准确或自由度不足。该工具广泛应用于机器视觉领域,通过9点标定等案例可验证坐标转换的准确性并优化参数设置。

212

C Primer Plus(第6版) 编程练习第7章答案

1.编写一个程序读取输入,读到#字符停止,然后报告读取的空格数、换行符数和所有其他字符的数量。 #include <stdio.h> #define SPACE ' ' #define LINE '\n' int main(void) { int sc = 0, lc = 0, oc = 0; char ch; while ((ch = getchar()) != '#') {...

rre55555的博客 659

PS射击游戏射线检测优化:原理、工程与全链路高性能实现

射线池:减少GC,提升批量检测效率。分层检测:先粗后细,远距离射击高效判定。批量检测:并行处理,适合大量射线场景。空间结构:进一步加速大场景检测。下面继续深入射线检测优化,补充更多实用细节和进阶技巧,包括空间分区加速、射线检测多线程/异步化、射线合并与分帧、射线池通用模板、常见性能陷阱与调优建议等。对于极端性能需求,可自定义轻量级物理系统,仅检测关键对象(如玩家、子弹),跳过复杂物理引擎。结合AABB、OBB、球体等简单碰撞体,射线-包围体检测极快。空间分区+分层检测是大场景射线优化核心。

本博客聚焦游戏开发技巧、创业实战心得及大学热门课程干货。这里既有技术深度,也有思维广度,无论你是开发者、创业者还是高校学子,都能在这里找到适合自己的成长之路! 440

C++ Primer Plus 第6版 中文版 第7章编程练习

1、 #include using namespace std; double Average(int x, int y); int main() { double result, one, two; cout << "Please enter two numbers:"; while (cin >> one >> two) { if(

PeterPan_hai的专栏 707

从零开始学Agent的搭建——多角色项目需求分析框架实战

场景一:电商促销需求——技术细节顾此失彼团队用单Agent分析一个"双11秒杀系统"的需求。Agent输出了完整的功能清单,但当我们拿着这份方案找架构师评审时,发现了致命问题:Agent完全没有考虑库存扣减的并发一致性、Redis与MySQL之间的数据同步延迟、以及超卖风险的控制策略。原因是单Agent在处理"业务理解"任务时,已经耗尽了它的"注意力预算",技术深度分析几乎为空。场景二:ERP集成需求——跨系统边界模糊。

软件行业技术文化交流。 545

微信小程序 - 解决微信支付报错 requestPayment:fail no permission 原因分析及排查处理(支付失败出错,无法唤起支付弹框面板,微信支付API报错请求付款:失败无权限)

微信小程序,微信支付,支付报错,errMsg: "requestPayment:fail no permission",支付失败,支付权限没问题,微信小程序支付报错,检查了appid正确依旧不行,微信小程序支付异常,苹果ios手机,安卓手机,开发者工具模拟器,最新解决教程,小程序wx.requestPayment报错/无响应,小程序支付 requestPaym,微信小程序认证,真机运行,小程序微信支付提示错误,微信小程序里使用微信支付错误提示,微信小程序支付异常,微信支付弹框拉不起来,小程序支付api,都检

🏆 前端领域优质创作者 1万+

C++ Primer Plus(第6版) 第7章 编程练习

#include <iostream> #define MAX_SCORE_CNT 10 typedef struct { char maker[40]; float height; float width; float length; float volume; } box_t; using name...

weixin_34361881的博客 76

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

C++Primer Plus (第6版)中文版 第2章 2.7 编程练习 第3题

#include &lt;iostream&gt; using namespace std; // 编写一个C++程序,它使用3个用户定义的函数(包括main()函数,并生成下面的输出: //Three blind mice //Three blind mice //See how they run //See how they run void mice();//声明要调用的函数原型 voi...

qq_38428822的博客 265

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

C++Primer Plus (第6版)中文版 第2章 2.7 编程练习 第7题

#include &lt;iostream&gt; using namespace std; // 编写一个程序,要求用户输入小时数和分钟数。在main()函数中,将这两个值传递给一个void()函数,后者以下面这样的格式显示这两个值 //Enter the number of hours:9 // Enter the number of minutes:28 //Time:9.28 void...

qq_38428822的博客 349

C++Primer Plus (第6版)中文版 第2章 2.7 编程练习 第6题

#include &lt;iostream&gt; using namespace std; // 编写一个程序,其main()调用一个用户定义的函数(以光年值为参数,并返回对应天文单位的值)。该程序按下面的格式要求用户输入光年值,并显示结果 //Enter the number of light years:4.2 //4.2 lights years =26608 astronomical u...

qq_38428822的博客 257

C++Primer Plus (第6版)中文版 第2章 2.7 编程练习 第5题

#include &lt;iostream&gt; using namespace std; // 编写一个程序,其中的main()调用一个用户定义的函数(以摄氏温度值为参数,并返回相应的华氏温度值) double CelsiusToFahrenheit(double); //声明调用函数原型 int main(){ double celsius,fahrenheit;//定义变量...

qq_38428822的博客 346

C++Primer Plus (第6版)中文版 第2章 2.7 编程练习 第2题

#include &lt;iostream&gt; using namespace std; // 编写一个C++程序,它要求用户输入一个以long为单位的距离,然后将它转化为码(1long等于220码) int longsToYards(int);//声明要调用的函数原型 int main(){ int longs,yards;//定义变量longs和yards,代表以long和码为单位的变...

qq_38428822的博客 287

C++Primer Plus (第6版)中文版 第2章 2.7 编程练习 第1题

//编写一个C++程序,它显示您的姓名和地址#include &lt;iostream&gt; using namespace std; int main(){ cout&lt;&lt;"My name is lunbo!"&lt;&lt;endl;         cout&lt;&lt;"My address is China!"&lt;&lt;endl; return 0; }

qq_38428822的博客 155

C++Primer Plus (第6版)中文版 第2章 2.7 编程练习 第4题

#include &lt;iostream&gt; using namespace std; // 编写一个程序,让用户输入其年龄,然后显示该年龄包含多少个月,如下所示:Enter your age:29 int ageToMonth(int); //声明调用函数原型 int main(){ int age,months; cout&lt;&lt;"Enter your age...

qq_38428822的博客 230

C++Primer Plus第6版&C Primer Plus第6版 中文版免费分享啦

最近在学习C++,用的资料是师兄分享的经典书籍《C++Primer Plus第6版中文版》的PDF,自带书签,使用很方便。但师兄说这个是他在网上花了积分才下载下来的,这让我很是吃惊,因为作为一本经久不衰的经典书籍,这样的资料不应该有很多网友免费分享出来方便大家学习嘛。 本着知识分享学习的思想,我特意找了对应的C语言版,两本资料一起分享给有需要的朋友。 1.C++Primer Plus第6版简介 ...

qq_41590635的博客 4万+

C++ Primer Plus 第六版 所有章节课后编程练习答案

C++ Primer Plus 第六版 所有章节课后编程练习答案

xiaojimmychen的专栏 9万+
上一篇: 《C++ Primer Plus》(第6版)第6章编程练习
下一篇: 《C++ Primer Plus》(第6版)第8章编程练习
UestcXiye
博客等级 码龄8年 9044粉丝 1306原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

UestcXiye

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值
⌂ 换网址