⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pex7_2.cpp

📁 数据结构C++代码,经典代码,受益多多,希望大家多多支持
💻 CPP
字号:
#include <iostream.h>

// copy the n element array B to array A
template <class T>
void Copy(T A[], T B[], int n)
{
	for (int i = 0; i < n; i++)
		A[i] = B[i];
}

struct Student
{
	int field1;
	double field2;
};

// stream output of Student records
ostream& operator << (ostream& istr, const Student &S)
{
	cout << S.field1 << "/" << S.field2;
	return istr;
}

// print the n element array A to the screen
template <class T>
void PrintArray (T A[], int n)
{
	for (int i = 0; i < n; i++)
		cout << A[i] << "    ";
	cout << endl;
} 

void main(void)
{
	// arrays used to test Copy
	int AInt[6], BInt[6] = {1,3,5,7,9,11};
	Student AStudent[3], BStudent[3] = {{1,3.5},{3,0},{5,5.5}};
	
	// copy BInt to AInt and print AInt
	Copy(AInt, BInt, 6);
	cout << "Resulting AInt Array:     ";
	PrintArray(AInt, 6);
	
	// copy BStudent to AStudent and print AStudent
	Copy(AStudent, BStudent, 3);
	cout << "Resulting AStudent Array: ";
	PrintArray(AStudent, 3);
}

/*
<Run>

Resulting AInt Array:     1    3    5    7    9    11
Resulting AStudent Array: 1/3.5    3/0    5/5.5
*/

⌨️ 快捷键说明

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