【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

相关推荐
redaijufeng9 小时前
C++雾中风景7:闭包
c++·算法·风景
小小龙学IT9 小时前
Go 语言后端开发:从并发模型到生产落地的工程实践
开发语言·后端·golang
ytttr8739 小时前
Qt 数字键盘实现
开发语言·qt
wearegogog1239 小时前
C# .NET 文件比较工具 WinForms
开发语言·c#·.net
再写一行代码就下班9 小时前
Cursor配置Java环境、创建Spring Boot项目的步骤
java·开发语言·spring boot
零陵上将军_xdr9 小时前
后端转全栈学习-Day5-JavaScript 基础-3
开发语言·javascript·学习
小欣加油9 小时前
leetcode287寻找重复数
数据结构·c++·算法·leetcode
oqX0Cazj29 小时前
2026超火Go-Zero实战:从架构原理到高并发接口落地,彻底解决接口超时、雪崩问题
开发语言·架构·golang
学会去珍惜9 小时前
C语言简介
c语言·开发语言
思麟呀9 小时前
C++11 核心特性(三):强类型枚举、static_assert 与 std::tuple
开发语言·c++