?? chapter3-7.cpp
字號:
//文件名:CHAPTER3-7.cpp
#include <iostream.h>
#include <string.h>
// 定義函數(shù)模板,找出三個值中最小的值,與數(shù)據(jù)類型無關(guān)
template <class T>
T min(T ii, T jj, T kk)
{
T temp;
if((ii<jj)&&(ii<kk)){ temp=ii; }
else if((jj<ii)&&(jj<kk)){ temp=jj; }
else { temp=kk; }
return temp;
}
//非模板函數(shù)重載
const char* min(const char* ch1, const char* ch2,const char* ch3)
{
const char* temp;
int result1 = strcmp(ch1,ch2);
int result2 = strcmp(ch1,ch3);
int result3 = strcmp(ch2,ch1);
int result4 = strcmp(ch2,ch3);
if((result1<0)&&(result2<0)) { temp = ch1; }
else if((result3<0)&&(result4<0)) { temp=ch2; }
else { temp=ch3; }
return temp;
}
// 下面是主函數(shù)
void main()
{
cout<<min(100,20,30)<<endl;
cout<<min(10.60,10.64,53.21)<<endl;
cout<<min('c','a','C')<<endl;
cout<<min("Anderson","Washington","Smith")<<endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -