栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

个人学习c++记录

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

个人学习c++记录

1.【例2.11】内联函数的应用

#include 
using namespace std;
inline double circumference(double radius);
void main()
{
	double r = 3.0, s;
	s = circumference(r);
	cout << "the circumference is" << s << endl;
}
inline double circumference(double radious)
{
	return 2 * 3.1415926 * radious;
}

2.重载函数应用举例

#include 
int add(int x, int y);
{
	int sum;
	sum = x + y;
	return sum;
}
int add(int x, int y, int z);
{
	int sum;
	sum = x + y + z;
	return sum;
}
void main()
{
	int a, b;
	a = add(5, 10);
	b = add(5, 10, 20);
	cout << "a=" << a << endl;
	cout << "b=" < , b << endl;
}

3.编写一个对具有n个元素的数组a[]求最小值的程序,将求最小值的函数设计成函数模板。

#include 
template
T min(T a[], int n);
{
	int i;
	T minv = a[0];
	for (i = 1; i < n; i++)
		if (minv > a[i])
			minv = a[i];
	return minv;
}
void mian()
{
	int a[] = { 1,3,0,2,7,6,4,5,2 };
	double b[] = { 1.2,-3.4,6.8,9.8 };
	cout << "a数组的最小值为:" << min(a, 9) << endl;
	cout << "b数组的最小值为:" << min(b, 4) << endl;
}

4.模板函数与重载函数同时出现在一个程序体内举例

#include 
#define PI 3.1415826535
template
double Circle_Square(long x)
{
	return x*x*PI
}
void main()
{
	int r1 = 1;
	double r2 = 2.0;
	long r3 = 3;
	cout << "The first circle square is" << Circle_Square(r1) << endl;
	cout << "The second circle square is" << Circle_Square(r2) << endl;
	cout << "The third circle square is" << Circle_Square(r3) << endl;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1009941.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号