【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

相关推荐
njxiejing2 分钟前
Numpy一维、二维、三维数组切片实例
开发语言·python·numpy
许长安16 分钟前
c/c++ static关键字详解
c语言·c++·经验分享·笔记
蒙奇D索大20 分钟前
【11408学习记录】考研英语长难句精析:三步拆解真题复杂结构,轻松攻克阅读难关!
笔记·学习·考研·改行学it
一位搞嵌入式的 genius24 分钟前
前端实战开发(四):从迭代器到异步编程:ES6 Generator 全面解析 + 实战问题排查
开发语言·前端·es6·前端实战
来来走走25 分钟前
Android开发(Kotlin) 高阶函数、内联函数
android·开发语言·kotlin
Murphy_lx35 分钟前
C++ thread类
开发语言·c++
月夜的风吹雨36 分钟前
【C++ STL 深度剖析】:vector 底层模拟实现与核心陷阱解析
c++·vector·类和对象·visual studio
彩妙不是菜喵43 分钟前
C++ 中 nullptr 的使用与实践:从陷阱到最佳实践
开发语言·jvm·c++
zd20057243 分钟前
AI辅助数据分析和学习了没?
人工智能·学习
lskisme1 小时前
springboot maven导入本地jar包
开发语言·python·pycharm