Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

第n次問c++的問題!!

0 views
Skip to first unread message

麻瓜

unread,
Aug 3, 2000, 3:00:00 AM8/3/00
to

既然是第 n 次問
有沒有找過答案
等著人家告訴你的時候 我想答案應該已經找到了吧...

function overloadding ...

加油吧...

《 在 CPTL...@bbs.ntit.edu.tw (笨笨的蝸牛) 的大作中提到: 》
: #include <iostream.h>
: #include <math.h>
: int sroot(int i);
: long sroot(long i);
: double sroot(double i);
: int main()
: {
: cout << "Square root of 90.34 is : " << sroot(90.34) << endl;
: cout << "Square root of 90L is : " << sroot(90L) << endl;
: cout << "Square root of 90 is : " << sroot(90) << endl;
: return 0;
: }
: int sroot(int i)
: {
: cout << "computing integer root" << endl;
: return (int) sqrt((double) i);
: }
: long sroot(long i)
: {
: cout << "computing long root" << endl;
: return (long) sqrt(double i);
: }
: double sroot(double i)
: {
: cout << "computing double root" << endl;
: return sqrt(i);
: }
: 請問程式中有一段 (int) sqrt((double) i) 及 (long) sqrt((double) i)是啥意思呀??
: 可否能請知道的前輩說明一下呢? 而且sqrt裡面只能用double嗎??


--

[1;33mMain [1;37m( ICQ:2883897 ; CICQ:153670 ) [1;33m{ polo...@msa.hinet.net }
[0m

[m [1;34m※ 來源:‧蛋捲廣場 bbs.tku.edu.tw‧[FROM: 203.69.219.2] [m

很累很累

unread,
Aug 4, 2000, 3:00:00 AM8/4/00
to
《 在 CPTL...@bbs.ntit.edu.tw (笨笨的蝸牛) 的大作中提到: 》
: #include <math.h>

: int sroot(int i)
: {
: cout << "computing integer root" << endl;
: return (int) sqrt((double) i);
: }
: long sroot(long i)
: {
: cout << "computing long root" << endl;
: return (long) sqrt(double i);
: }
: double sroot(double i)
: {
: cout << "computing double root" << endl;
: return sqrt(i);
: }
: 請問程式中有一段 (int) sqrt((double) i) 及 (long) sqrt((double) i)是啥意思呀??
: 可否能請知道的前輩說明一下呢? 而且sqrt裡面只能用double嗎??

1.(int) sqrt((double) i))是說在呼叫sqrt()函數時將欲傳入之參數轉型為double
然後將sqrt()所傳回的值(應該為double)再轉型為int

2.根據 ANSI C 的math.h內定義 sqrt()函數之參數為double型態 且return value
為double 所以說sqrt裡面只能用double

就是這樣

--
[m [1;32m※ 來源:‧蛋捲廣場 bbs.tku.edu.tw‧[FROM: 210.63.203.18] [m

0 new messages