ACCP7.0S2深入.NET和C#程式設計第二章上機1,2
阿新 • • 發佈:2019-01-23
-------上機1
------上機2class 上機1 { static void Main(string[] args) { int[] oldpoint = new int[5]; int[] newpoint=new int[5]; Console.WriteLine("請輸入五位會員積分"); for (int i = 0; i < oldpoint.Length;i++) { Console.WriteLine("第" + (i + 1) + "位會員積分為:"); oldpoint[i] = Convert.ToInt32(Console.ReadLine()); } for (int i = 0; i < newpoint.Length; i++) { newpoint[i] = oldpoint[i] + 500; } Console.WriteLine("序號\t歷史積分\t新年積分"); for (int i = 0; i < newpoint.Length; i++) { Console.Write((i+1)+"\t"+oldpoint[i]+"\t"); Console.WriteLine("\t"+newpoint[i]); } Console.WriteLine("按任意鍵繼續"); Console.ReadLine(); } }
class Program { static void Main(string[] args) { computer computer = new computer(); computer[] com = new computer[3]; com[0] = new computer(); com[0].type = "hpCQ-217TX"; com[0].date = "2013-10-5"; com[1] = new computer(); com[1].type = "Mc240CH/A"; com[1].date = "2013-10-5"; com[2] = new computer(); com[2].type = "SYNW18H/W"; com[2].date = "2013-10-5"; Console.WriteLine("===========設定計算機id前==========="); Console.WriteLine("計算機型號\t計算機id\t購買時間"); for (int i = 0; i < com.Length; i++) { Console.WriteLine(com[i].type + "\t\t\t" + com[i].date); } Random ran = new Random(); com[0].num = ran.Next(1000, 9999); com[1].num = ran.Next(1000, 9999); com[2].num = ran.Next(1000, 9999); Console.WriteLine("===========設定計算機id後==========="); Console.WriteLine("計算機型號\t計算機id\t購買時間"); for (int i = 0; i < com.Length; i++) { Console.WriteLine(com[i].type + "\t" +com[i].type+"-"+ com[i].num + "\t" + com[i].date); } Console.ReadLine(); } public class computer { public string type; public int num; public string date; } }