# 物件導向 程式設計實習
---
## 2024/1/24




---
**心得:**
經過了今天的課程,我發現不同的程式語言還是會有許多共同的語法和資料型別,像是C++中的cout在C#中是Console.Writeline,在這次的課程中我還學到了清單的用法,我覺得跟陣列有異曲同工之妙,但是用法比陣列更多。
---
## 2024/2/21
### 第一題練習題
**程式碼:**
```
Console.Write("請輸入你的名字: ");
string name = Console.ReadLine();
Console.WriteLine($"Good Day! {name}");
```
**運行:**

---
### 第二題練習題
**程式碼:**
```
Console.Write("請輸入名稱: ");
string name = Console.ReadLine();
Console.Write("請輸入提款金額: ");
int money = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"Hi! {name}, 提款金額: {money:C0}");
```
**運行:**

---
### 第三題練習題
**程式碼:**
```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace dafaq
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
label1.Text = "Hello,World!";
}
}
}
```
**運行:**


---
## 2024/3/6
### 第一題練習題
**程式碼:**
```
using static System.Console;
WriteLine("資訊一甲 28蔡宸睿");
WriteLine("");
int num1 = 123456;
long num2 = 456789123;
long max=Int64.MaxValue;
long min=Int64.MinValue;
int num3 = 0b1011110;
int num4 = 0b11111010;
int num5 = 0xFB12;
WriteLine($"Number:{num1:N0},{num2:n0}");
WriteLine($"二進位變十進位:{num3:D5},{num4:D4},{num5:D6}");
WriteLine($".NET Framework型別(num1): {num1:GetType()}");
WriteLine($".NET Framework型別(num2): {num2:GetType()}");
WriteLine($"最大值:{max} \n最小值:{min}");
```
**運行:**

---
### 第二題練習題
**程式碼:**
```
using static System.Console;
WriteLine("資訊一甲 28 蔡宸睿");
WriteLine("");
float num1 = 1.2233446F;
double num2 = 1.2233445566778899;
decimal num3 = 1.2233445566778899M;
double x1 = 0.1, x2 = 0.2;
decimal y1 = 0.1M, y2 = 0.2M;
WriteLine($"Float:{num1}");
WriteLine($"Double:{num2}");
WriteLine($"Decimal:{num3}");
WriteLine($"Float:{num1:f4}");
WriteLine($"double佔<{sizeof(double)}>位元組");
WriteLine($"decimal佔<{sizeof(decimal)}>位元組");
WriteLine($"double,x1+x2={x1 + x2}");
WriteLine($"decimal,y1+y2={y1 + y2}");
```
**輸出:**

---
### 第三題練習題
**程式碼:**
```
using static System.Console;
WriteLine("資訊一甲28蔡宸睿");
WriteLine();
const float square = 3.0579F;
Write("請輸入坪數:");
float area=Convert.ToSingle(ReadLine());
WriteLine($"{area}坪={square * area}平方公尺");
const float PI = 3.14159F;
const float circular = PI * 25.0F;
WriteLine($"圓面積 -> {circular}");
```
**輸出:**

---
### 第四題練習題
**程式碼:**
```
using static System.Console;
WriteLine("資訊一甲28蔡宸睿");
WriteLine();
Write("請輸入你的生日:");
string birth=ReadLine();
DateTime now=DateTime.Now;
DateTime special=Convert.ToDateTime(birth);
WriteLine($"今天是{now}");
WriteLine($"你的生日{special}");
```
**輸出:**

---
## 2024/3/13
### 第一題練習題
**程式碼:**
```
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.MaxLength = 3;
textBox2.ReadOnly = true;
textBox1.TabIndex = 0;
}
private void button1_Click(object sender, EventArgs e)
{
try
{
double sus=double.Parse(textBox1.Text);
double huasu = (sus * 9 / 5) + 32;
textBox2.Text=huasu.ToString();
textBox1.Focus();
}
catch
{
textBox2.Text = "溫度請輸入數值!";
textBox1.Clear();
}
}
}
}
```
**輸出:**


---
### 第二題練習題
**程式碼:**
```
using System.Data.SqlTypes;
namespace WinFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string username = Microsoft.VisualBasic.Interaction.InputBox("請輸入姓名", "輸入");
DialogResult dr=MessageBox.Show(username + "歡迎你!", "歡迎", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
Text = username;
}
private void button1_Click(object sender, EventArgs e)
{
try
{
decimal price = decimal.Parse(textBox2.Text);
label4.Text = price.ToString("N0");
}
catch
{
MessageBox.Show("請輸入整數! = =","注意",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
}
}
```




---
## 2024/3/20
### 第一題練習題
**程式碼:**
```
using static System.Console;
int sum = 0, cnt = 0;
for(; ; )
{
Write("請輸入數值做加總:");
int num = Convert.ToInt32(ReadLine());
cnt++;
sum+= num;
Write("還要繼續嗎?(y繼續,n離開)");
string endkey = ReadLine();
if (endkey == "y" || endkey == "Y")
continue;
else if (endkey == "n" || endkey == "N")
break;
}
WriteLine($"輸入{cnt}個數值,合計:{sum}");
ReadKey();
```
**輸出:**

---
## 2024/03/27
### 第一題練習題
**程式碼:**
```
string[] name = { "Molly", "Eric", "Johseph", "Peter", "Iron", "Priyanka" };
int[] age = { 24, 26, 24, 26, 28, 25 };
int index=Array.IndexOf(age, 24);
Console.WriteLine("---年齡符合24歲---");
while (index >= 0)
{
Console.Write($"{name[index],-8}");
index=Array.IndexOf(age, 24,index+1);
}
Array.Sort(age);
var key = Array.BinarySearch(age, 25);
switch (key)
{
case >= 0:
Console.WriteLine($"\n找到年齡25! 位置={key}");
break;
default:
Console.WriteLine($"\n未找到年齡25! 位置={key}");
break;
}
```
**輸出:**

---
### 第二題練習題
**程式碼:**
```
int outer, inner;
int[] sum = new int[3];
string[] names = {"Mary","Tomas","John"};
foreach(string name in names)
Console.Write("{0,7}",name);
Console.WriteLine();
int[,] score = { { 75, 64, 96 }, { 55, 67, 39 }, { 45, 92, 85 }, { 71, 69, 81 } };
int row = score.GetLength(0);
int column = score.GetLength(1);
for (outer = 0; outer < row; outer++)
{
for(inner = 0; inner < column; inner++)
{
Console.Write($"{score[outer, inner],7}");
}
Console.WriteLine();
sum[0] += score[outer, 0];
sum[1] += score[outer, 1];
sum[2] += score[outer, 2];
}
Console.WriteLine("-------------------------------------");
Console.WriteLine($"Sum:{sum[0]} {sum[1],5} {sum[2],6}");
```
**輸出:**

---
### 第三題練習題
**程式碼:**
```
int[,,] num3d = new int[2, 2, 3] { { { 11, 13, 15 }, { 22, 24, 26 } }, { { 33, 38, 41 }, { 44, 48, 52 } } };
Console.Write($"元素:{num3d[1,1,1]},"+$"位於第2個表格,位於第2列 第2欄\n");
int table = num3d.GetLength(0);
int row = num3d.GetLength(1);
int col = num3d.GetLength(2);
Console.Write($"表格{table}個,二維表格{row}*{col}\n");
for(int i = 0; i < table; i++)
{
Console.WriteLine($"----表格{i + 1}----");
for(int j=0; j < row; j++)
{
for(int k=0; k < col; k++)
{
Console.Write($"{num3d[i, j, k],3} |");
}
Console.WriteLine();
}
Console.WriteLine() ;
}
```
**輸出:**

---
## 2024/4/10
### 第一題練習題
**程式碼:**
```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Height = 90; pictureBox1.Width = 90; // 設定圖片高度和寬度
pictureBox1.Image = Image.FromFile("C:\\Users\\lung0\\Downloads\\images1.jpg"); // 載入圖檔
trackBar1.Maximum = 4; trackBar1.Minimum = 1;// 設定TkbPic的最大、最小值
vScrollBar1.Maximum = 180; vScrollBar1.Minimum = 1; // 設定最大、最小值
vScrollBar1.LargeChange = 1; // 設定VsbHeight的快動值 = 1
vScrollBar1.Value = pictureBox1.Height; // VsbHeight的Value值=圖片高度
hScrollBar1.Maximum = 180; hScrollBar1.Minimum = 1; // 設定最大、最小值
hScrollBar1.LargeChange = 1; // 設定HsbWidth的快動值 = 1
hScrollBar1.Value = pictureBox1.Width; // HsbWidth的Value值=圖片寬度
toolTip1.SetToolTip(vScrollBar1, $"{vScrollBar1.Value}");
toolTip1.SetToolTip(hScrollBar1, $"{hScrollBar1.Value}");
toolTip1.SetToolTip(trackBar1, "圖片1");
}
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
pictureBox1.Height = vScrollBar1.Value;
toolTip1.SetToolTip(vScrollBar1, $"{vScrollBar1.Value}");
}
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
pictureBox1.Width=hScrollBar1.Value;
toolTip1.SetToolTip(hScrollBar1, $"{hScrollBar1.Value}");
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile($"C:\\Users\\lung0\\Downloads\\images{trackBar1.Value}.jpg");
toolTip1.SetToolTip(trackBar1, $"圖片{trackBar1.Value}");
}
}
}
```
**輸出:**






---
### 第二題練習題
**程式碼:**
```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dateTimePicker1.CustomFormat = "yyyy-MM-dd HH:mm";
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.MinDate=DateTime.Now.AddMinutes(1);
dateTimePicker1.MaxDate = DateTime.Now.AddDays(7);
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Interval = 1000;
timer1.Enabled = true;
dateTimePicker1.Enabled = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
if(DateTime.Now>=dateTimePicker1.Value)
{
timer1.Enabled = false;
System.Media.SystemSounds.Beep.Play();
MessageBox.Show(textBox1.Text, "提示");
}
}
}
}
```
**輸出:**

---
## 2024/4/17
### 第一題練習題
**程式碼:**
```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://visualstudio.com/");
}
private void Form1_Load(object sender, EventArgs e)
{
linkLabel1.LinkColor = Color.DarkOrchid;
linkLabel1.ActiveLinkColor = Color.Yellow;
linkLabel1.LinkVisited = true;
linkLabel1.VisitedLinkColor = Color.Orange;
linkLabel1.LinkBehavior = LinkBehavior.HoverUnderline;
linkLabel1.Text = "Visual Studio Web";
linkLabel1.LinkArea = new LinkArea(0, 6);
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("C:\\Users\\user\\Desktop\\devcppPortable.exe - 捷徑.lnk\\");
}
}
}
```
**輸出:**


---