【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

相关推荐
laplace012312 小时前
PyQt5 + Qt Designer配置指令
开发语言·qt
nvd1112 小时前
Python 迭代器 (Iterator) vs. 生成器 (Generator)
开发语言·python
oioihoii12 小时前
C++中有双向映射数据结构吗?Key和Value能否双向查找?
数据结构·c++·算法
HalvmånEver12 小时前
Linux:基础开发工具(三)
linux·运维·服务器·开发语言·学习·gcc/g++
后端小张12 小时前
【JAVA 进阶】Spring Boot 注解体系与工程实践
java·开发语言·spring boot·后端·spring·spring cloud·java-ee
_OP_CHEN13 小时前
算法基础篇:(八)贪心算法之简单贪心:从直觉到逻辑的实战指南
c++·算法·贪心算法·蓝桥杯·算法竞赛·acm/icpc·简单贪心
倔强的石头10613 小时前
Rust实战:使用Axum和SQLx构建高性能RESTful API
开发语言·rust·restful
q***465213 小时前
对基因列表中批量的基因进行GO和KEGG注释
开发语言·数据库·golang
柠石榴13 小时前
GO-1 模型本地部署完整教程
开发语言·后端·golang