实验09 群体类与群体数据的组织.doc

实验09群体类与群体数据的组织解读

实验09 群体类与群体数据的组织(4学时) (第9章 群体类与群体数据的组织) 一、实验目的 (1) 掌握函数模板与类模板。 (2) 了解线性群体与群体数据的组织。 二、实验任务 9_1求绝对值的函数模板及其应用 #include iostream using namespace std; templatetypename T T fun(T x) { return x 0? -x : x; } int main() { int n = -5; double d = -5.5; cout fun(n) endl; cout fun(d) endl; return 0; } 9_2函数模板的示例。 #include iostream using namespace std; template class T //定义函数模板 void outputArray(const T *array, int count){ for (int i = 0; i count; i++) cout array[i] ; cout endl; } int main(){ //主函数 const int A_COUNT = 8, B_COUNT = 8, C_COUNT = 20; int a [A_COUNT] = { 1, 2, 3, 4, 5

文档评论(0)

1亿VIP精品文档

相关文档