9_296_4.cpp

来自「我学习C++ Primer Plus过程中写下的课后作业的编程代码」· C++ 代码 · 共 34 行

CPP
34
字号
/*--------------------------------------------------------------

4.请基于下面这个名称空间编写一个由3个文件组成的程序:

namespace SALES
{
	const int QUARTERS = 4;
	struct Sales
	{
		double sales[QUARTERS];
		double average;
		double max;
		double min;
	};

	// copies the lesser of 4 or n items from the array ar
	// to the sales member of s and computes and stores the 
	// remaining elements of sales, if any,set to 0
	void setSales (Sales & s, const double ar[], int n);
	
	// gathers sales for 4 quarters interactively, stores them
	// in the sales member of s and computes and stores the 
	// average, maximum, and minumum values
	void setSales (Sales & s);

	// display all information in structure s
	void showSales (const Sales & s);
}
第一个文件是一个头文件,其中包含名称空间.第二个文件是一个源代码文件,
它对这个名称空间进行扩展,以提供这3个函数的定义.第三个文件声明两个
Sales对象,并使用setSales()的非交互式版本为另一个结构提供值.另外它
还使用showSales()来显示这两个结构的内容.

-----------------------------------------------------------------*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?