全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1927
推到 Plurk!
推到 Facebook!

C++Builder 6程式幫幫忙~~

尚未結案
aexi2000
一般會員


發表:4
回覆:5
積分:1
註冊:2008-04-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-05-01 11:57:30 IP:59.126.xxx.xxx 訂閱
請用迴圈語法
1.
編輯記錄
aexi2000 重新編輯於 2008-05-01 13:19:02, 註解 無‧
aexi2000 重新編輯於 2008-05-01 14:23:50, 註解 無‧
aexi2000 重新編輯於 2008-05-01 14:24:35, 註解 無‧
aexi2000 重新編輯於 2008-05-01 14:25:15, 註解 無‧
aexi2000 重新編輯於 2008-05-01 14:30:59, 註解 無‧
aexi2000 重新編輯於 2008-05-01 14:32:11, 註解 無‧
aexi2000 重新編輯於 2008-05-01 14:33:21, 註解 無‧
aexi2000 重新編輯於 2008-05-01 14:41:30, 註解 無‧
aexi2000 重新編輯於 2008-05-01 14:44:24, 註解 無‧
jow
尊榮會員


發表:66
回覆:751
積分:1253
註冊:2002-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-05-01 13:03:57 IP:123.193.xxx.xxx 訂閱

[code cpp]
//---------------------------------------------------------------------------
double __fastcall TForm1::FuncA(unsigned int n)
{
double ret=0;
while(n>0){
int i=n--;
double sum=0;
while(i>0)sum =i--;
if(sum>0)ret =1/sum;
}
return ret;
}
//---------------------------------------------------------------------------
double __fastcall TForm1::FuncB(unsigned int n)
{
double ret=0, sum=0, i=0;
while(i<=n)
if((sum =i )>0)ret =1/sum;
return ret;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
String S;
Label1->Caption = S.sprintf("%f", FuncA(3));
Label2->Caption = S.sprintf("%f", FuncB(3));
}
//---------------------------------------------------------------------------
[/code]

程式碼下載:
http://delphi.ktop.com.tw/download.php?download=upload/481954a20acc8_TestC047.zip
編輯記錄
jow 重新編輯於 2008-05-01 13:12:55, 註解 無‧
jow 重新編輯於 2008-05-01 13:18:36, 註解 無‧
jow 重新編輯於 2008-05-01 13:27:46, 註解 無‧
aexi2000
一般會員


發表:4
回覆:5
積分:1
註冊:2008-04-28

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-05-01 13:32:41 IP:59.126.xxx.xxx 訂閱

===================引 用 jow 文 章===================

[code cpp]
//---------------------------------------------------------------------------
double __fastcall TForm1::FuncA(unsigned int n)
{
double ret=0;
while(n>0){
int i=n--;
double sum=0;
while(i>0)sum =i--;
if(sum>0)ret =1/sum;
}
return ret;
}
//---------------------------------------------------------------------------
double __fastcall TForm1::FuncB(unsigned int n)
{
double ret=0, sum=0, i=0;
while(i<=n)
if((sum =i )>0)ret =1/sum;
return ret;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
String S;
Label1->Caption = S.sprintf("%f", FuncA(3));
Label2->Caption = S.sprintf("%f", FuncB(3));
}
//---------------------------------------------------------------------------
[/code]

抱歉忘記打要用迴圈雨法寫這題>"<
jow
尊榮會員


發表:66
回覆:751
積分:1253
註冊:2002-03-13

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-05-01 13:42:16 IP:123.193.xxx.xxx 訂閱
[code cpp]
double __fastcall TForm1::FuncC(unsigned int n)
{
double ret=0, sum=0;
for(int i=0; i<=(int)n; i )
if((sum =i)>0)ret =1/sum;
return ret;
}
[/code]
aexi2000
一般會員


發表:4
回覆:5
積分:1
註冊:2008-04-28

發送簡訊給我
#5 引用回覆 回覆 發表時間:2008-05-01 16:04:01 IP:59.126.xxx.xxx 訂閱
這是我用你的方式寫的不知哪裡錯了>"<
http://delphi.ktop.com.tw/download.php?download=upload/48196b2caf137_新資料夾.rar
jow
尊榮會員


發表:66
回覆:751
積分:1253
註冊:2002-03-13

發送簡訊給我
#6 引用回覆 回覆 發表時間:2008-05-01 16:42:03 IP:123.193.xxx.xxx 訂閱
你程式碼中的問題:
(1)你手動將Unit1.cpp中, TForm1的建構式刪除了
[code cpp]
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
}
//---------------------------------------------------------------------------
[/code]
處理方式: 加回Unit1.cpp

(2)你手動將Unit1.cpp中, FormCreate的刪除了,所以會產生
外部引用的錯誤,因為Unit1.h中的宣告還在,並且在物件檢視器
中TForm1的Event Page中,還掛載著它的連結.
[code cpp]
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
}
//---------------------------------------------------------------------------
[/code]
處理方式:(a)移除Event Page中掛載的連結.(b)刪除Unit1.h中的宣告

(3)
新增的兩個Function,

[code cpp]
double __fastcall FuncA(unsigned int n);
double __fastcall FuncB(unsigned int n);
[/code]
在Unit1.h中, 沒有宣告.

處理方式:
(a)移除FuncA及FuncB前的 " TForm1:: "讓它變成一般函式
或 (b)在Unit1.h中,加入它的宣告.




編輯記錄
jow 重新編輯於 2008-05-01 16:47:06, 註解 無‧
aexi2000
一般會員


發表:4
回覆:5
積分:1
註冊:2008-04-28

發送簡訊給我
#7 引用回覆 回覆 發表時間:2008-05-01 17:23:15 IP:59.126.xxx.xxx 訂閱
我可以問一下label1代表啥媽
label2代表啥媽
又怎任意輸入n呢>"<?
抱歉資質比較愚笨
hipig
高階會員


發表:31
回覆:75
積分:111
註冊:2007-01-15

發送簡訊給我
#8 引用回覆 回覆 發表時間:2008-05-01 22:58:25 IP:220.132.xxx.xxx 未訂閱
基本上工具的用法並不在討論之內
你應該去找相關書籍或看HELP

我的程式碼比較簡單
因為這題目的作法幾乎大家都不會相差太多
[code cpp]
#include
#include

int main(int argc, char *argv[])
{
double sum=0, ans=0;
int i, n;
printf("輸入n階值(整數)\n");
scanf("%d", &n);
for(i=0; i<=n; i )
if((sum =i)>0)
ans =1/sum;
printf("Ans = %f\n", ans);
system("PAUSE");
return 0;
}

[/code]
編譯方式
用記事本打完後儲存成main.c後以指令bcc32編譯或以bcb開啟後直接編譯
[code cpp]
D:\>bcc32 main.c
Borland C 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland
main.c:
Warning W8057 main.c 16: Parameter 'argc' is never used in function main
Warning W8057 main.c 16: Parameter 'argv' is never used in function main
Turbo Incremental Link 5.64 Copyright (c) 1997-2002 Borland
[/code]
執行
[code cpp]
D:\>main
輸入n階值
3
Ans = 1.500000
請按任意鍵繼續 . . .

[/code]

===================引 用 aexi2000 文 章===================
我可以問一下label1代表啥媽
label2代表啥媽
又怎任意輸入n呢>"抱歉資質比較愚笨
aexi2000
一般會員


發表:4
回覆:5
積分:1
註冊:2008-04-28

發送簡訊給我
#9 引用回覆 回覆 發表時間:2008-05-02 00:39:54 IP:59.126.xxx.xxx 訂閱

===================引 用 hipig 文 章===================
基本上工具的用法並不在討論之內
你應該去找相關書籍或看HELP

我的程式碼比較簡單
因為這題目的作法幾乎大家都不會相差太多
[code cpp]
#include
#include

int main(int argc, char *argv[])
{
double sum=0, ans=0;
int i, n;
printf("輸入n階值(整數)\n");
scanf("%d", &n);
for(i=0; i<=n; i )
if((sum =i)>0)
ans =1/sum;
printf("Ans = %f\n", ans);
system("PAUSE");
return 0;
}

[/code]
編譯方式
用記事本打完後儲存成main.c後以指令bcc32編譯或以bcb開啟後直接編譯
[code cpp]
D:\>bcc32 main.c
Borland C 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland
main.c:
Warning W8057 main.c 16: Parameter 'argc' is never used in function main
Warning W8057 main.c 16: Parameter 'argv' is never used in function main
Turbo Incremental Link 5.64 Copyright (c) 1997-2002 Borland
[/code]
執行
[code cpp]
D:\>main
輸入n階值
3
Ans = 1.500000
請按任意鍵繼續 . . .

[/code]


我看不太懂呢>"<你能幫我看哪裡需要改媽感恩喔
http://delphi.ktop.com.tw/download.php?download=upload/4819f1bb52ebb_11.rar
hipig
高階會員


發表:31
回覆:75
積分:111
註冊:2007-01-15

發送簡訊給我
#10 引用回覆 回覆 發表時間:2008-05-02 01:57:37 IP:220.132.xxx.xxx 未訂閱
我覺得你不是不太懂
而是根本沒有看
連我寫的說明也完全沒有看

這題目老實說一看就像是學校作業之類的
姑且不論你有沒有興趣學
當一天和尚好歹也敲一天鐘
算算期中應該過了
半個學期都過去了
連給你答案都不知道要如何複製貼上??
BCB還不會用(版本還比我的好 = =)
連Label是啥都不知道
而我寫的是C語言
想都沒想就貼在FormCreate...這我已經不知道要寫啥了
你直接退選這科如何
如果是必修不給退
那我真的對貴校感到遺憾

我想剛剛我那短短幾句你都沒看了
上面那一串我也不奢望你會看到
看上面一堆回文我想你唯一的目的就是要已經寫好的程式和程式碼是吧
那 拿去(大放送說...)
http://delphi.ktop.com.tw/download.php?download=upload/4819ff4aab3a1_1234567.rar
當然
天下沒有白吃得午餐
這玩意有密碼
密碼也不難
就你這題目
算n =1234567好了
答案就是密碼....基本上不用算也應該知道大概是多少
至於含小數點有幾個字
用點觀察你就知道

這邊都是好人
偏偏我是個脾氣不佳的大壞人( ′___`)y-~
是呀 用心觀察呀不過才!* (注音)個字罷了
===================引 用 aexi2000 文 章===================
我看不太懂呢>"<你能幫我看哪裡需要改媽感恩喔
http://delphi.ktop.com.tw/download.php?download=upload/4819f1bb52ebb_11.rar
系統時間:2024-04-27 10:40:43
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!