關於我自己

我的相片
Welcome to discuss about : Chinese Traditional Medicine and Acupuncture Please send me the email: tccnchsu@gmail.com Chih-Yu Hsu

最新消息

總網頁瀏覽量

2008年9月18日 星期四

逢甲課程-物件導向設計-VC++(#)

971-物件導向設計-VC++(#)OBJECT-ORIENTED DESIGN(應數三合)[選課代號:3013]
-----------------------------------------------------------------------------

第十六週 2008/12/19 網路程式
-----------------------------------------------------------------------------
Wireshark 教學
http://blog.shaolin.tw/2008/03/wireshark.html
防毒軟體失效,您要靠誰? 木馬後門入侵,誰能救您? 網路通訊的關鍵,看封包! 網路攻擊的關鍵,看封包! 病毒蠕蟲感染分析.


----------------------------------------------------------------------------------
網路通訊是靠"封包"廣播的方式,因此才可以看見自己和別人的封包!

安裝Wireshark:

官方網頁來下載安裝程式,位置是http://www.wireshark.org/


操作步驟
步驟1: Capture → Interfaces 選擇一個 start

步驟2: Capture → stop

步驟3:Expression,找到TELNET字樣如下,直接按OK。
步驟4:Apply
步驟5:Capture → start


實例測試

步驟1:測試
開始->執行cmd
在命令提示字元視窗

1. ipconfig 本機之IP
2. 連線 telnet bbs.rumor.tw
3. Wireshark 看封包, bbs.rumor.tw 之IP 為 140.136.148.18
Source(來源) 發送封包, Destination (目的地) 接收封包
4.輸入 guest
5.Wireshark 看封包, telnet 可看到 g-u-e-s-t
6. Follow TCP Stream

練習:
觀察HTTP Protocol的封包
目的:藉由HTTP Protocol的觀察,練習篩選所要的資訊,並能夠清楚的知道TCP/IP實際的運作模式


-------------------------------------------------------------------------------
參考資料


Instructor Resources Computer Networking with Internet Protocols and Technology
http://williamstallings.com/CNIP/CNIP1e-inst.html

Ethereal 抓網路封包+封包內容分析+看明碼連線教學內容

http://chris701203.pixnet.net/blog/post/21891886
http://www.google.com.tw/search?hl=zh-TW&q=%E7%9C%8B%E5%B0%81%E5%8C%85++%E5%BE%8C%E9%96%80&meta=&aq=f&oq=


-----------------------------------------------------------------------------
匯入 vb 之winsock 元件
網路程式設計CH7
http://www.csie.thit.edu.tw/ELearn/Chapter07A.ppt
http://www.csie.thit.edu.tw/ELearn/Chapter03A.ppt

Download a Copy of the MSCOM32.OCX
http://www.yes-tele.com/mscomm.html
下载mswinsck.ocx与VB6Controls.reg:
http://zzzevazzz.bokee.com/inc/vb6controls.rar
參考
http://hi.baidu.com/zzzevazzz/blog/item/8790a501de37ced7267fb52e.html



1. 將mswinsck.ocx放入C:\WINDOWS\system32 之中

2.
開始->執行
regsvr32 mswinsck.ocx

Someone else says this worked install the license for MSCOMM32.OCX with VB.NET
I executed VB6Controls.reg from the VB.Net installation CD and registered the .ocx and it worked.

Full Download Results For "VB6Controls.reg"


http://www.yes-tele.com/mscomm.html

http://support.microsoft.com/kb/318597/zh-tw

3.
開始->執行
regedit.exe
檔案-匯入
選 vb6controls
4. 執行microsoft visual studio 2003
建立專案
其他語言 Visual Basic
windows 應用程式
確定
5. 工具箱-資料-右鍵-選擇項目-COM元件
Microsoft WinSock Control.version 6.0
打勾,確定








------------------------------------------------------------------------------
第十五週 2008/12/12 網路程式設計


------------------------------------------------------------------------------
1.問 http://tw.yahoo.com/ 的主機 IP為何?
using System.Net;
-------
IPAddress[]myaddress = Dns.GetHostAddresses("tw.yahoo.com");
Console.WriteLine(myaddress[0]);
-------------------------------------------------------------------------------
2.問 IP 119.160.246.241 的主機名稱為何?
IPHostEntry hostaddress;
hostaddress = Dns.GetHostEntry("119.160.246.241");
Console.WriteLine(hostaddress.HostName);
-------------------------------------------------------------------------------
3.
How to read XML from a file by using Visual C# .NET
http://programsolution.blogspot.com/2008/01/how-to-read-xml-from-file-by-using.html

XML Programming in C# and .NET
http://www.c-sharpcorner.com/Articles/ArticleListing.aspx?SectionID=1&SubSectionID=79
---------------------------------------
使用 Visual C# .NET 從 URL 讀取 XML 資料
http://support.microsoft.com/kb/307643
-------------
using System.Xml;
---
String URLString = "http://www.galaxquery.com/demo/docs/book1.xml";
XmlTextReader reader = new XmlTextReader(URLString);
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
Console.Write("<" + reader.Name);
Console.WriteLine(">");
break;

case XmlNodeType.Text: //Display the text in each element.
Console.WriteLine(reader.Value);
break;

case XmlNodeType.EndElement: //Display the end of the element.
Console.Write(" Console.WriteLine(">");
break;
}
}

-------------------------------------------------------------------------------------
-----------------------------------------------------------------------------




------------------------------------------------------------------------------
第十四週 2008/12/12 集合(Queue,Stack)


Queue 類別(FIFO 先進先出 First In First Out)
------------------------------------------------------------------------------
Enqueue()方法加入元素到佇列最尾端,Dequeue 方法從佇列最前端拿出元素


using System.Collections;

object x;
Queue a = new Queue();
Console.WriteLine("長度" + a.Count);
a.Enqueue("1");
Console.WriteLine("加入1後長度" + a.Count);
a.Enqueue("2");
Console.WriteLine("加入2後長度"+a.Count);
x=a.Dequeue();
Console.WriteLine("取出資料" + x);
Console.WriteLine("長度" + a.Count);
x=a.Dequeue();
Console.WriteLine("取出資料" + x);
Console.WriteLine("長度" + a.Count);


------------------------------------------------------------------------------
peek() 方法永遠只看最前端,並不會將它取出

object x;
Queue a = new Queue();
Console.WriteLine("長度" + a.Count);
a.Enqueue("1");
Console.WriteLine("加入1後長度" + a.Count);
a.Enqueue("2");
Console.WriteLine("加入2後長度"+a.Count);
x=a.Peek();
Console.WriteLine("取出資料" + x);
Console.WriteLine("長度" + a.Count);
x=a.Peek();
Console.WriteLine("取出資料" + x);
Console.WriteLine("長度" + a.Count);


------------------------------------------------------------------------------
ToArray()方法 將佇列轉換成陣列

object[] x;
Queue a = new Queue();
Console.WriteLine("長度" + a.Count);
a.Enqueue("1");
Console.WriteLine("加入1後長度" + a.Count);
a.Enqueue("2");
Console.WriteLine("加入2後長度"+a.Count);
x=a.ToArray();
Console.WriteLine("取出資料" + x[0]);
Console.WriteLine("長度" + a.Count);
Console.WriteLine("取出資料" + x[1]);
Console.WriteLine("長度" + a.Count);
------------------------------------------------------------------------------
課堂練習:
設計程式模擬
一台網路型印表機(標籤),有兩台電腦(兩個按鈕)透過網路送出列印文件,顯示等待列印的數目.
設計(一個按鈕)可以印完一個文件並將它除去.
在類別下宣告
Queue a=new Queue(32);
object[] x;
int b = 0;
------------------------
按鈕程式
string s="";
b = b + 1;
a.Enqueue(b);
x=a.ToArray();
for (int i = 0; i < a.Count; i++)
{
s = s + x[i];
label1.Text = "" + s;
}



------------------------------------------------------------------------------
Stack 類別(LIFO Last In First Out 後進先出)

object[] x;
Stack a = new Stack();
Console.WriteLine("長度" + a.Count);
a.Push("1");
Console.WriteLine("加入1後長度" + a.Count);
a.Push("2");
Console.WriteLine("加入2後長度"+a.Count);
Console.WriteLine("長度" + a.Count);
Console.WriteLine("取出資料" + a.Pop());
Console.WriteLine("長度" + a.Count);
Console.WriteLine("取出資料" + a.Pop());
Console.WriteLine("長度" + a.Count);

------------------------------------------------------------------------------
課堂練習:
設計程式模擬
漢諾塔問題
http://www.google.com.tw/search?hl=zh-TW&q=%E8%8B%B1%E6%96%87+%E6%BC%A2%E8%AB%BE%E5%A1%94%E5%95%8F%E9%A1%8C&meta=&aq=f&oq=
http://www.google.com.tw/search?hl=zh-TW&q=Hanoi+tower&btnG=%E6%90%9C%E5%B0%8B&meta=&aq=f&oq=




http://www.google.com.tw/images?q=tbn:3ssGiIp86l4J::mmdays.files.wordpress.com/2007/05/tower_of_hanoi.jpg

1.實作三個stack a,b,c
2.第一個按鈕 "開始",將a 放入 3,2,1, 並在標籤labale中顯現(利用方法toArray產生陣列再用for結合陣例放入字串),將b,c stack中的內容清掉.
3. 另七個按鈕
按鈕"第一步": (a之1->b)將a 的最上元素pop出,再push到b,即b.push(a.pop())
按鈕"第二步": (a之2->c) 將a 的最上元素pop出,再push到c,即c.push(a.pop())
按鈕"第三步": (b之1->c) 將b 的最上元素pop出,再push到c,即c.push(b.pop())
按鈕"第四步": (a之3->b) 將a 的最上元素pop出,再push到b,即b.push(a.pop())
按鈕"第五步": (c之1->a) 將c 的最上元素pop出,再push到a,即a.push(c.pop())
按鈕"第六步": (c之2->b) 將c 的最上元素pop出,再push到b,即b.push(c.pop())
按鈕"第七步": (a之1->b) 將a 的最上元素pop出,再push到b,即b.push(a.pop())



------------------------------------------------------------------------------

第十三週 2008/12/05 集合(ArrayList)




------------------------------------------------------------------------------
複習
範例 10-3a


int c,i;
int[] a ={ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
string s="";


Random r = new Random();
for (i = 0; i <= 3;i++ )
{
c = r.Next(10-i) + i;
s = s + a[c];
label2.Text = s;
a[c] = a[i];%挑過的數用前面的數覆蓋,因為前面的數還未被挑到,被挑過的不能再挑,因此覆蓋掉
}
----------------------------------------

------------------------------------------------------------------------------
1. 增加命名空間
using System.Collections;
2. 實作ArrayList類別之物件b
ArrayList a = new ArrayList();
3. 印出物件b所放資料的容量
Console.WriteLine(b.Capacity);
4. 加入數字5和2到b中
b.Add(5);
b.Add(2);
5. 印出物件b能放資料的容量,是否為2
Console.WriteLine(b.Capacity);
ans:4 加倍

課堂練習:建構子給定值0,2,3
ArrayList a = new ArrayList(0);

7. 印出物件b已放資料的容量,是否為2
Console.WriteLine(b.Count);
ans: Yes
8. 把b的元素取出
Console.WriteLine(b[1]);
Console.WriteLine(b[2]);
--------------------------
Console.WriteLine(b[0]);
Console.WriteLine(b[1]);
正確
-----------------------------------------------------------------------------
ArrayList b = new ArrayList(3);
Console.WriteLine(b.Capacity);
b.Add(5);
b.Add(2);
Console.WriteLine(b.Capacity);
Console.WriteLine(b.Count);
Console.WriteLine(b[0]);
Console.WriteLine(b[1]);
------------------------------------------------------------------------------
9. 排序方法 sort (複習 6-9~ 6-15)
ArrayList b = new ArrayList(9);
Console.WriteLine(b.Capacity);
b.Add(5);
b.Add(2);
b.Add(3);
b.Add(9);
b.Add(6);
b.Add(4);
Console.WriteLine(b.Capacity);
Console.WriteLine(b.Count);
Console.WriteLine("排序前");
Console.WriteLine(b[0]);
Console.WriteLine(b[1]);
Console.WriteLine(b[2]);
Console.WriteLine(b[3]);
Console.WriteLine(b[4]);
Console.WriteLine(b[5]);
b.Sort();
Console.WriteLine("排序後");
for (int i=0;i<=5;i++)
{
Console.WriteLine(b[i]);
}
----------------------------------------------------------------------------------
10. 清除ArrayList 的所有內容
Console.WriteLine("清除前");
Console.WriteLine(b.Count);
b.Clear();
Console.WriteLine("清除後");
Console.WriteLine(b.Count);
-----------------------------------------------------------------------------
搜尋給訂數字的編號
int n=b.BinarySearch(4);
Console.WriteLine(n);

Console.WriteLine(b.IndexOf(4));
------------------------------------------------------------------------------
插入:在給定的號插入數值
b.Insert(2, 7);
Console.WriteLine("插入後");

for (int i = 0; i <= 5; i++)
{
Console.WriteLine(b[i]);
}

-------------------------------------------------------------------------------
從0~9 中挑四個數字,但不可重複
另一種寫法
int c;
string s="";
ArrayList b = new ArrayList(9);
for (int i = 0; i <= 9; i++)
{
b.Add(i);
Console.WriteLine(b[i]);
}

Random r = new Random();
for (int i=0;i<=3;i++)
{
c = r.Next(b.Count);
s = s + b[c];
Console.WriteLine("移除前"+b.Count);
b.RemoveAt(c);
Console.WriteLine( "移除後"+ b.Count);
Console.WriteLine( s);
}


------------------------------------------------------------------------------
課後練習
利用ArrayList製作猜數字遊戲


------------------------------------------------------------------------------
第十二週 2008/11/28 字串
------------------------------------------------------------------------------
String 字串類別
windows application
------------------------------------------------------------------------------
1. 在表單內寫程式(滑鼠在表單上按左鍵兩下)

2. 在表單上放一個textbox,並檢視屬性視窗中name的屬性值
放一個標籤修改name的屬性值為lname,修改text屬性值為"長度"
放一個標籤修改name的屬性值為llength,修改text屬性值為" ",並修改borderstyle


3. 程式
1. 宣告 並實作str1物件
char[] a ={ 'a', 'b', 'c' };
String strlen;
int length;
String str1 = new string(a);

2. 在文字方塊放入字串str
textBox1=str;


char[] a ={ 'a', 'b', 'c' };
String strlen;
int length;
String str1 = new string(a);
textBox1.Text = str1;
4. llength.Text = strlen;

char[] a ={ 'a', 'b', 'c' };
String strlen;
String str1 = new string(a);
textBox1.Text = str1;
string length ="長度"+str1.Length;
strlen = length;
llength.Text = strlen;

------------------------------------------------------------------------------
範例:猜數字遊戲(四位數阿拉伯數字不可重複)
1. 使用人出題,電腦猜數字
2. 電腦出題,使用人猜數字

按鈕的程式
private void button1_Click(object sender, EventArgs e)
{
Ngame a = new Ngame();
llength.Text =""+a.no1+a.no2+a.no3+a.no4;
}

----------------
發牌類別
public class Ngame
{
public int no1,no2,no3,no4;
public Ngame()
{
Random s = new Random();
no1 = s.Next(1, 5);
no2 = s.Next(1, 5);
no3 = s.Next(1, 5);
no4 = s.Next(1, 5);

}

}


課堂練習:
猜撲克牌遊戲
1. 使用人出題(花色和數字),電腦猜(花色和數字)
2. 電腦出題(花色和數字),使用人猜(花色和數字)
-----------------------------------------------------------------------------
第十一週 2008/11/21 數值
------------------------------------------------------------------------------
複習_類別


在主類別MyMain中main方法之中實作產生的rect物件的屬性,預設值為0.
class Mymain
{

static void Main(string[] args)
{
CRectangle rect = new CRectangle();
//實作名稱為rect的物件(OBJECT)具有CRectangle 類別的屬性width和height及方法compute_area()
Console.WriteLine("rect.width" + rect.width);
Console.WriteLine("rect.height" + rect.height);
}
}
public class CRectangle
{
public int width, height;
public int compute_area()
{
int area;
area = width * height;
return area;
}

}
-----------------------------------------------------------------------------
rect屬性質更改後產生永久改變,
但是新誕生新的物件rect1其width與height也是預設之值0.


static void Main(string[] args)
{
CRectangle rect = new CRectangle();
Console.WriteLine("rect.width" + rect.width);
Console.WriteLine("rect.height" + rect.height);
rect.width = 99;
rect.height = 100;
Console.WriteLine("rect.width" + rect.width);
Console.WriteLine("rect.height" + rect.height);
CRectangle rect1 = new CRectangle();
Console.WriteLine("rect1.width" + rect1.width);
Console.WriteLine("rect1.height" + rect1.height);
}
----------------------------------------------------------------------------
利用建構子(constructor)來解決預設值不希望是0的情況
public CRectangle()
{
width = 99;
height = 100;
}
-----------------------------------------------------------------------------
仿方形類別設計圓形類別,分別計算半徑為5,10,15的三個圓形面積與周長
1. 改類別名稱CCricle
public class CCricle
{
public int width, height;
public int compute_area()
{
int area;
area = width * height;
return area;
}

}
2.將屬性改成只有半徑
public class CCricle
{
public int radius;
public int compute_area()
{
int area;
area = width * height;
return area;
}

}

3.修改方法compute_area()的內容,圓面積公式


int area;
area = radius * radius*ˇ;
return area;

4. 主程式實作產生物件 circ
CCircle circ = new CCircle;


5.簡單的發牌程式
Random r = new Random();
int no=r.Next(1,14);
int color = r.Next(1, 5);
switch (color)
{
case 1:
Console.WriteLine("黑桃");
break;
case 2:
Console.WriteLine("紅心");
break;
case 3:
Console.WriteLine("方塊");
break;
case 4:
Console.WriteLine("梅花");
break;
}

Console.WriteLine(no);

---------------------------------------------------------------------------





-----------------------------------------------------------------------------
第十週 2008/11/14
類別(Class)

what:幾何形狀可以分為許多類,例如圓形,...,三角形,矩形.
圓形和矩形是很重要的類別(類別 Class)
幾何形狀中的矩形類別有四個直角,其大小由長(width)與寬(height)做決定.
矩形的長與寬的值給定以後,我們叫這個具有特定長與寬的矩形為一個實體物件(東西),是由(抽象)矩形類別實作而成的東西(物件).
同理幾何形狀中圓形類別是由到一個點(圓心)相等距離(半徑)之所有點所乘的集合.給定特殊半徑值的圓形物件(東西)),是由(抽象)圓形類別實作而成的東西(物件).

why:寫程式為何要有類別的觀念?

以簡馭繁

為自己的類別取名
例:
-----------------------------------------------------------------------------
class Mymain
{
static void Main(string[] args)
{

}
}

-----------------------------------------------------------------------------
宣告變數
class Mymain
{
static void Main(string[] args)
{
int width, height, area;

}
}
-----------------------------------------------------------------------------
給定舉行之width與height定起始值並計算矩形面積(area)
class Mymain
{
static void Main(string[] args)
{
int width, height, area;
width = 10;
height = 5;
area = width * height;
Console.WriteLine("area="+area);

}
}
-----------------------------------------------------------------------------
如果要計算三個不同長寬的矩形面積,則程式要複製三份,使程式看起來繁瑣,又佔篇幅
class Mymain
{
static void Main(string[] args)
{
int width, height, area;
width = 10;
height = 5;
area = width * height;
Console.WriteLine("area="+area);
width = 20;
height = 10;
area = width * height;
Console.WriteLine("area=" + area);
width = 30;
height = 15;
area = width * height;
Console.WriteLine("area=" + area);
}
-----------------------------------------------------------------------------
建立矩形類別
class Mymain
{
static void Main(string[] args)
{
int width, height, area;
width = 10;
height = 5;
area = width * height;
Console.WriteLine("area="+area);
width = 20;
height = 10;
area = width * height;
Console.WriteLine("area=" + area);
width = 30;
height = 15;
area = width * height;
Console.WriteLine("area=" + area);
}
}
class CRectangle
{
int width, height;
int compute_area()
{
int area;
area=width*height;
return area;
}

}
-----------------------------------------------------------------------------
在主類別中新生()一個給定名稱(rect)的矩形物件
class Mymain
{
static void Main(string[] args)
{
CRectangle rect = new CRectangle();
}
}
class CRectangle
{
int width, height;
int compute_area()
{
int area;
area=width*height;
return area;
}

}
-----------------------------------------------------------------------------
給定rect矩形物件之特定的長寬並修改屬性width及height之範圍為public
class Mymain
{
static void Main(string[] args)
{
CRectangle rect = new CRectangle();
rect.width = 10;
rect.height = 5;
}
}
public class CRectangle
{
public int width;
public int height;
int compute_area()
{
int area;
area=width*height;
return area;
}

}

-----------------------------------------------------------------------------
修改矩形rect物件之計算面積方法compute_area()之範圍為public並利用其計算矩形面積的數值指定給變數result,宣告int整數型態給result.
54
class Mymain
{
static void Main(string[] args)
{
int result;
CRectangle rect = new CRectangle();
rect.width = 10;
rect.height = 5;
result=rect.compute_area();
}
}
public class CRectangle
{
public int width;
public int height;
public int compute_area()
{
int area;
area=width*height;
return area;
}

}
-----------------------------------------------------------------------------
利用終端機consle顯示result之數值結果
class Mymain
{
static void Main(string[] args)
{
int result;
CRectangle rect = new CRectangle();
rect.width = 10;
rect.height = 5;
result=rect.compute_area();
Console.WriteLine("result=" + result);

}
}
public class CRectangle
{
public int width;
public int height;
public int compute_area()
{
int area;
area=width*height;
return area;
}

}

-----------------------------------------------------------------------------
在CRectangle類別中增加計算周長的計算方法perimeter()
public class CRectangle
{
public int width;
public int height;
public int compute_area()
{
int area;
area=width*height;
return area;
}
public int compute_parimeter()
{
int parimeter;
parimeter = 2 * (width + height);
return parimeter;
}

}
----------------------------------------------------------------------------
在主類別MyMain中使用矩形rect物件之計算面積方法compute_perimeter()並利用其計算矩形周長的數值指定給變數result_perimeter,宣告int整數型態給result.

static void Main(string[] args)
{
int result, result_perimeter;
CRectangle rect = new CRectangle();
rect.width = 10;
rect.height = 5;
result=rect.compute_area();
Console.WriteLine("result=" + result);
result_perimeter = rect.compute_parimeter();
Console.WriteLine("result_perimeter=" + result_perimeter);
}
-----------------------------------------------------------------------------
在主類別MyMain中之main方法增加計算width = 20;height = 10及width = 30;height = 15;兩矩形之面積與周長

static void Main(string[] args)
{
int result, result_perimeter;
CRectangle rect = new CRectangle();
rect.width = 10;
rect.height = 5;
result=rect.compute_area();
Console.WriteLine("result=" + result);
result_perimeter = rect.compute_parimeter();
Console.WriteLine("result_perimeter=" + result_perimeter);
rect.width = 20;
rect.height = 10;
result = rect.compute_area();
Console.WriteLine("result=" + result);
result_perimeter = rect.compute_parimeter();
Console.WriteLine("result_perimeter=" + result_perimeter);
rect.width = 30;
rect.height = 15;
result = rect.compute_area();
Console.WriteLine("result=" + result);
result_perimeter = rect.compute_parimeter();
Console.WriteLine("result_perimeter=" + result_perimeter);
}


-----------------------------------------------------------------------------
課堂練習
設計圓形類別,分別計算半徑為5,10,15的三個圓形面積與周長
-----------------------------------------------------------------------------

-----------------------------------------------------------------------------

第九週 2008/11/07
主題:方法(Method)
static void Main(string[] args)
{
int d = 0, e = 0,f=0;
d = 1;
e = 2;
f = work(d, e);

Console.Write(f);
}

static int work(int a, int b)
{
int c;
c=a+b;
return (c);
}
---------------------------------------------------
static void Main(string[] args)
{
int[,] a ={ { 1, 2 }, { 4, 3 } };
int[] b ={0,0,0,0};
b=work(a);
for (int i = 0; i <= 3;i++ ) Console.Write(b[i]); } static int[] work(int[,] a) { int[] b ={ 0, 0, 0, 0 }; b[0] = a[0, 0]; b[1] = a[0, 1]; b[2] = a[1, 1]; b[3] = a[1, 0]; return (b); } ----------------------------------------------------------------------------- static int[] work(int[,] a) { int[] b ={ 0, 0, 0, 0 }; int k = 0; for (int i = 0; i <= 1; i++) { if (i == 0) { //第一列 for (int j = 0; j <= 1; j++) { b[k] = a[i, j]; k++; } } if (i == 1) { //第二列 for (int j = 1; j >= 0; j--)
{
b[k] = a[i, j];
k++;
}
}

}

return (b);

}
----------------------------------四列的情形----------------------------------
static int[] work(int[,] a)
{
int[] b ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int k = 0;
for (int i = 0; i <= 3; i++) { if (i == 0) { //第一列 for (int j = 0; j <= 3; j++) { b[k] = a[i, j]; k++; } } if (i == 1) { //第二列 for (int j = 3; j >= 0; j--)
{
b[k] = a[i, j];
k++;
}
}
if (i == 2)
{
//第三列
for (int j = 0; j <= 3; j++) { b[k] = a[i, j]; k++; } } if (i == 3) { //第四列 for (int j = 3; j >= 0; j--)
{
b[k] = a[i, j];
k++;
}
}
}

return (b);
------------------------------比較簡潔的寫法------------------------------------
static int[] work(int[,] a)
{
int[] b ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int k = 0;
for (int i = 0; i <= 3; i++) { if (i%2 == 0) { //偶數列 for (int j = 0; j <= 3; j++) { b[k] = a[i, j]; k++; } } if (i%2 == 1) { //奇數列 for (int j = 3; j >= 0; j--)
{
b[k] = a[i, j];
k++;
}
}

}

return (b);
------------------------------switch的寫法-------------------------------------
{
int[] b ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int k = 0;
for (int i = 0; i <= 3; i++) { switch (i%2 == 0) { case 0: //偶數列 for (int j = 0; j <= 3; j++) { b[k] = a[i, j]; k++; } break; case 1: { //奇數列 for (int j = 3; j >= 0; j--)
{
b[k] = a[i, j];
k++;
}
}
break;
}


}

return (b);
------------------------------------------------------------------------------

第八週 2008/10/31
期中考
-----------------------------------------------------------------------------
第七週 2008/10/24

static void Main(string[] args)
{
int[] a ={0,2};
Console.WriteLine(a[1]);
}
----------------------------------------
static void Main(string[] args)
{
int[] a ={0,2,4,6,8,10};
int i = 0;
for (i = 0; i <= 5;i++ ) Console.WriteLine(a[i]); } ----------------------------------------- static void Main(string[] args) { int[] a ={0,2,4,6,8,10}; int i = 0; int tmp = 0; tmp = a[0]; a[0] = a[1]; a[1] = tmp; for (i = 0; i <= 5;i++ ) Console.WriteLine(a[i]); } ---------------換位置------------------------ static void Main(string[] args) { int[] a ={6,4,2,0}; int i = 0; int tmp = 0; if (a[0] > a[1])
{

tmp = a[0];
a[0] = a[1];
a[1] = tmp;
}
for (i = 0; i <= 5;i++ ) Console.WriteLine(a[i]); } ------------------------------------------- static void Main(string[] args) { int[] a ={6,4,2,0}; int i = 0; int tmp = 0; if (a[0] > a[1])
{
i = 2;
tmp = a[1];
a[i] = a[i+1];
a[i+1] = tmp;
}
for (i = 0; i <= 3;i++ ) Console.WriteLine(a[i]); } -------------------------------------------- static void Main(string[] args) { int[] a ={6,4,2,0}; int i = 0; int tmp = 0; for (i = 0; i <= 2; i++) { if (a[i] > a[i + 1])
{
tmp = a[i];
a[i] = a[i + 1];
a[i + 1] = tmp;
}
}
for (i = 0; i <= 3;i++ ) Console.WriteLine(a[i]); } ------------------------------------------ static void Main(string[] args) { int[] a ={6,4,2,0}; int i = 0; int tmp = 0; int k = 0; for (k = 1; k <= 3; k++) { for (i = 0; i <= 2; i++) { if (a[i] > a[i + 1])
{
tmp = a[i];
a[i] = a[i + 1];
a[i + 1] = tmp;
}
}
}
for (i = 0; i <= 3;i++ ) Console.WriteLine(a[i]); } ---------------------------------------------------------- 讓程式更有效率,減少不必要的運算。(下列數字由小排序到大) static void Main(string[] args) { int[] a ={5,14,12,6,8,4,1,18,11,9,3,2,7,15}; int i = 0; int tmp = 0; int k = 0; for (k = 0; k <= 12; k++) { for (i = 0; i <= 12-k; i++) { if (a[i] > a[i + 1])
{
tmp = a[i];
a[i] = a[i + 1];
a[i + 1] = tmp;
}
}
}
for (i = 0; i <= 13;i++ ) Console.WriteLine(a[i]); } ------------------------------------------------------------ static void Main(string[] args) { int [,] a=new int[,]{{0,1,2},{3,4,5}}; int [] b={0,0,0,0,0,0}; int i = 0,j=0,k=0,tmp= 0; int count = 0; while (count<=14) { count++; tmp = a[0, 0]; b[0] = tmp; Console.WriteLine(count); } -------------------------------------------------------------- ----------------------------------------------------------------------------- 第六週 2008/9/12 範例目標: 1.數一數 for (int i = 1; i < i =" i">
i=i+1; i+=1; i++;
------------------------------------------------------------------------------
int i = 0;
i = i + 1;
Console.WriteLine(i);
i += 1;
Console.WriteLine(i);
i++;
Console.WriteLine(i);
------------------------------------------------------------------------------
3.求和
sum=sum+x
------------------------------------------------------------------------------
int i = 0;
int sum = 0;
for (i = 0; i <= 10; i++) { Console.WriteLine("i={0}",i); sum = sum + i; Console.WriteLine("sum={0}",sum); } --------------------------- -------------------------------------------------- int i = 0; int s = 0; for (i = 1; i <= 10; i++) { s += i; Console.WriteLine("s={0}",s); } ---------------------------------------------------------------------------- int i = 0; int s = 0; int ai = 0; for (i = 1; i <= 5; i++) { ai = 4 + (i - 1) * 3; s = s + ai; Console.WriteLine("s={0}",s); } ----------------------------------------------------------------------------- 九九乘法表 int i, j; for (i = 1; i <= 9; i++) { for( j = 1; j <= 9; j++) { Console.WriteLine("i={0},j={1},i*j={2}", i,j,i*j); } } ----------------------------------------------------------------------------- P5-14第15題 int i, j; int s = 0; for (i = 1; i <= 9; i++) { for (j = 1; j <= 9; j++) { s+=(i+j); } } Console.WriteLine("s={0}", s); --------------------------------------------------------- 4. Game over --> while
---------------------------------------------------------
int i = 1000;
while (i > 0)
{
i--;
}
Console.WriteLine(i);
---------------------------------------------------------
int i = 0;
int sum = 0;
while (i <= 9) { i++; sum += i; Console.WriteLine("i={0},sum={1}",i,sum); } ------------------------------------------------------ P5-36 求積分 int i, n = 100; double s = 0; double ai=0; double a = 1; double b = 2; for (i = 1; i <= n; i++) { ai = (a + i * (b - a) / n) * ((b - a) / n); s = s + ai; Console.WriteLine(s); } ----------------------------------------------------------------------------- 第五週 2008/10/10 雙十節 第一週 2008/9/12 ---------------------------------------------------------------------------- 第二週 2008/9/19 http://www.powercam.cc/show.php?id=409
範例目標:
1.在記憶體中保留之空間給對應位置的變數.
2.利用終端機將一字串顯示出來
3.利用終端機將變數對應記憶體位置中的數字顯示出來
範例一
static void Main(string[] args)
{
//declare 在記憶體保留空間給變數a和b
int a,b;
a = 2; //將數字2放在記憶體中 a對應位置所保留之空間
b = 1;//將數字1放在記憶體中 b對應位置所保留之空間
Console.Write("a=");//將字串"a="輸出到終端機
Console.WriteLine(a);//將記憶體中 a對應位置所保留之空間內的數字輸出到終端機
Console.Write("b=");//將字串"b="輸出到終端機
Console.Write(b);//將記憶體中 b對應位置所保留之空間內的數字輸出到終端機
}
範例目標:
1.在記憶體中保留之空間給對應位置的變數.
2.利用終端機將鍵盤輸入到電腦的一字串顯示出來
3.利用終端機將變數對應記憶體位置中的數字顯示出來
範例二:
//declare 在記憶體保留空間給變數a和b
String a, b;
Console.Write("請輸入a");//提示語
a = Console.ReadLine();//將鍵盤的字元放入變數a所對應記憶體的空間內 Console.WriteLine("a={0:c}", a);//將字串"a="輸出到終端機及記憶體中 a對應位置所保留之空間內的數字輸出到終端機
Console.Write("請輸入b");//提示語
b = Console.ReadLine();//將鍵盤的字元放入變數b所對應記憶體的空間內
Console.Write("b={0:c}", b);//將字串"b="輸出到終端機及記憶體中 b對應位置所保留之空間內的數字輸出到終端機
----------------------------------------------------------------------------------------
課堂作業
輸入三角形三邊長a,b,c
計算三角形面積
輸出三角形面積結果
----------------------------------------------------------------------------

第三週 2008/9/26
http://www.powercam.cc/show.php?id=459

範例目標:
1.視窗程式顯示表單
2.提示文字所使用的物件 "Lable"標籤
3.輸入文字的物件"Textbox"文字方塊
4.製作物件"Button"按鈕並將指令程式放入其中
4.1.輸出文字到標籤
4.2.輸出文字到物件"MessageBox"對話框

MessageBox.Show("請按確定按鈕","標題");

課堂作業
1.利用表單及標籤和文字方塊
輸入三角形三邊長a,b,c

2.製作物件"Button"按鈕
並將"計算三角形面積"指令程式放入其中

3.輸出三角形面積結果 到標籤和對話框
-----------------------------------------------------------------------------
第四週 2008/10/03

範例目標:
一 了解電腦程式語言的決策指令 if
二 如果條件 (運算式)為真就執行敘述
if (運算式)
{
敘述區塊;
}
範例1
利用多個if 條件 (運算式)製作出可以依據鍵盤輸入判斷輸入值是否大於設定值:
例如
設定值為60
測試結果
1.若輸入1就顯示"不及格"
2.若輸入59就顯示"不及格"
3.若輸入60就顯示"及格"
4.若輸入61就顯示"及格"

範例2
利用多個if製作出可以依據鍵盤輸入不同而執行不同的敘述:
例如
輸入1就顯示"一"
輸入2就顯示"二"
輸入3就顯示"三"

三. 如果條件 (運算式)為真就執行 { 敘述區塊1; } 否則就執行 { 敘述區塊2; }
if (運算式)
{
敘述區塊1;
}
else
{
敘述區塊2;
}
四 將三中的敘述區塊2換成if (運算式) { 敘述區塊2; } else {敘述區塊3; }
if (運算式) { 敘述區塊1; }
else {

if (運算式)
{ 敘述區塊2; }
else {敘述區塊3; }

}
範例4 利用巢狀if else 製作出判斷成
績等級A(90-100),B(80-89),C(70-79),D(<70)


五. 利用切換開關的方式,依據運算式所算出的數值再選取不同 case 的敘述區塊來執行;
switch (運算式)
{
case 數值1
{
敘述區塊1;
break;
}
case 數值2
{
敘述區塊1;
break;
}

...
...

default:
{
敘述區塊;
break;
}

}

附註:
運算式若為字串型態的變數則可利用 case "字串" 選擇不同 情況來執行不同敘述區塊;
i=i+1

範例3

利用switch...case 製作出輪流明暗之紅綠燈

4. 例外處理
try
{
}
catch
{
}
catch
{
}
...
...
finally
{
}


課堂作業
1.利用表單及標籤和兩個文字方塊將輸入轉成實數a,b(雙精倍數)
2.製作物件"Button"按鈕四個來進行+,-,*,/四種運算,其運算元是a和b
3.利用例外處理處理除數為零的情況
4.輸出結果到標籤和對話框

74 則留言:

123 提到...
作者已經移除這則留言。
HPS 提到...

//第二週作業 d9539125
double a,b,c,d, e;//宣告在記憶體裡面保留三個位置給a,b,c
string s;
Console.Write("請輸入a的值:");
s = Console.ReadLine();
a = double.Parse(s);
Console.Write("請輸入b的值:");
s = Console.ReadLine();
b = double.Parse(s);
Console.Write("請輸入c的值:");
s = Console.ReadLine();
c = double.Parse(s);
d = (a + b + c)/2;//處理 process
e = d * (d - a) * (d - b) * (d - c);
Console.Write("a=");//把字串"a="輸出到終端機的畫面
Console.WriteLine(a);//把a變數對應到的記憶體位址的內容輸出到終端機的畫面
Console.Write("b=");//把字串"b="輸出到終端機的畫面
Console.WriteLine(b);//把b變數對應到的記憶體位址的內容輸出到終端機的畫面
Console.Write("c=");//把字串"c="輸出到終端機的畫面
Console.WriteLine(c);//把c變數對應到的記憶體位址的內容輸出到終端機的畫面
Console.Write("d=");//把字串"c="輸出到終端機的畫面
Console.WriteLine(d);//把c變數對應到的記憶體位址的內容輸出到終端機的畫面
Console.Write("三角形ABC面積為:");//把字串"c="輸出到終端機的畫面
Console.WriteLine(Math.Sqrt(e));//把c變數對應到的記憶體位址的內容輸出到終端機的畫面

HPS 提到...

//第三週作業 d9539125
string sa, sb, sc,sd;
double a, b, c, d, f;
sa = textBox1.Text;
sb = textBox2.Text;
sc = textBox3.Text;
label9.Text=sa;
label10.Text=sb;
label11.Text=sc;
a = double.Parse(sa);
b = double.Parse(sb);
c = double.Parse(sc);
d = (a + b + c)/2;
f=d*(d-a)*(d-b)*(d-c);
f=Math.Sqrt(f);
sd = string.Format("{0}", f);
label4.Text= sd;
MessageBox.Show("三角形ABC的面積=" + sd, "計算結果");

123 提到...

d9538922

第二週作業

double a, b, c, d,
e;//宣告abc三個變數
string s;
//a = 1;//在a對應的記憶體裡面放入1
//b = 2;//在b對應的記憶體裡面放入2
Console.Write("請輸入a:");
s = Console.ReadLine();
a = double.Parse(s);
Console.Write("請輸入b:");
s = Console.ReadLine();
b = double.Parse(s);
Console.Write("請輸入c:");
s = Console.ReadLine();
c = double.Parse(s);
d = (a + b + c) / 2;
e=d*(d-a)*(d-b)*(d-c);
//Console.Write(Math.Sqrt(e));//處理
process

//Console.Write("a=");//字串a=輸出到終端機的畫面

//Console.WriteLine(a);//把a對應到的記憶體位址的內容輸出到終端機的畫面

//Console.Write("b=");//字串b=輸出到終端機的畫面

//Console.WriteLine(b);//把b對應到的記憶體位址的內容輸出到終端機的畫面

Console.Write("則三角形的面積為:");//字串c=輸出到終端機的畫面

Console.WriteLine(Math.Sqrt(e));//把c對應到的記憶體位址的內容輸出到終端機的畫面

123 提到...

d9538922

第三週作業

string sa,sb,sc,sd;
double a,b,c,d,f,x;
sa = textBox1.Text;
sb = textBox2.Text;
sc = textBox3.Text;
label4.Text = sa;
label5.Text = sb;
label6.Text = sc;
a = double.Parse(sa);
b = double.Parse(sb);
c = double.Parse(sc);
d = (a + b + c) / 2;
f = d * (d - a) * (d - b) * (d - c);
x = Math.Sqrt(f);

sd=string.Format("三角形面積為{0}",x);
label7.Text = sd;
MessageBox.Show("三角形面積為"+sd,
"標題");

d9552566 提到...

第二週
double a , b , c , d , e, f, g , h,i;
string sa, sb, sc;
Console.Write("輸入a=");
sa = Console.ReadLine();
a = int.Parse(sa);
Console.Write("輸入b=");
sb = Console.ReadLine();
b = int.Parse(sb);
Console.Write("輸入c=");
sc = Console.ReadLine();
c = int.Parse(sc);
Console.WriteLine("求a,b,c為三邊的三角形面積");
d = (a + b + cf)/2;
e = d - a;
f = d - b;
g = d - c;
h=d*e*f*g;
i = Math.Sqrt(h);
Console.Write("面積為");
Console.WriteLine(i);
第三週
private void button1_Click(object sender, EventArgs e)
{
string sa, sb, sc,sd,sg;
int a, b, c,d,f;
double g;
sa = textBox1.Text;
sb = textBox2.Text;
sc = textBox3.Text;
label7.Text = sa;
label8.Text = sb;
label9.Text = sc;
a = int.Parse(sa);
b = int.Parse(sb);
c = int.Parse(sc);
d = a + b + c;
sd = string.Format("{0}", d);
label11.Text = sd;
f = d/2 * (d/2 - a) * (d/2 - b) * (d/2 - c);
g = Math.Sqrt(f);
sg = string.Format("{0}", g);
label13.Text = sg;
MessageBox.Show("三角形面積為"+sg,
"標題");

}

d9538905 提到...

D9538905
作業
***************第二周***************

int a, b, c;//宣告 ABC
double d,e;
string x,y,z;
Console.Write("請輸入a=");
x = Console.ReadLine();
a = int.Parse(x);//解析
Console.Write("請輸入b=");
y = Console.ReadLine();
b = int.Parse(y);
Console.Write("請輸入c=");
z = Console.ReadLine();
c = int.Parse(z);
d = (a + b + c ) / 2;
e = d * (d - a) * (d - b) * (d - c);
Console.Write("三角形面積=");//字串c=輸出到終端機
Console.WriteLine(Math.Sqrt(e));



***************第三周***************

String sa,sb,sc,se;
double a, b, c , d, f;
sa = textBox1.Text;
sb = textBox2.Text;
sc = textBox3.Text;
label9.Text = sa;
label10.Text = sb;
label11.Text = sc;
a = int.Parse(sa) ;
b = int.Parse(sb) ;
c = int.Parse(sc) ;
d = (a + b + c) / 2;
f = Math.Sqrt( d * (d - a) * (d - b) * (d - c));
se = string.Format("{0}", f);
label4.Text =se ;
MessageBox.Show( "三角形面積等於" + se ,"答案");

dragon 提到...

d9582608

第二週作業

string sa, sb, sc;
double a, b, c, d, e;
Console.Write("第一邊邊長=");
sa = Console.ReadLine();
Console.Write("第二邊邊長=");
sb = Console.ReadLine();
Console.Write("第三邊邊長=");
sc = Console.ReadLine();
a = int.Parse(sa);
b = int.Parse(sb);
c = int.Parse(sc);
d = (a + b + c) / 2;
e = Math.Sqrt(d * (d - a) * (d - b) * (d - c));
Console.WriteLine("三角形面積={0}", e);

dragon 提到...

d9582608

第三週作業

string sa,sb,sc,sd;
double a,b,c,d,x,f;
sa = textBox1.Text;
a = double.Parse(sa);
label7.Text = sa;
sb=textBox2.Text;
b=double.Parse(sb);
label8.Text = sb;
sc = textBox3.Text;
c = double.Parse(sc);
label9.Text = sc;
d = (a + b + c) / 2;
f=d*(d-a)*(d-b)*(d-c);
sd = string.Format("{0}", d);
label11.Text = sd;
x = Math.Sqrt(f);
MessageBox.Show("面積為"+sd,"標題");

dragon 提到...
作者已經移除這則留言。
dragon 提到...

d9582608

第四週作業

int a, b, c;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = a + b;
label1.Text = c.ToString();
}

private void button2_Click(object sender, EventArgs e)
{
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = a - b;
label1.Text = c.ToString();

}

private void button3_Click(object sender, EventArgs e)
{
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = a * b;
label1.Text = c.ToString();
}

private void button4_Click(object sender, EventArgs e)
{
try
{
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = a / b;
label1.Text = c.ToString();
}
catch(DivideByZeroException)
{
MessageBox.Show("除數不可為0");

}
catch(FormatException)
{

}
}

D9583066 提到...

第二週作業 D9583066

int b, a, c, s;
double z;
string aa, bb, cc;
Console.WriteLine("輸入三角形邊長a");
aa = Console.ReadLine();
a = int.Parse(aa);
Console.WriteLine("輸入三角形邊長b");
bb = Console.ReadLine();
b = int.Parse(bb);
Console.WriteLine("輸入三角形邊長c");
cc = Console.ReadLine();
c = int.Parse(cc);
s = (a + b + c) / 2;
z = Math.Sqrt(s * (s - a) * (s - b) * (s - c));
Console.Write("面積=");
Console.Write(z);

D9583066 提到...

第三週作業 D9583066

string aa,bb,cc,ss;
double s;
int a,b,c,d;
aa=textBox1.Text;
label9.Text=aa;
a = int.Parse(aa);
bb = textBox2.Text;
label10.Text = bb;
b=int.Parse(bb);
cc = textBox3.Text;
label11.Text = cc;
c = int.Parse(cc);
d=(a+b+c)/2;
s = Math.Sqrt(d * (d - a) * (d - b) * (d - c));
ss = string.Format("{0}", s);
label3.Text = ss;
MessageBox.Show(ss, "面積");

D9583066 提到...

第四週作業 D9583066

private void button1_Click(object sender, EventArgs e)
{
string aa, bb,ss;
double s;
int a, b;
aa = textBox1.Text;
a = int.Parse(aa);
bb = textBox2.Text;
b = int.Parse(bb);
s = a + b;
ss = string.Format("{0}", s);
MessageBox.Show(ss, "加");
}

private void button2_Click(object sender, EventArgs e)
{
string aa, bb, ss;
double s;
int a, b;
aa = textBox1.Text;
a = int.Parse(aa);
bb = textBox2.Text;
b = int.Parse(bb);
s = a - b;
ss = string.Format("{0}", s);
MessageBox.Show(ss, "減");
}

private void button3_Click(object sender, EventArgs e)
{
string aa, bb, ss;
double s;
int a, b;
aa = textBox1.Text;
a = int.Parse(aa);
bb = textBox2.Text;
b = int.Parse(bb);
s = a * b;
ss = string.Format("{0}", s);
MessageBox.Show(ss, "乘");
}

private void button4_Click(object sender, EventArgs e)
{
string aa, bb, ss;
double s;
int a, b;
try
{
aa = textBox1.Text;
a = int.Parse(aa);
bb = textBox2.Text;
b = int.Parse(bb);
s = a / b;
ss = string.Format("{0}", s);
MessageBox.Show(ss, "除");
}
catch (DivideByZeroException)
{
MessageBox.Show("除數為零", "除");
}
catch (FormatException)
{
MessageBox.Show("引數格式不和", "除");
}
}

匿名 提到...

d9582523

第三週作業

string sa, sb, sc, sd;
double a, b, c, d, f;
sa = textBox1.Text;
sb = textBox2.Text;
sc = textBox3.Text;

a = double.Parse(sa);
b = double.Parse(sb);
c = double.Parse(sc);
d = (a + b + c)/2;
f = d * (d - a) * (d - b) * (d - c);
f = Math.Sqrt(f);
sd = string.Format("{0}", f);
label7.Text = sd;
MessageBox.Show("面積為"+sd, "面積");

第四週作業

double a, b, c;
public Form1()
{
InitializeComponent();
}

private void button3_Click(object sender, EventArgs e)
{
a = double.Parse(textBox1.Text);
b = double.Parse(textBox2.Text);
c = a * b;
label1.Text = string.Format("{0}", c);
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
}

private void button1_Click(object sender, EventArgs e)
{
a = double.Parse(textBox1.Text);
b = double.Parse(textBox2.Text);
c = a + b;
label1.Text = string.Format("{0}", c);
}

private void button2_Click(object sender, EventArgs e)
{
a = double.Parse(textBox1.Text);
b = double.Parse(textBox2.Text);
c = a - b;
label1.Text = string.Format("{0}", c);
}

private void button4_Click(object sender, EventArgs e)
{
{
try
{
a = double.Parse(textBox1.Text);
b = double.Parse(textBox2.Text);
c = a / b;
label1.Text = string.Format("{0}", c);

}
catch (DivideByZeroException)
{

}
catch (FormatException)
{
MessageBox.Show("引數格式不對", "訊息");
}
}

}

HPS 提到...

//第四週作業 d9539125
double a, b, c;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
a = double.Parse(textBox1.Text);
b = double.Parse(textBox2.Text);
c = a + b;
label1.Text = string.Format("{0}", c);
}
private void button2_Click(object sender, EventArgs e)
{
a = double.Parse(textBox1.Text);
b = double.Parse(textBox2.Text);
c = a - b;
label1.Text = string.Format("{0}", c);
}
private void button3_Click(object sender, EventArgs e)
{
a = double.Parse(textBox1.Text);
b = double.Parse(textBox2.Text);
c = a * b;
label1.Text = string.Format("{0}", c);
}
private void button4_Click(object sender, EventArgs e)
{
try
{
a = double.Parse(textBox1.Text);
b = double.Parse(textBox2.Text);
c = a / b;
label1.Text = string.Format("{0}", c);
}
catch (DivideByZeroException)
{
MessageBox.Show("除數不可為0", "訊息");
}
catch (FormatException)
{
MessageBox.Show("引數格式不對", "訊息");
}
}

123 提到...

d9538922

第四週作業

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void label1_Click(object sender,
EventArgs e)
{
}

private void textBox1_TextChanged(object
sender, EventArgs e)
{

}

private void button1_Click(object sender,
EventArgs e)
{
string sa, sb, sc;
double a, b, c;
sa = textBox1.Text;
sb = textBox2.Text;
a = double.Parse(sa);
b = double.Parse(sb);
c = a + b;
sc = string.Format("a+b為{0}", c);
label3.Text = sc;

}

private void button2_Click(object sender,
EventArgs e)
{
string sa, sb, sc;
double a, b, c;
sa = textBox1.Text;
sb = textBox2.Text;
a = double.Parse(sa);
b = double.Parse(sb);
c = a - b;
sc = string.Format("a-b為{0}", c);
label3.Text = sc;

}

private void button3_Click(object sender,
EventArgs e)
{
string sa, sb, sc;
double a, b, c;
sa = textBox1.Text;
sb = textBox2.Text;
a = double.Parse(sa);
b = double.Parse(sb);
c = a * b;
sc = string.Format("a*b為{0}", c);
label3.Text = sc;
}

private void button4_Click(object sender,
EventArgs e)
{
string sa, sb, sc;
double a, b, c;
try
{
sa = textBox1.Text;
sb = textBox2.Text;
a = double.Parse(sa);
b = double.Parse(sb);
c = a / b;
sc = string.Format("a/b為{0}",
c);
label3.Text = sc;
}
catch (DivideByZeroException)
{
label3.Text = "除數為0";
}
catch (FormatException)
{

MessageBox.Show("引數格式不合","標題");
}

}
}
}

Unknown 提到...

第四週作業D9552566
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 加減乘除
{
public partial class Form1 : Form
{
string sa, sb;
string sc;
double a, b, c;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

sa = textBox1.Text;
sb = textBox2.Text;
a = double.Parse(sa);
b = double.Parse(sb);
c = a + b;
sc = string.Format("{0}", c);
label1.Text = sc;
MessageBox.Show(label1.Text);
}

private void button2_Click(object sender, EventArgs e)
{
sa = textBox1.Text;
sb = textBox2.Text;
a = double.Parse(sa);
b = double.Parse(sb);
c = a - b;
sc = string.Format("{0}", c);
label1.Text = sc;
MessageBox.Show(label1.Text);
}

private void button3_Click(object sender, EventArgs e)
{
sa = textBox1.Text;
sb = textBox2.Text;
a = double.Parse(sa);
b = double.Parse(sb);
c = a * b;
sc = string.Format("{0}", c);
label1.Text = sc;
MessageBox.Show(label1.Text);
}

private void button4_Click(object sender, EventArgs e)
{
sa = textBox1.Text;
sb = textBox2.Text;
a = double.Parse(sa);
b = double.Parse(sb);
if (b < 0|b>0 )
{
c = a / b;
sc = string.Format("{0}", c);
label1.Text = sc;
}
else
if(a>0)
label1.Text = "正無窮大";


else
if(a<0)
label1.Text = "負無窮大";

MessageBox.Show(label1.Text);
}
}
}

HPS 提到...

//第六週作業 d9539125
int i = 0, j = 0;
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= i; j++)
Console.Write(j + " ");
Console.WriteLine();
}
Console.WriteLine();
for (i = 1; i <= 5; i++)
{
for (j = 1; j < i; j++)
Console.Write(" ");
for (j = i; j <= 5; j++)
Console.Write(j + " ");
Console.WriteLine();
}

dragon 提到...

第六週
for (int i = 1; i <= 5; i++)
{
for (int j = 5 - i; j <= 5; j++)
Console.Write(" ");
{
for (int j = i; j <= 5; j++)
Console.Write(j+" ");
Console.WriteLine(" ");
}
}

牛奶糖 提到...

//第二週D9583079

int a, b, c, s ;
Double d;
string m, n, o;

Console.Write("請輸入a=");
m = Console.ReadLine();
a = int.Parse(m);


Console.Write("請輸入b=");
n = Console.ReadLine();
b = int.Parse(n);


Console.Write("請輸入c=");
o = Console.ReadLine();
c = int.Parse(o);


s = (a + b + c) / 2;

d = Math.Sqrt(s * (s - a) * (s - b) * (s - c));
Console.Write("三角形面積為");
Console.Write(d);

牛奶糖 提到...

//第三週 D9583079

string sa, sb, sc,sd;
int a, b, c,s;
Double d;

sa = textBox1.Text;
sb = textBox2.Text;
sc = textBox3.Text;
label5.Text = sa;
a = int.Parse(sa);
label7.Text = sb;
b = int.Parse(sb);
label9.Text = sc;
c = int.Parse(sc);
s = (a + b + c) / 2;
d = Math.Sqrt(s * (s - a) * (s - b) * (s - c));
sd = string.Format("{0}", d);
label11.Text = sd;
MessageBox.Show(sd, "三角形面積");

牛奶糖 提到...

//第四週 D9583079

private void button3_Click(object sender, EventArgs e)
{
int a, b;
string sa, sb, sc;
double d;


sa = textBox1.Text;
a = int.Parse(sa);
sb = textBox2.Text;
b = int.Parse(sb);

d = a * b;
sc = string.Format("{0}", d);
MessageBox.Show(sc);


}

private void label1_Click(object sender, EventArgs e)
{


}

private void button1_Click(object sender, EventArgs e)
{
int a, b;
string sa, sb, sc;
double d;


sa = textBox1.Text;
a = int.Parse(sa);
sb = textBox2.Text;
b = int.Parse(sb);

d= a + b;

sc = string.Format("{0}", d);
MessageBox.Show(sc);


}

private void button4_Click(object sender, EventArgs e)
{
int a, b;
string sa, sb,sc;
double d;
try
{
sa = textBox1.Text;
a = int.Parse(sa);
sb = textBox2.Text;
b = int.Parse(sb);

d = a / b;
sc = string.Format("{0}", d);
MessageBox.Show(sc);
}
catch (DivideByZeroException)
{
MessageBox.Show("除數為零", "除數為零");
}

}

private void button2_Click(object sender, EventArgs e)
{
int a, b;
string sa, sb, sc;
double d;


sa = textBox1.Text;
a = int.Parse(sa);
sb = textBox2.Text;
b = int.Parse(sb);

d = a - b;
sc = string.Format("{0}", d);
MessageBox.Show(sc);


}

123 提到...
作者已經移除這則留言。
123 提到...

第六週作業
D9538922

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int i, j;
for (i = 1; i <= 5; i++)
{

for (j = 1; j <= i; j++)
{
Console.Write(j);
}
Console.WriteLine();
}
Console.WriteLine();
for(i=1;i<=5;i++)
{
for (j = 1; j <= i; j++)
{
Console.Write(" ");
}
for (j = i; j <=5 ; j++)
{
Console.Write(j+" ");
}

Console.WriteLine();
}
}
}
}

Unknown 提到...

第七週D9552566楊明鑫
第一題
int i,j;
for (i = 1; i<=5; i++)
{

for (j = 1; j <= i ; j++)
{ Console.Write(j);
Console.Write(" ");
} Console.WriteLine("");
第二題
int i, j,k;


for (i = 1; i <= 5; i++)
{

for (j = i; j <= 5; j++)
{

Console.Write(j);
Console.Write(" ");
} Console.WriteLine("");
for (k = 1; k <= i; k++)
{
Console.Write(" ");
}
}

D9583066 提到...

第六週作業 D9583066


int a, b;
for (a = 1; a <= 5; a++)
{
for (b = 1; b <= a; b++)
Console.Write(b+" ");
Console.WriteLine();
}
Console.WriteLine();
int i, j;
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= i; j++)
{
Console.Write(" ");
}
for (j = i; j <= 5; j++)
{
Console.Write(j + " ");
}
Console.WriteLine();
}

匿名 提到...

第六週作業
d9582523


int i;
int j;
for (i = 1; i <=5 ; i +=1)
{
for (j = 1; j <=i; j+=1)
{
Console.Write(j+" ");
}
Console.WriteLine();
}
Console.WriteLine();
for (i = 1; i <= 5; i += 1)
{
for (j = 1; j < i; j += 1)
{
Console.Write(" ");
}
for (j = i; j <= 5; j += 1)
Console.Write(j + " ");
Console.WriteLine();
}

d9538905 提到...

-----------------------------第四周作業-----------------------------
int a, b, c;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = a + b;
label1.Text = c.ToString();
}

private void button2_Click(object sender, EventArgs e)
{
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = a - b;
label1.Text = c.ToString();

}

private void button3_Click(object sender, EventArgs e)
{
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = a * b;
label1.Text = c.ToString();
}

private void button4_Click(object sender, EventArgs e)
{
try
{
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = a / b;
label1.Text = c.ToString();
}
catch(DivideByZeroException)
{
MessageBox.Show("除數不能為0");

}
catch(FormatException)
{

}
}


-----------------------------第六周作業-----------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j;
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= i; j++)
{
Console.Write(j);
Console.Write(" ");
}
Console.WriteLine();
}
Console.WriteLine();
for (i = 1; i <= 5; i++)
{
for (j = 1; j < i; j++)
Console.Write(" ");
for (j = i; j <= 5; j++)
{
Console.Write(j);
Console.Write(" ");
}
Console.WriteLine();
}
}
}
}

123 提到...

第七週作業 D9538922

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
int[,] a = new int[,] { { 1, 2, 3, 4,
5 },
{ 10, 9, 8,
7, 6 },
{
11,12,13,14,15 } };
int []b=new int[15];
int i = 0, j = 0, k = 0;
for (i = 0; i < 3; i++)
{
if (i == 0)
{
for (j = 0; j < 5; j++)
{

b[k] = a[i, j];
Console.WriteLine(b[k]);
}
}
if (i == 1)
{
for (j = 4; j >= 0; j--)
{
b[k] = a[i, j];
Console.WriteLine(b[k]);
}
}
if (i == 2)
{
for (j = 0; j < 5; j++)
{
b[k] = a[i, j];
Console.WriteLine(b[k]);
}
}
}
}
}
}

D9583066 提到...

第六週作業 D9583066


int a, b;
for (a = 1; a <= 5; a++)
{
for (b = 1; b <= a; b++)
Console.Write(b+" ");
Console.WriteLine();
}
Console.WriteLine();
int i, j;
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= i; j++)
{
Console.Write(" ");
}
for (j = i; j <= 5; j++)
{
Console.Write(j + " ");

}
Console.WriteLine();
}

D9583066 提到...

第七週作業 D9583066

int[,] a = new int[,] { { 1, 2, 3, 4, 5 }, { 10, 9, 8, 7, 6 }, {11,12,13,14,15 } };
int[] b = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int i=0,j=0,k=0;
for (i = 0; i < 1; i++)
{
for (j = 0; j < 5;j++ )

{
b[k] = a[i, j];
Console.WriteLine(b[k]);
}
}
for (i = 1; i < 2;i++ )
{
for (j = 4; j >=0;j-- )
{
b[k]=a[i,j];
Console.WriteLine(b[k]);
}
}
for (i = 2; i < 3;i++ )
{
for (j = 0; j < 5;j++ )
{
b[k] = a[i, j];
Console.WriteLine(b[k]);
}
}

HPS 提到...

//第七週作業 d9539125
int i = 0, j = 0, k = 0;
int[] b = new int[15];
int[,] a =new int[,] { { 1, 2, 3, 4, 5 }, { 10, 9, 8, 7, 6 }, { 11, 12, 13, 14, 15 } };
for (i = 0; i < 3; i++)
{
if (((i+1) % 2) == 0)
{
for (j = 4; j >= 0; j--)
{
b[k] = a[i, j];
k++;
}
}
else
{
for (j = 0; j < 5; j++)
{
b[k] = a[i, j];
k++;
}
}
}
for (k = 0; k < 15;k++ )
Console.WriteLine(b[k]);

Unknown 提到...

1

Unknown 提到...

第七週作業D9552566
int[,] a ={ { 1, 2, 3,4,5 }, { 10,9,8,7,6 }, { 11,12,13,14,15} };
int[] b ={ 0 ,1,2,3,4,5,6,7,8,9,10,11,12,13,14};
int temp,i,j,k,m;

for (i = 0; i <= 2; i++)
{
for (j = 0; j <= 4; j++)
{
b[5*i+j] = a[i, j];
}

} for (m = 0; m < 15; m++)
{
for (k = 0; k < 14; k++)
{
if (b[k] > b[k + 1])
{
temp = b[k];
b[k] = b[k + 1];
b[k + 1] = temp;
}

}Console.WriteLine("{0} ", b[m]);
}

123 提到...

第八週作業 D9538922

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
int[,] a ={ { 1, 2, 3, 4 }, { 8, 7,
6, 5 }, { 9, 10, 11, 12 }, { 16, 15, 14, 13 } };
int []b=new int[16];
b=work(a);
int i=0;
for (i = 0; i <= 15; i++)
Console.WriteLine(b[i]);
}
static int[] work(int [,]a)
{
int[] b = new int[16];
int i=0,j=0,k=0;
for (i = 0; i <= 3; i++)
{
switch (i % 2)
{
case 0:
for (j = 0; j <= 3; j++)
{
b[k] = a[j, i];
k++;
}
break;
case 1:
for (j = 3; j >= 0; j--)
{
b[k] = a[j, i];
k++;
}
break;
}

}
return (b);
}
}
}

HPS 提到...
作者已經移除這則留言。
HPS 提到...

//第九週作業 d9539125
static void Main(string[] args)
{
int[,] a ={ { 1, 2, 3, 4 }, { 8, 7, 6, 5 }, { 9, 10, 11, 12 }, { 16, 15, 14, 13 } };
int[] b = new int[16];
b = work(a);
for (int i = 0; i < 16; i++)
Console.Write(b[i]+" ");
Console.WriteLine();
}
static int[] work(int[,] a)
{
int i = 0, k = 0, j = 0;
int[] b = new int[16];
for (j = 0; j < 4; j++)
{
if (j % 2 == 0)//奇數列
{
for (i = 0; i <= 3; i++)
{
b[k] = a[i, j];
k++;
}
}
else //偶數列
{
for (i = 3; i >= 0; i--)
{
b[k] = a[i, j];
k++;
}
}
}
return (b);
}

匿名 提到...
作者已經移除這則留言。
匿名 提到...

第七週 d9582523


int i = 0, j = 0, k = 0;
int[] b = new int[15];
int[,] a =new int[,] { { 1, 2, 3, 4, 5 }, { 10, 9, 8, 7, 6 }, { 11, 12, 13, 14, 15 } };
for (i = 0; i < 3; i++)
{
if (((i+1) % 2) == 0)
{
for (j = 4; j >= 0; j--)
{
b[k] = a[i, j];
k++;
}
}
else
{
for (j = 0; j < 5; j++)
{
b[k] = a[i, j];
k++;
}
}
}
for (k = 0; k < 15;k++ )
Console.WriteLine(b[k]);

匿名 提到...

第九週 d9582523
static void Main(string[] args)
{
int[,] a ={ { 1, 2, 3, 4 }, { 8, 7, 6, 5 }, { 9, 10, 11, 12 }, { 16, 15, 14, 13 } };
int[] b ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

b=work(a);
for (int i = 0; i <= 15;i++ )
Console.Write(b[i]);

}
static int[] work(int[,] a)
{
int[] b ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int i = 0,k = 0;
for (i = 0; i <= 3;i++ )
{
if( i%2== 0)
{
for (int j = 0; j <= 3; j++)
{
b[k] = a[j, i];
k++;
}
}
if (i%2 == 1)
{
for (int j = 3; j >= 0; j--)
{
b[k] = a[j, i];
k++;
}
}

}
return (b);
}

Unknown 提到...

第九週作業 D9552566 楊明鑫
for (i = 0; i <= 3; i++)
{
for (j = 0; j <= 3; j++)
{
Console.WriteLine(a[j+(3-2*j)*(i%2),i+(3-2*i)*((j+(3-2*j)*(i%2))%2)]);
}
}

匿名 提到...

第十週 d9582523
class MyMain
{
static void Main(string[] args)
{
CRectangle rect = new CRectangle();
int result, result_parimeter;
rect.height = 10;
rect.width = 5;
result = rect.compute_area();
result_parimeter = rect.compute_parimeter();
Console.WriteLine("result=" + result);
Console.WriteLine("result_perimeter=" + result_parimeter);
rect.height = 20;
rect.width = 10;
result = rect.compute_area();
result_parimeter = rect.compute_parimeter();
Console.WriteLine("result=" + result);
Console.WriteLine("result_parimeter=" + result_parimeter);
rect.height = 30;
rect.width = 15;
result = rect.compute_area();
result_parimeter = rect.compute_parimeter();
Console.WriteLine("result=" + result);
Console.WriteLine("result_parimeter=" + result_parimeter);
rect.r = 5;
result = rect.r_area();
result_parimeter = rect.r_parimeter();
Console.WriteLine("r=" + rect.r);
Console.WriteLine("area=" + result);
Console.WriteLine("parimeter=" + result_parimeter);
rect.r = 10;
result = rect.r_area();
result_parimeter = rect.r_parimeter();
Console.WriteLine("r=" + rect.r);
Console.WriteLine("area=" + result);
Console.WriteLine("parimeter=" + result_parimeter);
rect.r = 15;
result = rect.r_area();
result_parimeter = rect.r_parimeter();
Console.WriteLine("r=" + rect.r);
Console.WriteLine("area=" + result);
Console.WriteLine("parimeter=" + result_parimeter);
}
}
class CRectangle
{
public int width;
public int height;
public int r;
public int compute_area()
{
int area = width * height;
return area;
}
public int compute_parimeter()
{
int parimeter;
parimeter = 2 * (width + height);
return parimeter;
}
public int r_area()
{
int area = r * r * 3;
return area;
}
public int r_parimeter()
{
int parimeter;
parimeter = 2 * 3 * r;
return parimeter;
}


}

Unknown 提到...

第十週作業D9552566楊明鑫
class MyMain
{
static void Main(string[] args)
{

CRectangle rect = new CRectangle();
rect.width = 5;
rect.height = 10;
Console.WriteLine("長=" + rect.width);
Console.WriteLine("寬=" + rect.height);
Console.WriteLine("面積=" + rect.A());
Console.WriteLine("周長=" + rect.P());
Console.WriteLine();
rect.width = 10;
rect.height = 20;
Console.WriteLine("長=" + rect.width);
Console.WriteLine("寬=" + rect.height);
Console.WriteLine("面積=" + rect.A());
Console.WriteLine("周長=" + rect.P());
Console.WriteLine();
rect.width = 15;
rect.height = 30;
Console.WriteLine("長=" + rect.width);
Console.WriteLine("寬=" + rect.height);
Console.WriteLine("面積=" + rect.A());
Console.WriteLine("周長=" + rect.P());
Console.WriteLine();
rect.r = 5;
Console.WriteLine("半徑=" + rect.r);
Console.WriteLine("圓面積=" + rect.OA());
Console.WriteLine("圓周長=" + rect.OP());
Console.WriteLine();
rect.r = 10;
Console.WriteLine("半徑=" + rect.r);
Console.WriteLine("圓面積=" + rect.OA());
Console.WriteLine("圓周長=" + rect.OP());
Console.WriteLine();
rect.r = 15;
Console.WriteLine("半徑=" + rect.r);
Console.WriteLine("圓面積=" + rect.OA());
Console.WriteLine("圓周長=" + rect.OP());
Console.WriteLine();

}
}
class CRectangle
{
public int width;
public int r;
public int height;

public double A()
{
double area;
area = width * height;
return area;
}
public double P()
{
double s;
s = 2 * (width + height);
return s;
}
public double OA()
{
double areatwo;
areatwo = r * r * Math.PI;
return areatwo;
}
public double OP()
{
double stwo;
stwo = 2 * r * Math.PI;
return stwo;
}
}

d9538905 提到...

D9538905
第十週作業

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication12
{
class MyMain
{
static void Main(string[] args)
{
double result, result_parimeter;
double r,width,height;
CRectangle rect = new CRectangle();
rect.r = 5;
r = 5;
Console.WriteLine("半徑等於" + r);
result = rect.compute_aarea();
Console.WriteLine("面積等於"+result);
result_parimeter = rect.compute_aparimeter();
Console.WriteLine("周長等於"+result_parimeter);
Console.WriteLine(" ");
rect.r = 10;
r = 10;
Console.WriteLine("半徑等於" + r);
result = rect.compute_aarea();
Console.WriteLine("面積等於" + result);
result_parimeter = rect.compute_aparimeter();
Console.WriteLine("周長等於" + result_parimeter);
Console.WriteLine(" ");
rect.r = 15;
r = 15;
Console.WriteLine("半徑等於" + r);
result = rect.compute_aarea();
Console.WriteLine("面積等於" + result);
result_parimeter = rect.compute_aparimeter();
Console.WriteLine("周長等於" + result_parimeter);
Console.WriteLine(" ");
rect.width = 10;
rect.height=5;
width = 10;
height = 5;
Console.Write("長" + width);
Console.WriteLine(" 寬" + height);
result = rect.compute_area();
Console.WriteLine("面積等於" + result);
result_parimeter = rect.compute_parimeter();
Console.WriteLine("周長等於" + result_parimeter);
Console.WriteLine(" ");
rect.width = 20;
rect.height = 10;
width = 20;
height = 10;
Console.Write("長" + width);
Console.WriteLine(" 寬" + height);
result = rect.compute_area();
Console.WriteLine("面積等於" + result);
result_parimeter = rect.compute_parimeter();
Console.WriteLine("周長等於" + result_parimeter);
Console.WriteLine(" ");
rect.width = 30;
rect.height = 15;
width = 30;
height = 15;
Console.Write("長" + width);
Console.WriteLine(" 寬" + height);
result = rect.compute_area();
Console.WriteLine("面積等於" + result);
result_parimeter = rect.compute_parimeter();
Console.WriteLine("周長等於" + result_parimeter);
Console.WriteLine(" ");

}
}
class CRectangle
{
public double r;
public double width;
public double height;
public double compute_aarea()
{
double aarea;
aarea = r*r*3;
return aarea;
}
public double compute_aparimeter()
{
double aparimeter;
aparimeter = 2 * r * 3;
return aparimeter;
}
public double compute_area()
{
double area;
area = width * height;
return area;
}
public double compute_parimeter()
{
double parimeter;
parimeter = 2*(width + height);
return parimeter;
}

}

}

123 提到...

第十週作業
D9538922

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication8
{
class Mymain
{
static void Main(string[] args)
{
int width, height;
double area, perimeter;
CCircle cir = new CCircle();
cir.radius = 5;
area = cir.compute_area();
perimeter = cir.compute_parimeter();
Console.WriteLine("radius=" + cir.radius);
Console.WriteLine("area=" + area);
Console.WriteLine("perimeter=" + perimeter);
Console.WriteLine();
cir.radius = 10;
area = cir.compute_area();
perimeter = cir.compute_parimeter();
Console.WriteLine("radius=" + cir.radius);
Console.WriteLine("area=" + area);
Console.WriteLine("perimeter=" + perimeter);
Console.WriteLine();
cir.radius = 15;
area = cir.compute_area();
perimeter = cir.compute_parimeter();
Console.WriteLine("radius=" + cir.radius);
Console.WriteLine("area=" + area);
Console.WriteLine("perimeter=" + perimeter);
Console.WriteLine();

int result, result_perimeter;
CRectangle rect = new CRectangle();
rect.width = 10;
rect.height = 5;
result = rect.compute_area1();
Console.WriteLine("width=" + rect.width + ", height=" + rect.height);
Console.WriteLine("result_area=" + result);
result_perimeter = rect.compute_parimeter();
Console.WriteLine("result_perimeter=" + result_perimeter);
Console.WriteLine();
rect.width = 20;
rect.height = 10;
result = rect.compute_area1();
Console.WriteLine("width=" + rect.width + ", height=" + rect.height);
Console.WriteLine("result_area=" + result);
result_perimeter = rect.compute_parimeter();
Console.WriteLine("result_perimeter=" + result_perimeter);
Console.WriteLine();
rect.width = 30;
rect.height = 15;
result = rect.compute_area1();
Console.WriteLine("width=" + rect.width + ", height=" + rect.height);
Console.WriteLine("result_area=" + result);
result_perimeter = rect.compute_parimeter();
Console.WriteLine("result_perimeter=" + result_perimeter);
Console.WriteLine();


}

dragon 提到...

第11週作業 d9582608
class Mymain
{
static void Main(string[]args)
{
double no;
poke result = new poke();
no = result.no();
Console.WriteLine(no);
}
}
public class poke
{
public double no()
{
Random r = new Random();
int no = r.Next(1, 14);
int color = r.Next(1, 5);
switch (color)
{
case 1:
Console.WriteLine("黑桃");
break;
case 2:
Console.WriteLine("紅心");
break;
case 3:
Console.WriteLine("方塊");
break;
case 4:
Console.WriteLine("梅花");
break;
}
return (no);
}
}

d9538905 提到...

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication13
{
class Mymain
{
static void Main(string[] args)
{
string pork = " ";
int numb = 0;
Pork a = new Pork();
pork = a.Color("");
numb = a.No(0);
Console.WriteLine(pork + numb);
}
}
public class Pork
{
public int No(int m)
{
Random r = new Random();
int no = r.Next(1, 14);
return (no);
}
public string Color(string n)
{
Random s = new Random();
int color = s.Next(1, 5);
String color_1 = "";
switch (color)
{
case 1:
color_1 = "黑桃";
break;
case 2:
color_1 = "紅心";
break;
case 3:
color_1 = "方塊";
break;
case 4:
color_1 = "梅花";
break;
}
return (color_1);

}
}

}

Unknown 提到...
作者已經移除這則留言。
123 提到...

第11週作業
D9538922

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication13
{
class Mymain
{
static void Main(string[] args)
{
Poke poke = new Poke();
int color = poke.poke_give();
int no = poke.number();
Console.WriteLine("color=" + color+
"number=" + no);
}
class Poke
{
public int poke_give()
{
Random r = new Random();
int color = r.Next(1, 5);
switch (color)
{
case 1:
Console.WriteLine("黑桃");
break;
case 2:
Console.WriteLine("紅心");
break;
case 3:
Console.WriteLine("方塊");
break;
case 4:
Console.WriteLine("梅花");
break;
}
return color;
}
public int number()
{
Random r = new Random();
int number = r.Next(1, 14);
return number;
}
}

}




}

Unknown 提到...

第十一週作業D9552566楊明鑫

XXx xx = new XXx();
Random r = new Random();
xx.a = r.Next(53);

switch (xx.Y())
{
case 1:
Console.Write("黑桃");
break;

case 2:
Console.Write("紅心");

break;

case 3:
Console.Write("方塊");
break;

case 4:
Console.Write("梅花");
break;
}
Console.WriteLine(xx.X());
}
}
public class XXx
{
public double a, b,d;
public int c;
public double X()
{

b = Math.Ceiling(a / 13);
d = a - 13 * b + 13;
return d;
}
public int Y()
{

b = Math.Ceiling(a / 13);
c = (int)b;

return c;
}

HPS 提到...
作者已經移除這則留言。
HPS 提到...

//第十一週作業 d9539125
class Peisyun
{
static void Main(string[] args)
{
int i = 0;
Poke pkgive = new Poke();
string pkend = " ";
for (i = 0; i < 5; i++)
{
pkend = pkgive.poke_give();
Console.WriteLine(pkend);
}
Console.WriteLine();
}
}
class Poke
{
public int num, clr;
public string clr_s = " ";
bool[,] a = new bool[4, 13];
public Poke()
{
int i = 0, j = 0;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 13; j++)
{
a[i, j] = false;
}
}
}
public string poke_give()
{
string result = "";
clr_num();
while (a[clr, num] == true)
{
clr_num();
}
a[clr, num] = true;

result = string.Format(clr_s + " " + (num + 1));
return result;
}
void clr_num()
{
Random rn = new Random();
num = rn.Next(0, 13);
clr = rn.Next(0, 4);
switch (clr)
{
case 0:
clr_s = "黑桃";
break;
case 1:
clr_s = "紅心";
break;
case 2:
clr_s = "方塊";
break;
case 3:
clr_s = "梅花";
break;
}
}
}

d9538905 提到...

d9538905
第12週作業

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication6
{
public partial class Form1 : Form
{
int no1, no2, no3, no4;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
Ngame nom = new Ngame();
textBox1.Text = "" + nom.no1 + nom.no2 + nom.no3 + nom.no4;
no1 = nom.no1;
no2 = nom.no2;
no3 = nom.no3;
no4 = nom.no4;

}

private void button2_Click(object sender, EventArgs e)
{
Ngame nom = new Ngame();
double g1,a, b, c, d;
string g;
int oa = 0;
int ob = 0;
g = textBox2.Text;
g1 = int.Parse(g);
d = g1 % 10;
c = ((g1 - d) % 100) / 10;
b = ((g1 - c * 10 - d) % 1000) / 100;
a = (g1 - b * 100 - c * 10 - d) / 1000;
if (a == no1)
oa++;
if (a == no2 || a == no3 || a == no4)
{
ob++;
}
if (b == no2)
{
oa++;
}
if (b == no1 || b == no3 || b == no4)
{
ob++;
}
if (c == no3)
{
oa++;
}
if (c == no1 || c == no2 || c == no4)
{
ob++;
}
if (d == no4)
{
oa++;
}
if (d == no1 || d == no2 || d == no3)
{
ob++;
}
label4.Text = " " + oa;
label5.Text = " " + ob;
if (oa == 4)
{
MessageBox.Show("答案正確", "恭喜");
}


}
}
public class Ngame
{
public int no1, no2, no3, no4;
public Ngame()
{

Random r = new Random();
no1 = r.Next(0, 10);
no2 = r.Next(0, 10);
while (no1 == no2)
no2 = r.Next(0, 10);
no3 = r.Next(0, 10);
while (no1 == no3||no2==no3)
no3 = r.Next(0, 10);
no4 = r.Next(0, 10);
while (no4 == no1 || no4 == no2 || no4 == no3)
no4 = r.Next(0, 10);
}
}
}

Unknown 提到...

第十二週作業D9552566楊明鑫
private void button1_Click(object sender, EventArgs e)
{

Ngame a=new Ngame();
label1.Text=""+a.no1+a.no2+a.no3+a.no4;
int []c = new int[4];
c[0] = int.Parse(textBox1.Text);
c[1] = int.Parse(textBox2.Text);
c[2] = int.Parse(textBox3.Text);
c[3] = int.Parse(textBox4.Text);
int[] b = new int[4];
b[0] = a.no1;
b[1] = a.no2;
b[2] = a.no3;
b[3] = a.no4;
int i, j,f=0,g=0,h;
for (i = 0; i <= 3; i++)
for (j = 0; j <= 3; j++)
if (c[i] == b[j])
f++;

for (i = 0; i <= 3; i++)
if (c[i] == b[i])
g++;
h = f - g;
label2.Text = "" +h;
label5.Text = "" + g;

}
public class Ngame
{
public int no1, no2, no3, no4;
public Ngame()
{
Random r = new Random();
no1=r.Next(0,10);
no2=r.Next(0,10);
while (no1 == no2)
{ no2 = r.Next(0, 10); }
no3=r.Next(0,10);
while (no1 == no3 | no2 == no3)
{ no3 = r.Next(0, 10); }
no4=r.Next(0,10);
while (no4 == no1 | no4 == no2|no4==no3)
{ no4 = r.Next(0, 10); }
}
}

d9538905 提到...

D9538905 第13週作業

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;


namespace WindowsApplication7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int c;
ArrayList a = new ArrayList(9);
Random r = new Random();
for (int i = 0; i < 10; i++)
a.Add(i);
string s = "";
for (int i = 0; i < 4; i++)
{
c = r.Next(a.Count);
s=s+a[c];
a.RemoveAt(c);
}
label2.Text = s;

}
}
}

Unknown 提到...

第十三週作業 D9552566 楊明鑫
int i,c;
string s = "";
ArrayList b = new ArrayList(9);

for ( i = 0; i <= 9; i++)
{
b.Add(i); Console.WriteLine(b[i]);
}
Random r = new Random();
for (i = 0; i <= 3; i++)
{
c = r.Next(i, b.Count);
s = s + b[c];
label1.Text = s;
b.RemoveAt(c);
}

123 提到...

第13週作業
D9538922

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;


namespace WindowsApplication17
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int c,i;
string s="";
ArrayList b = new ArrayList(10);
Random r = new Random();

for (i = 0; i <= 9; i++)
{
b.Add(i);
}
for (i = 0; i <= 3; i++)
{
c = r.Next(b.Count);
s = s + b[c];
b.RemoveAt(c);
label2.Text = "" + s;
}

}
}
}

HPS 提到...

//第十二週作業 d9539125
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication5
{
public partial class Form1 : Form
{
int[] aa = new int[4];
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Ngame no = new Ngame();
label2.Text= " "+no.no4 + no.no3 + no.no2 + no.no1;
aa[0] = no.no1;
aa[1] = no.no2;
aa[2] = no.no3;
aa[3] = no.no4;
button2.Enabled = true;
button1.Text = "重新開始";
}

private void button2_Click(object sender, EventArgs e)
{
int[] a = new int[4];
int count_a = 0, count_b = 0;
int in_num = int.Parse(textBox1.Text);
a[0] = in_num % 10;
a[1] = ((in_num % 100) - a[0])/10;
a[2] = ((in_num % 1000) - a[0] - a[1] * 10)/100;
a[3] = (in_num - a[0] - a[1] * 10 - a[2] * 100)/1000;
for (int i = 0; i < 4; i++)
{
if (a[i] == aa[i])
count_a++;
else
{
for (int j = 0; j < 4; j++)
{
if (a[i] == aa[j])
count_b++;
}
}
}
label3.Text = "結果:" + count_a + "A" + count_b + "B";
if (count_a == 4)
{
label2.Visible = true;
button2.Enabled = false;
MessageBox.Show("正確答案", "訊息");
}
}
}
public class Ngame
{
public int no1, no2, no3, no4;
public Ngame()
{
Random r_no = new Random();
no1 = r_no.Next(0, 10);
no2 = r_no.Next(0, 10);
no3 = r_no.Next(0, 10);
no4 = r_no.Next(0, 10);
while (no1 == no2 || no1 == no3 || no1 == no4 || no2 == no3 || no2 == no4 || no3 == no4)
{
no1 = r_no.Next(0, 10);
no2 = r_no.Next(0, 10);
no3 = r_no.Next(0, 10);
no4 = r_no.Next(0, 10);
}
}
}
}

HPS 提到...

//第十三週作業 d9539125
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace WindowsApplication5
{
public partial class Form1 : Form
{
int[] aa = new int[4];
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Ngame no = new Ngame();
label2.Text= " "+no.c_no[3] + no.c_no[2] + no.c_no[1] + no.c_no[0];
aa[0] = int.Parse(no.c_no[0]);
aa[1] = int.Parse(no.c_no[1]);
aa[2] = int.Parse(no.c_no[2]);
aa[3] = int.Parse(no.c_no[3]);
button2.Enabled = true;
button1.Text = "重新開始";
}

private void button2_Click(object sender, EventArgs e)
{
int[] a = new int[4];
int count_a = 0, count_b = 0;
int in_num = int.Parse(textBox1.Text);
a[0] = in_num % 10;
a[1] = ((in_num % 100) - a[0])/10;
a[2] = ((in_num % 1000) - a[0] - a[1] * 10)/100;
a[3] = (in_num - a[0] - a[1] * 10 - a[2] * 100)/1000;
for (int i = 0; i < 4; i++)
{
if (a[i] == aa[i])
count_a++;
else
{
for (int j = 0; j < 4; j++)
{
if (a[i] == aa[j])
count_b++;
}
}
}
label3.Text = "結果:" + count_a + "A" + count_b + "B";
if (count_a == 4)
{
label2.Visible = true;
button2.Enabled = false;
MessageBox.Show("正確答案", "訊息");
}
}
}
public class Ngame
{
public string[] c_no=new string [4];

ArrayList arrray = new ArrayList();
public Ngame()
{
int j = 0;
Random r_no = new Random();
for (int i = 0; i < 10; i++)
arrray.Add(i);
for (int i = 0; i < 4; i++)
{
j = r_no.Next(arrray.Count);
c_no[i] = c_no[i] + arrray[j];
arrray.RemoveAt(j);
}
}
}
}

D9583066 提到...

第九週作業 D9583066

static void Main(string[] args)
{
int[,] d ={ { 1, 2, 3, 4 }, { 8, 7, 6, 5 }, { 9, 10, 11, 12 }, { 16, 15, 14, 13 } };
int[] c ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int i = 0;
c = work(d);
for (i = 0; i <= 15; i++)
Console.WriteLine(c[i]);

}
static int[] work(int [,]a)
{
int[] b ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int i = 0, j = 0, k = 0;
for (j = 0; j <= 3; j++)
{
if (j%2 == 0)
{
for (i = 0; i <= 3; i++)
{
b[k] = a[i, j];
k++;
}
}
if (j%2 == 1)
{
for (i = 3; i >= 0; i--)
{
b[k] = a[i, j];
k++;
}
}
}
return (b);
}

D9583066 提到...

第十週作業 D9583066

namespace ConsoleApplication12
{
class Mymain
{
static void Main(string[] args)
{
int result,zero_result;
int pp,zero_p;
CR r = new CR();
r.width = 10;
r.height = 5;
result = r.compute_area();
pp = r.computer_p();
Console.WriteLine("result=" + result);
Console.WriteLine("PP=" + pp);
r.width = 20;
r.height = 10;
result = r.compute_area();
pp = r.computer_p();
Console.WriteLine("result=" + result);
Console.WriteLine("PP=" + pp);
r.width = 30;
r.height = 15;
result = r.compute_area();
pp = r.computer_p();
Console.WriteLine("result=" + result);
Console.WriteLine("PP=" + pp);
r.a = 5;
Console.WriteLine("zero_radius="+r.a);
zero_result = r.computer_zero1();
zero_p = r.computer_zero2();
Console.WriteLine("zero_result=" + zero_result);
Console.WriteLine("zero_p=" + zero_p);
r.a = 10;
Console.WriteLine("zero_radius=" + r.a);
zero_result = r.computer_zero1();
zero_p = r.computer_zero2();
Console.WriteLine("zero_result=" + zero_result);
Console.WriteLine("zero_p=" + zero_p);
r.a = 15;
Console.WriteLine("zero_radius=" + r.a);
zero_result = r.computer_zero1();
zero_p = r.computer_zero2();
Console.WriteLine("zero_result=" + zero_result);
Console.WriteLine("zero_p=" + zero_p);

}
}
class CR
{
public int width;
public int height;
public int a;
public int compute_area()
{
int area;
area=width*height;
return area;
}
public int computer_p()
{
int p;
p = 2 * (width + height);
return p;
}
public int computer_zero1()
{
int z1;
z1 = 3 * a * a;
return z1;
}
public int computer_zero2()
{
int z2;
z2 = 2 * a * 3;
return z2;
}
}
}

D9583066 提到...

第十一週作業 D9583066

class Mymain
{
static void Main(string[] args)
{
int no;
MyPoke k = new MyPoke();
no = k.Poke();
Console.WriteLine(no);
}
}
public class MyPoke
{
public int colar;
public int no;
public int Poke()
{
Random r = new Random();
no = r.Next(1, 14);
colar = r.Next(1, 5);
switch (colar)
{
case 1:
Console.WriteLine("黑桃");
break;
case 2:
Console.WriteLine("愛心");
break;
case 3:
Console.WriteLine("方塊");
break;
case 4:
Console.WriteLine("梅花");
break;
}
return no;
}

}
}

D9583066 提到...

第十三週作業 D9583066

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int i,c;
string s = "";
ArrayList a = new ArrayList(9);

for (i = 0; i <= 9; i++)
{
a.Add(i);
}
Random r = new Random();
for (i = 0; i <= 3; i++)
{
c = r.Next(0, a.Count);
s = s + a[c];
label1.Text = s;
a.RemoveAt(c);
}

}
}
}

dragon 提到...

d9582608 第八週
static void Main(string[] args)
{
int[,] a = { { 1, 2, 3, 4 }, { 8, 7, 6, 5 }, { 9, 10, 11, 12 }, { 16, 15, 14, 13 } };
int[] b = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
b = work(a);
for (int i = 0; i <= 15; i++)
Console.WriteLine(b[i]);
}
static int[] work(int[,] a)
{
int[] b = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int k = 0;
for (int i = 0; i <= 3; i++)
{
if (i % 2 == 0)
{

for (int j = 0; j <= 3; j++)
{
b[k] = a[j, i];
k++;
}

}


if (i % 2 == 1)
{
for (int j = 3; j >= 0; j--)
{
b[k] = a[j, i];
k++;
}
}
}
return (b);
}

Unknown 提到...

應數四乙 高治國 D9476863

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication15
{
class Program
{
static void Main(string[] args)
{
string s;

XXx xx = new XXx();
Random r = new Random();
xx.a = r.Next(53);

switch (xx.Y())
{
case 1:
Console.WriteLine("黑桃");
break;
case 2:
Console.WriteLine("紅心");
break;
case 3:
Console.WriteLine("方塊");
break;
case 4:
Console.WriteLine("梅花");
break;
}
Console.WriteLine(xx.X());
}
}
public class XXx
{
public double a, b,d;
public int c;
public double X()
{

b = Math.Ceiling(a / 13);
d = a - 13 * b + 13;
return d;
}
public int Y()
{
b = Math.Ceiling(a / 13);
c = (int)b;

return c;
}
}
}
---------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 四抽一
{
public partial class Form1 : Form
{
public Form1()
{

InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{

Ngame a=new Ngame();
label1.Text=""+a.no1+a.no2+a.no3+a.no4;
int []c = new int[4];
c[0] = int.Parse(textBox1.Text);
c[1] = int.Parse(textBox2.Text);
c[2] = int.Parse(textBox3.Text);
c[3] = int.Parse(textBox4.Text);
int[] b = new int[4];
b[0] = a.no1;
b[1] = a.no2;
b[2] = a.no3;
b[3] = a.no4;
int i, j,f=0,g=0,h;
for (i = 0; i <= 3; i++)
for (j = 0; j <= 3; j++)
if (c[i] == b[j])
f++;
for (i = 0; i <= 3; i++)
if (c[i] == b[i])
g++;
h = f - g;
label2.Text = "" +h;
label5.Text = "" + g;

}
public class Ngame
{
public int no1, no2, no3, no4;
public Ngame()
{
Random r = new Random();
no1=r.Next(0,10);
no2=r.Next(0,10);
while (no1 == no2)
{ no2 = r.Next(0, 10); }
no3=r.Next(0,10);
while (no1 == no3 | no2 == no3)
{ no3 = r.Next(0, 10); }
no4=r.Next(0,10);
while (no4 == no1 | no4 == no2|no4==no3)
{ no4 = r.Next(0, 10); }
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{

}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}

}
}

dragon 提到...

d9582608 第九週
int[,] a = { { 1, 2, 3, 4 }, { 8, 7, 6, 5 }, { 9, 10, 11, 12 }, { 16, 15, 14, 13 } };
int[] b = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
b = work(a);
foreach (int j in b)
Console.WriteLine(j);
static int[] work(int[,] a)
{
int[] b = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int k=0 ;
for (int i = 0; i <= 3;i++)
{
if (i %2== 1)
for (int j = 3; j >= 0; j--)
{
b[k] = a[j, i];
k++;

}
if (i %2== 0)
for (int j = 0; j <= 3; j++)
{
b[k] = a[j, i];
k++;

}
}
return (b);

Unknown 提到...

應數四乙 高治國 D9476863
VC++ 081024

using System;
using System.Collections.Generic;
using System.Text;
namespace 二微陣列
{
class Program
{
static void Main(string[] args)
{
int[,] a ={ { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } };
int[,] c ={ { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } };
int i,j;
/* for (i = 0; i <= 3; i++)
{
for (j = 0; j <= 3; j++)
{
c[i, j + 3 * (i%2) - 2 * j * (i%2)] = a[i, j];
}
} for (i = 0; i <= 3; i++)
{
for (j = 0; j <= 3; j++)
{
a[i,j]=c[j,i];
}
} for (i = 0; i <= 3; i++)
{
for (j = 0; j <= 3; j++)
{
c[i, j + 3 * (i % 2) - 2 * j * (i % 2)] = a[i, j];
}
}
for (i = 0; i <= 3; i++)
{
for (j = 0; j <= 3; j++)
{
Console.WriteLine (c[i, j] );
}
}*/
for (i = 0; i <= 3; i++)
{
for (j = 0; j <= 3; j++)
{
Console.WriteLine(a[j+(3-2*j)*(i%2),i+(3-2*i)*((j+(3-2*j)*(i%2))%2)]);
}
}



}
}
}

Unknown 提到...

應數四乙 高治國 D9476863
VC++ 081205


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace ConsoleApplication15
{
class Program
{
static void Main(string[] args)
{
ArrayList b = new ArrayList();
Console.WriteLine(b.Capacity);
Console.WriteLine(b.Count);
b.Add(5);
b.Add(1);
b.Add(3);
Console.WriteLine(b.Capacity);
Console.WriteLine(b.Count);
Console.WriteLine(b[1]);
Console.WriteLine(b[2]);
}
}
}
-------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace WindowsApplication14
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ArrayList b= new ArrayList(10);
int c;
string s="";
int i=0;
for(i=0; i<10; i++)
{
b.Add(i);
}
Random r = new Random();
for ( i = 0; i < 4; i++)
{
c = r.Next(b.Count);
s = s + b[c];
label1.Text = s;
b.RemoveAt(c);
}
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}

Unknown 提到...

應數四乙 高治國 D9476863
VC++ 081121


using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication3
{
class Mymain
{
static void Main(string[] args)
{
CRectangle rect = new CRectangle(10, 20);
//實作名稱為rect的物件(OBJECT)具有CRectangle 類別的屬性width和height及方法compute_area()
Console.WriteLine("rect.width=" + rect.width);
Console.WriteLine("rect.height=" + rect.height);
Console.WriteLine("rect.area=" + rect.compute_area());

/*rect.width = 10;
rect.height = 20;
Console.WriteLine("rect.width" + rect.width);
Console.WriteLine("rect.height" + rect.height);
CRectangle rect1 = new CRectangle();
Console.WriteLine("rect1.width" + rect1.width);
Console.WriteLine("rect1.height" + rect1.height);
CRectangle rect2 = new CRectangle();
Console.WriteLine("rect2.width" + rect2.width);
Console.WriteLine("rect2.height" + rect2.height);*/

CCricle circ = new CCricle(10);
Console.WriteLine("circ.radius=" + circ.radius);
Console.WriteLine("circ.area=" + circ.compute_area());

}
public class CCricle
{
public double radius;
public CCricle()
{
radius = 0;

}
public CCricle(double v1)
{
radius = v1;

}
public double compute_area()
{
double area;
area = radius * radius * Math.PI;
return area;
}
}
}
public class CRectangle
{
public double width, height, area;
public CRectangle()
{
width = 0;
height = 0;
}
public CRectangle(double v1,double v2)
{
double area;
width = v1;
height = v2;
area = width * height;
}
public double compute_area()
{
double area;
area = width * height;
return area;
}
}
}

Unknown 提到...

應數四乙 高治國 D9476863
VC++ 081114

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication11
{
class MyMain
{
static void Main(string[] args)
{
{
int result;
CRectangle rect = new CRectangle();
int width, height, area, painter;

rect.width = 10;
rect.height = 5;
result = rect.ComputeArea();
Console.WriteLine("矩形面積&周長");
Console.WriteLine("area=" + rect.ComputeArea());
Console.WriteLine("parinter=" + rect.ComputeParinter());
rect.width = 20;
rect.height = 10;
result = rect.ComputeArea();
Console.WriteLine("area=" + rect.ComputeArea());
Console.WriteLine("parinter=" + rect.ComputeParinter());
rect.width = 30;
rect.height = 15;
result = rect.ComputeArea();
Console.WriteLine("area=" + rect.ComputeArea());
Console.WriteLine("parinter=" + rect.ComputeParinter());

Console.WriteLine("圓面積&周長");
CCircle ccir = new CCircle();
ccir.r = 5;
result = ccir.Compute_Area();
Console.WriteLine("area=" + result);
result = ccir.Compute_Parimeter();
Console.WriteLine("parineter=" + result);
Console.WriteLine(" ");
ccir.r = 10;
result = ccir.Compute_Area();
Console.WriteLine("area=" + result);
result = ccir.Compute_Parimeter();
Console.WriteLine("parineter=" + result);
Console.WriteLine(" ");
ccir.r = 15;
result = ccir.Compute_Area();
Console.WriteLine("area=" + result);
result = ccir.Compute_Parimeter();
Console.WriteLine("parineter=" + result);
Console.WriteLine(" ");

}
}
}
class CRectangle
{
public int width, height, area;
public int ComputeArea()
{
area = width * height;
return area;

}
public int parinter;
public int ComputeParinter()
{
parinter = 2 * (width + height);
return parinter;
}


}
class CCircle
{
public int r, pi = 3;
public int Compute_Area()
{
int area;
area = pi * r * r;
return area;
}
public int Compute_Parimeter()
{
int Parimeter;
Parimeter = pi * r * 2;
return Parimeter;
}
}
}

東東 提到...

應數三乙 吳東翰

import java.io.*;
import java.io.FileReader;
import java.io.File;
import java.io.BufferedReader;
import java.util.StringTokenizer;
class momo
{
public static void main(String[] args)
{
String InputFile,OutFile;
int num=0,sumall=1;
InputFile=args[0];
System.out.println("InputFile:"+InputFile);
StringTokenizer st = new StringTokenizer(InputFile,".");
OutFile=st.nextToken()+".w"+st.nextToken();
System.out.println("OutputFileName:"+OutFile);
File position = new File(InputFile);
try{
BufferedReader input = new BufferedReader(new FileReader(position));
num=Integer.parseInt(input.readLine());
System.out.println(num);
}
catch(Exception e)
{
System.out.println("Error:"+e);
}
for(int j=1;j<=num;j++)
{
sumall=sumall*j;
System.out.println(sumall);
}
}
}

東東 提到...

應數三乙 吳東翰

import java.io.*;
import java.io.PrintStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;

class Myfirstjava extends Object
{
public static void main(String[] args)
{
String Inputfile;
System.out.println(args[0]);
Inputfile=args[0];
File position=new File(Inputfile);
try{
BufferedReader input = new BufferedReader(new FileReader( position ) );
int num = Integer.parseInt(input.readLine());
System.out.println(num );
FileOutputStream fos = new FileOutputStream
("C:\\Myjava\\test.txt");
BufferedOutputStream bos = new BufferedOutputStream
(fos);
PrintStream ps = new PrintStream(bos);

ps.println(num);
ps.close();
bos.close();
fos.close();
}
catch(Exception e)
{
System.out.println("Error:"+e);
}



}
}

d9538905 提到...

import java.io.*;
import java.util.StringTokenizer;

class Myjava05
{
public static void main(String[] args)
{
int x=1,num=0,i=0;
String InFileName,OutFileName,InputFile;
InputFile=args[0];
try
{
BufferedReader input = new BufferedReader(new FileReader( InputFile ) );
num = Integer.parseInt(input.readLine());
System.out.println(num);
}
catch(Exception e)
{
System.out.print("錯誤:"+e);
}
for(int j=1;j<=num;j++)
{
x=x*j;
System.out.println(j+"階="+x);

}
}
}