發表文章

目前顯示的是 2013的文章

文字遮色片

延遲時間

延遲一秒 寫法一: Sleep(1000); 寫法二: for (int delay=0; delay<=10000; delay++) 寫法三: time_t t1 = time(NULL), t2; do { t2 = time(NULL); } while((t2-t1)<1;

for 巢狀迴圈

#include #include #include using namespace std; int main(int argc, char *argv[]) { int multiplier, faciend; for (faciend=1; faciend<=9; faciend++) { for (multiplier=1; multiplier<=9; multiplier++) { cout << multiplier << '*' << faciend << '=' << setw(2) << multiplier*faciend << '\t'; } cout << endl; } system("PAUSE"); return EXIT_SUCCESS; }

for 迴圈

基本型 int sum=0; for (int count=1; count<=MAX; count++) { sum+=count; } 簡化型 int sum=0; for (int count=1; count<=MAX; count++) sum+=count; 省略型 int sum=0, count=1; for ( ; count=1; count<=MAX; count++) sum+=count; 單行型 int count, sum; for (count=1, sum=0; count<=MAX; sum+=count, count++);

while巢狀迴圈 數字三角形

#include #include #include using namespace std; int main(int argc, char *argv[]) { int outer = 0; while (outer++ <= 4) { int inner = 0; while (inner++ < outer) { cout << setw(3) << inner; } cout << endl; } system("PAUSE"); return EXIT_SUCCESS; }

do-while巢狀迴圈 數字三角形矩陣

#include #include #include using namespace std; int main(int argc, char *argv[]) { int outer = 1; do { int inner = 1; do { cout << setw(3) << inner; } while (inner++ <= 5-outer); cout << endl; } while (outer++ <= 4); system("PAUSE"); return EXIT_SUCCESS; }

兩數除法(判斷大小及除數是否為0)

#include #include using namespace std; int main(void) { int a, b; cout << "請輸入二個整數數值,以空白分隔:"; cin >> a >> b; if(a >= b) { if(b == 0) cout << "除數為 0\n"; else cout << a << " / " << b << " = " << (float)a/(float)b << endl; } else { if(a == 0) cout << "除數為 0\n"; else cout << b << " / " << a << " = " << (float)b/(float)a << endl; } return 0; }

判斷直角、鈍角或銳角三角形(II)

#include #include #include using namespace std; int main(int argc, char *argv[]) { float a, b, c; cout << "請輸入三角形三邊邊長,以空白分隔:"; cin >> a >> b >> c; if((a+b)>c && (b+c)>a && (c+a)>b) { if(pow(a,2) + pow(b,2) == pow(c,2) || pow(b,2) + pow(c,2) == pow(a,2) || pow(c,2) + pow(a,2) == pow(b,2)) cout << a << ' ' << b << ' ' << c << " 三邊構成直角三角形\n"; else if(pow(a,2) + pow(b,2) > pow(c,2) && pow(b,2) + pow(c,2) > pow(a,2) && pow(c,2) + pow(a,2) > pow(b,2)) cout << a << ' ' << b << ' ' << c << " 三邊構成銳角三角形\n"; else if(pow(a,2) + pow(b,2) < pow(c,2) || pow(b,2) + pow(c,2) < pow(a,2) || pow(c,2) + pow(a,2) < pow(b,2)) cout << a << ' ' << b << ' ' << c << " 三邊構成鈍角三角形\n"; } else

判斷直角、鈍角或銳角三角形(I)

#include #include #include using namespace std; int main(int argc, char *argv[]) { float a, b, c, d; cout << "請輸入三角形三邊邊長,以空白分隔:"; cin >> a >> b >> c; d = (pow(a,2)+pow(b,2)-pow(c,2))*(pow(b,2)+pow(c,2)-pow(a,2))*(pow(a,2)+pow(c,2)-pow(b,2)); if (d == 0 && (a+b)>c && (b+c)>a && (c+a)>b) cout << a << ' ' << b << ' ' << c << " 三邊構成直角三角形\n"; else if (d > 0 && (a+b)>c && (b+c)>a && (c+a)>b) cout << a << ' ' << b << ' ' << c << " 三邊構成銳角三角形\n"; else if (d < 0 && (a+b)>c && (b+c)>a && (c+a)>b) cout << a << ' ' << b << ' ' << c << " 三邊構成鈍角三角形\n"; else cout << a << ' ' << b << ' ' << c <&

判斷三角形三邊邊長是否構成三角形

1.利用兩邊長和必須大於第三邊,而且需檢驗三次同時成立。 #include #include #include using namespace std; int main(int argc, char *argv[]) { float a, b, c; cout << "請輸入三角形三邊邊長,以空白分隔:"; cin >> a >> b >> c; if((a+b)>c && (b+c)>a && (c+a)>b) cout << a << ' ' << b << ' ' << c << " 三邊構成三角形\n"; else cout << a << ' ' << b << ' ' << c << " 三邊不構成三角形\n"; system("PAUSE"); return EXIT_SUCCESS; } 2.利用兩邊和大於第三邊且兩邊差的絕對值小於第三邊。 #include #include #include using namespace std; int main(int argc, char *argv[]) { float a, b, c; cout << "請輸入三角形三邊邊長,以空白分隔:"; cin >> a >> b >> c; if((a+b)>c && abs(a-b)

cout&cin

Q:求BMI #include <cstdlib> #include <iostream> #include <cmath> using namespace std; int main(int argc, char *argv[]) { float weight; float height; cout << "請輸入體重:"; cin >> weight; cout << "請輸入身高:"; cin >> height; float bmi = weight / pow(height, 2); cout << "bmi = " << bmi << " 公斤/平方公尺\n";      system("PAUSE");         return EXIT_SUCCESS; }

整數亂數

Q:產生0~9之間的整數亂數 #include <cstdlib> #include <iostream> #include <ctime> using namespace std; int main(int argc, char *argv[]) { srand(time(NULL)); cout << 0 + rand() % (9 - 0 + 1) << endl;          system("PAUSE");     return EXIT_SUCCESS; }

比較大小

Q:比較與輸出$sin25^\circ$與$cos70^\circ$的大小 #include <cstdlib> #include <iostream> #include <cmath> using namespace std; int main(int argc, char *argv[]) { const int max = 2; int l, i, j, k; double funBuffer; char strBuffer[8]; double a1 = (3.1415926) * 25 / 180; double a2 = (3.1415926) * 70 / 180; double fun[max] = {sin(a1), cos(a2)}; char str[max][8] = {"sin(25)", "cos(70)"}; for (l=0; l<max; l++) cout << str[l] << " = " << fun[l] << endl; cout << endl; for (i=0; i<max-1; i++) for (j=i; j<max; j++) if (fun[i] > fun[j]) { funBuffer = fun[i]; fun[i] = fun[j]; fun[j] = funBuffer; for (k=0; k<8; k++) { strBuffer[k] = str[i][k]; str[i][k] = str[j][k]; str[j][k] = strBuffer[k]; } } for (i = 0; i<max; i++) { cout << str[i]; if (i<max-1) cout << " < "; } c

輸出問題

double a; a = 6./9;     cout << a << endl;  輸出為0.66667         double a; a = 6/9;   cout << a << endl;  輸出為0

CI基本設定與login頁面建立

圖片
1.下載codenogiter http://www.codeigniter.org.tw/downloads/file/CodeIgniter_2.1.4 將壓縮檔下的資料上傳至放置網頁的空間中 2.建立.htaccess => ci去掉index.php的方式 <IfModule mod_rewrite.c>    RewriteEngine on    RewriteBase / CI/    RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|assets|robots\.txt|$)    RewriteRule ^(.*)$ index.php/$1 [L,QSA] </IfModule> #RewriteEngine on #RewriteBase / #RewriteCond $1 !^(index\.php|images|robots\.txt|$) #RewriteRule ^(.*)$ index.php/$1 [L,QSA] 3.在URL 移除 index.php 編輯application/config/config.php 將$config['index_page'] = 'index.php';改成$config['index_page'] = ''; 4.修改application/autoload.php 原 $autoload['libraries'] = array(); 修改為 $autoload['libraries'] = array( 'database','session' ); 5.編輯 application/config/database.php 6.編輯application/config/autoload.php 將$autoload['helper'] = array(); 修改為 $autoload['helper'] = array('f

使用者資料庫設定

圖片
1.建立資料庫使用者表單 users:使用者表單 temp_users:申請註冊使用者表單 2.users的表單結構 3.temp_users的表單結構 4.users預先建立使用者 其中password是以md5編碼方式 http://www.miraclesalad.com/webtools/md5.php password = 5f4dcc3b5aa765d61d8327deb882cf99

EasyPHP環境設定

圖片
單機操作是使用EasyPHP環境 帳號創立,有最基本的root, 接著創nee2427,此帳號內要建立三個table: 1.學生student_grade(部 division 、年級grade、班級class、學號Sid、中文姓名Cname、英文姓名Ename、護照ID、ELA、IS、Math、Enrichment、Eng、ELA_G、IS _G 、Math _G 、Enrichment _G 、Eng _G ) 這裡忘記拍照....跟下張照片一樣的意思 只能使用英文命名,類型varchar 長度255,先設定到護照,後面的先不設定讓他預設INT,以後要改再改,後面2.3表格也是varchar  長度255 varchar=最長字元 2.教師account(教師帳號T_account、姓名T_name、密碼password) 3.權限表competence (教師thacher) 全部建立完成如下圖 G=Group,有Group代表要建Jexcel

零分(值得深思的一篇文章)

零分(值得深思的一篇文章) 一位中學生拿了一張「零分」的考卷給媽媽簽名,那孩子的母親仍保持著笑容說:「兒子呀 !!  你就是這麼乖,老師說要蓋章,你就一定會拿來蓋章。你是個好孩子 ! 」 而後她問兒子題目難不難呢 ? 兒子竟說:「不難呀 !!  因為老師說:『考卷寫好可以去打籃球。』 以我的速度,寫好了,球場必定已客滿了,所以我只寫了名字就去打球了。陽光又好,球場上那時只有我一人,好愉快喔 !  反正考卷一定會發下來,回家再寫也是一樣。」 媽媽終於明白零分之後的另一段插曲;兒子不在乎當時的分數,認為只要事後弄懂題目即可。真是灑脫 ! 這是源於媽媽常說的: 「事後把考題全弄懂,跟考滿分的人一樣棒」的觀念,在這個家只有包容與讚美。 兒女們經常把學校的大小事帶回來與爸媽共同分享。 有一次姊姊數學只考八分,氣得不想讀普通高中,想轉到高職去。 媽媽說從前大專聯考,被錄取者也有人數學是個位數的。 只要有分數就有希望。 女兒在媽媽的鼓勵下,八分、十六分、逐步的往前進,終於在高三下學期初就甄試上了大學。 班上另一位高材生就沒有這位小孩這麼快樂。 高材生常為九十九分而悶悶不樂。 因為他的媽媽是個完美主義者,常說: 「你怎麼這麼笨呀 !!  幫你溫習了一晚, 還如此粗心,掉了一分。」 少一分,回家可是要被敲一下頭的。 並且一百分與九十分所領的零用錢相差好幾倍 ! 再說聯考,差一分說不定就輸了幾個人哩 ! 孩子在這家中難得有笑容。全家的情緒與孩子的分數息息相關。 一位功課老是掛車尾的小學二年級學生,有一天,拿了一張九十分的小考考卷,興沖沖的跑回家告訴媽媽。 媽媽開心的把它框起來,掛在客廳。 晚上,一向成績很好的姐姐問弟弟:「班上有沒有人考一百分呢 ? 」 弟弟回答說:「好多人呀 !! 」 姐姐又追問他有沒有人九十分以下呢 ? 弟弟笑著說:「沒有啦 !! 」 姐姐暗自好笑,原來弟弟是最後一名呢 ! 父親出差回來,看到弟弟的成績,開心的說:「我的兒子進步好多 ! 」 奶奶每天飯後,看著九十分的考卷就露出滿足的笑容,親朋好友來了,就讚美這孩子。 這個男孩子覺得日子過得好快樂,好有成就感,開始每天更用心在書本上,功課扶搖直