【C++ Primer Plus习题】7.7

问题:



解答:

cpp 复制代码
#include <iostream>
using namespace std;

#define SIZE 10

double* fill_array(double* begin, double* end)
{
	for (begin; begin < end; begin++)
	{
		cout << "请输入值:";
		cin >> *begin;
		if (cin.fail())
		{
			cout << "非法数字,结束输入!" << endl;
			break;
		}
	}
	return begin;
}

void show_array(double* arr, double* end)
{
	double* n = arr;
	cout << "数组信息为:";
	for (n; n < end; n++)
	{
		cout << *n << "  ";
	}
	cout << endl;
}

void revalue(double r, double* arr, double* end)
{
	double* n = arr;
	for (n; n < end; n++)
	{
		(*n) *= r;
	}
}

int main()
{
	double array[SIZE];
	double* begin = &array[0];
	double* end = &array[SIZE];

	double *index=fill_array(begin, end);
	show_array(array, index);
	revalue(2, array, index);
	show_array(array, index);

	return 0;
}

运行结果:

考查点:

  • 数组和指针

2024年8月30日21:16:55

相关推荐
Jasmine_llq11 分钟前
《B3840 [GESP202306 二级] 找素数》
开发语言·c++·试除法·顺序输入输出算法·素数判定算法·枚举遍历算法·布尔标记算法
低频电磁之道18 分钟前
C++ 中的深浅拷贝
c++
梁山好汉(Ls_man)21 分钟前
鸿蒙_ArkTS解决Duplicate function implementation错误
开发语言·华为·typescript·harmonyos·鸿蒙
xiaoshuaishuai825 分钟前
Git二分法定位Bug
开发语言·python
so2F32hj232 分钟前
一款Go语言Gin框架DDD脚手架,适合快速搭建项目
开发语言·golang·gin
ybzj.1 小时前
2025年第十六届蓝桥杯省赛C/C++大学B组 个人题解
c++
LJianK11 小时前
Java中的类、普通类,抽象类,接口的区别
java·开发语言
Dev7z1 小时前
基于MATLAB的5G物理层文本传输系统仿真与性能分析
开发语言·5g·matlab
小智社群1 小时前
贝壳获取小区的名称
开发语言·前端·javascript
lsx2024061 小时前
Python3 OS模块详解
开发语言