【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

相关推荐
冷崖5 分钟前
MySQL异步连接池的学习(五)
学习·mysql
知识分享小能手7 分钟前
Vue3 学习教程,从入门到精通,Axios 在 Vue 3 中的使用指南(37)
前端·javascript·vue.js·学习·typescript·vue·vue3
七七&5563 小时前
2024年08月13日 Go生态洞察:Go 1.23 发布与全面深度解读
开发语言·网络·golang
java坤坤3 小时前
GoLand 项目从 0 到 1:第八天 ——GORM 命名策略陷阱与 Go 项目启动慢问题攻坚
开发语言·后端·golang
元清加油3 小时前
【Golang】:函数和包
服务器·开发语言·网络·后端·网络协议·golang
健康平安的活着4 小时前
java之 junit4单元测试Mockito的使用
java·开发语言·单元测试
No0d1es4 小时前
电子学会青少年软件编程(C/C++)5级等级考试真题试卷(2024年6月)
c语言·c++·算法·青少年编程·电子学会·五级
焄塰5 小时前
Ansible 管理变量和事实
学习·centos·ansible
DjangoJason5 小时前
C++ 仿RabbitMQ实现消息队列项目
开发语言·c++·rabbitmq
oe10196 小时前
读From GPT-2 to gpt-oss: Analyzing the Architectural Advances(续)
笔记·gpt·学习