2015年6月18日 星期四
[2015][Quiz][Week12]Quiz06 - Team05
主程式:Form1.cs
父類別:Shape3D
子類別:Ball,Cube,Cylinder,Pyramid
靜態類別:GeoConstant
2015年4月9日 星期四
[2015][Homework]Team05-Hw05
read more
程式分為四個部分, 包含主程式及3個class
MyPoint 定義兩點以及之間的距離
Triangle 定義三點座標、三角形是否合理、求初期周長 面積 以及外接圓半徑
PinBoard 定義板子大小(行列 間隔數)把板子都先填上虛擬點
Program
MyPoint 定義兩點以及之間的距離
Triangle 定義三點座標、三角形是否合理、求初期周長 面積 以及外接圓半徑
PinBoard 定義板子大小(行列 間隔數)把板子都先填上虛擬點
Program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW5
{
class Program
{
static void Main(string[] args)
{
PinBoard board = new PinBoard();
Triangle tri = new Triangle();
MyPoint point = new MyPoint();
Random rand = new Random();
while (true)
{
Console.WriteLine("請決定點鎮的大小:");
RowsLabel:
Console.WriteLine("幾列:?");
board.rows = int.Parse(Console.ReadLine());
if (board.rows <= 0)
{
Console.WriteLine("列數必須要大於0!");
goto RowsLabel;
}
ColsLabel:
Console.WriteLine("幾行:?");
board.columns = int.Parse(Console.ReadLine());
if (board.columns <= 0)
{
Console.WriteLine("行數必須要大於0!");
goto ColsLabel;
}
Console.WriteLine("請決定點陣間隔");
XIntervalLabel:
Console.WriteLine("橫向間隔?");
board.rowInterval = int.Parse(Console.ReadLine());
if (board.rowInterval <= 0)
{
Console.WriteLine("橫向間隔必須要大於0!");
goto XIntervalLabel;
}
YIntervalLabel:
Console.WriteLine("縱向間隔?");
board.rowInterval = int.Parse(Console.ReadLine());
if (board.columnInterval <= 0)
{
Console.WriteLine("縱向間隔必須要大於0!");
goto YIntervalLabel;
}
board.CreatePins();
board.SetPinPosition();
TrianglePin:
for (int i = 0; i < 3; i++)
{
tri.pointArray[i] = board.pinArray[rand.Next(board.rows), rand.Next(board.columns)];
}
if (!tri.IsQualified())
{
Console.WriteLine("此三點不構成三角形!");
goto TrianglePin;
}
for (int i = 0; i < 3; i++)
{
Console.WriteLine("({0},{1})",tri.pointArray[i].x,tri.pointArray[i].y);
}
Console.WriteLine("此三角形的周長為:{0}",tri.Perimeter());
Console.WriteLine("此三角形的面積為:{0}",tri.Area());
Console.WriteLine("此三角形的外接圓半徑為:{0}", tri.RadiusOfCircumcircle());
string select = Console.ReadLine();
Console.WriteLine("Again?");
if (("y" != select) && ("Y" == select))
break;
}
Console.Read();
}
}
}
MyPoint
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW5
{
class MyPoint
{
public double x;
public double y;
public double DistanceTo(MyPoint pin)//兩點之間距離
{
double Distance=Math.Sqrt(Math.Pow((pin.x-x),2)+Math.Pow((pin.y-y),2));
return Distance;
}
}
}
Triangle
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW5
{
class Triangle
{
public MyPoint[] pointArray = new MyPoint[3];
public double Perimeter()//求三角形周長
{
double Length1 = pointArray[0].DistanceTo(pointArray[1]);//用DistanceTo計算三邊長
double Length2 = pointArray[1].DistanceTo(pointArray[2]);
double Length3 = pointArray[2].DistanceTo(pointArray[0]);
double perimeter = Length1 + Length2 + Length3;
return perimeter;
}
public double Area()//求三角形面積
{
double Length1 = pointArray[0].DistanceTo(pointArray[1]);//用DistanceTo計算三邊長
double Length2 = pointArray[1].DistanceTo(pointArray[2]);
double Length3 = pointArray[2].DistanceTo(pointArray[0]);
double perimeter = Length1 + Length2 + Length3;
double area = Math.Sqrt((0.5 * perimeter) + (0.5 * (perimeter - Length1)) + (0.5 * (perimeter - Length2)) + (0.5 * (perimeter - Length3)));//海龍公式
return area;
}
public bool IsQualified()//判斷三角形
{
double Length1 = pointArray[0].DistanceTo(pointArray[1]);//用DistanceTo計算三邊長
double Length2 = pointArray[1].DistanceTo(pointArray[2]);
double Length3 = pointArray[2].DistanceTo(pointArray[0]);
double temp = 0;
while(true) //將Length1設定為最大邊
{
if (Length1 < Length2)
{
temp = Length1;
Length1 = Length2;
Length2 = temp;
}
else if (Length2 < Length3)
{
temp = Length2;
Length2 = Length3;
Length3 = temp;
}
else
break;
}
if (Length1 < (Length2 + Length3))//兩邊和大於第三邊
return true;
else
return false;
}
public double RadiusOfCircumcircle()//求三角形外接圓半徑
{
double Length1 = pointArray[0].DistanceTo(pointArray[1]);//用DistanceTo計算三邊長
double Length2 = pointArray[1].DistanceTo(pointArray[2]);
double Length3 = pointArray[2].DistanceTo(pointArray[0]);
double cosA = (Length3 * Length3 + Length2 * Length2 - Length1 * Length1) / (2 * Length2 * Length3);
double sinA = Math.Sqrt(1 - cosA * cosA);
double radius = 0.5 * Length1 / sinA;
return radius;
}
}
}
PinBoard
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW5
{
class PinBoard
{
public int rows = 10;
public int columns = 10;
public Double rowInterval = 10;
public Double columnInterval = 10;
public MyPoint[,] pinArray = null;
public void CreatePins() //產生矩陣各點的位置
{
pinArray = new MyPoint[rows, columns];
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
pinArray[i, j] = new MyPoint();
}
}
}
public void SetPinPosition() //依行列間距計算出各點x.y之座標
{
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
pinArray[i, j].x = (i * rowInterval);
pinArray[i, j].y = (j * columnInterval);
}
}
}
}
}
2015年4月8日 星期三
2015年3月26日 星期四
2015年3月25日 星期三
[2015][Homework]Team05 - Hw01 (Revised)
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _40173007H_hw3
{
class Program
{
static void Main(string[] args)
{
string select;
int y, m, d, sel;
while (1 == 1)
{
Console.WriteLine("輸入1~6題號");
Console.WriteLine("輸入其他數字以結束程式");
select = Console.ReadLine();
sel = int.Parse(select);
switch (sel)
{
case (1):
//第一題 阿姆斯壯數
int a = 0;
int b = 0;
int c = 0;
double sum = 0;
Console.WriteLine("顯示100~999間的阿姆斯壯數");
for (int i = 100; i <= 999; i++)
{
a = i % 10;
b = i / 10 % 10;
c = i / 100 % 10;
sum = Math.Pow((double)a, 3) + Math.Pow((double)b, 3) + Math.Pow((double)c, 3);
if (sum == i)
Console.WriteLine("{0}", i);
}
Console.ReadKey();
Console.Clear();
break;
case (2):
//第二題 判斷閏年
Console.WriteLine("輸入年分");
y = int.Parse(Console.ReadLine());
if (y % 4 == 0 && y % 100 != 0)
Console.WriteLine("這年是閏年");
else if (y % 400 == 0)
Console.WriteLine("這年是閏年");
else
Console.WriteLine("這年不是閏年");
Console.ReadKey();
Console.Clear();
break;
case (3):
//第三題 判斷天數
Console.WriteLine("輸入年分");
y = int.Parse(Console.ReadLine());
Console.WriteLine("輸入月分");
m = int.Parse(Console.ReadLine());
if (m > 12)
Console.WriteLine("這不是月份!");
else if (m == 2)
if (y % 4 == 0)
Console.WriteLine("這個月有29天");
else
Console.WriteLine("這個月有28天");
else if (m % 2 == 1 || m == 8)
Console.WriteLine("這個月有31天");
else
Console.WriteLine("這個月有30天");
Console.ReadKey();
Console.Clear();
break;
case (4):
//第四題 判斷星期幾
Console.WriteLine("輸入年分");
y = int.Parse(Console.ReadLine());
Console.WriteLine("輸入月分");
m = int.Parse(Console.ReadLine());
Console.WriteLine("輸入日期");
d = int.Parse(Console.ReadLine());
int W;
if (m == 1)
{
y = y - 1;
m = 13;
}
else if (m == 2)
{
y = y - 1;
m = 14;
}
W = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400 + 1) % 7;
switch (W)
{
case (1):
Console.WriteLine("今天星期一");
break;
case (2):
Console.WriteLine("今天星期二");
break;
case (3):
Console.WriteLine("今天星期三");
break;
case (4):
Console.WriteLine("今天星期四");
break;
case (5):
Console.WriteLine("今天星期五");
break;
case (6):
Console.WriteLine("今天星期六");
break;
case (0):
Console.WriteLine("今天星期天");
break;
}
Console.ReadKey();
Console.Clear();
break;
case (5):
//第五題 判斷日期合法與否
Console.WriteLine("輸入年分");
y = int.Parse(Console.ReadLine());
Console.WriteLine("輸入月分");
m = int.Parse(Console.ReadLine());
Console.WriteLine("輸入日期");
d = int.Parse(Console.ReadLine());
if (d > 31)
Console.WriteLine("此日期不合法");
else if (d == 31 && m % 2 == 0)
{
if (m == 8 || m == 10 || m == 12)
Console.WriteLine("此日期合法");
else
Console.WriteLine("此日期不合法");
}
else if (d == 30 && m == 2)
Console.WriteLine("此日期不合法");
else if (d == 29)
{
if (y % 4 == 0)
{
if (y % 100 == 0 && y % 400 != 0)
Console.WriteLine("此日期不合法");
else
Console.WriteLine("此日期合法");
}
else
Console.WriteLine("此日期不合法");
}
else
Console.WriteLine("此日期合法");
Console.ReadKey();
Console.Clear();
break;
case (6):
//第六題 判斷日期相差天數
int totalDay1 = 0, totalDay2 = 0, diff = 0, leaps, tempsum;
for (int times = 1; times < 3; times++)
{
Console.WriteLine("輸入第{0}次年分", times);
y = int.Parse(Console.ReadLine());
Console.WriteLine("輸入第{0}次月分", times);
m = int.Parse(Console.ReadLine());
Console.WriteLine("輸入第{0}次日期", times);
d = int.Parse(Console.ReadLine());
leaps = y / 4 - y / 100 + y / 400;
switch (m)
{
case (1):
tempsum = (y * 365 + leaps) + d;
totalDay1 = totalDay2;
totalDay2 = tempsum;
break;
case (2):
tempsum = (y * 365 + leaps) + 31 + d;
totalDay1 = totalDay2;
totalDay2 = tempsum;
break;
case (3):
tempsum = (y * 365 + leaps) + 59 + d;
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
tempsum = tempsum + 1;
totalDay1 = totalDay2;
totalDay2 = tempsum;
break;
case (4):
tempsum = (y * 365 + leaps) + 90 + d;
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
tempsum = tempsum + 1;
totalDay1 = totalDay2;
totalDay2 = tempsum;
break;
case (5):
tempsum = (y * 365 + leaps) + 120 + d;
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
tempsum = tempsum + 1;
totalDay1 = totalDay2;
totalDay2 = tempsum;
break;
case (6):
tempsum = (y * 365 + leaps) + 151 + d;
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
tempsum = tempsum + 1;
totalDay1 = totalDay2;
totalDay2 = tempsum;
break;
case (7):
tempsum = (y * 365 + leaps) + 181 + d;
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
tempsum = tempsum + 1;
totalDay1 = totalDay2;
totalDay2 = tempsum;
break;
case (8):
tempsum = (y * 365 + leaps) + 212 + d;
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
tempsum = tempsum + 1;
totalDay1 = totalDay2;
totalDay2 = tempsum;
break;
case (9):
tempsum = (y * 365 + leaps) + 243 + d;
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
tempsum = tempsum + 1;
totalDay1 = totalDay2;
totalDay2 = tempsum;
break;
case (10):
tempsum = (y * 365 + leaps) + 273 + d;
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
tempsum = tempsum + 1;
totalDay1 = totalDay2;
totalDay2 = tempsum;
break;
case (11):
tempsum = (y * 365 + leaps) + 304 + d;
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
tempsum = tempsum + 1;
totalDay1 = totalDay2;
totalDay2 = tempsum;
break;
case (12):
tempsum = (y * 365 + leaps) + 334 + d;
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
tempsum = tempsum + 1;
totalDay1 = totalDay2;
totalDay2 = tempsum;
break;
}
}
diff = totalDay1 - totalDay2;
if (diff < 0)
Console.WriteLine("此兩日相差{0}天", -(diff - 1));
else
Console.WriteLine("此兩日相差{0}天", diff - 1);
Console.ReadKey();
Console.Clear();
break;
default:
return;
}
}
}
}
}
2015年3月18日 星期三
訂閱:
文章 (Atom)