2017-2-19,做業

 1             //輸出;
 2             Console.Write("「請輸入第一個學生的姓名:」");
 3             //定義a1並賦值a1爲讀取的內容爲值;
 4             string a1 = Console.ReadLine();
 5             Console.Write("「請輸入第一個學生的年齡:」");
 6             string b1 = Console.ReadLine();
 7             Console.Write("「請輸入第一個學生的語文成績:」");
 8             string c1 = Console.ReadLine();
 9             Console.Write("「請輸入第一個學生的數學成績:」");
10             string d1 = Console.ReadLine();
11             Console.Write("「請輸入第一個學生的英語成績:」");
12             string e1 = Console.ReadLine();
13 
14             //將string字符串類型變量轉換爲int整型、相加,並將值賦予a;
15             int a = (int.Parse(c1)) + (int.Parse(d1)) + (int.Parse(e1));
16             //輸出分割線;
17             Console.WriteLine("--------------------------------------------------------------");
18 
19             //輸出;
20             Console.Write("「第二個學生的姓名:」");
21             //賦值a2於讀取內容;
22             string a2 = Console.ReadLine();
23             Console.Write("「第二個學生的年齡:」");
24             string b2 = Console.ReadLine();
25             Console.Write("「第二個學生的語文成績:」");
26             string c2 = Console.ReadLine();
27             Console.Write("「第二個學生的數學成績:」");
28             string d2 = Console.ReadLine();
29             Console.Write("「第二個學生的英語成績:」");
30             string e2 = Console.ReadLine();
31 
32             //將string字符串類型的變量轉換爲int整型變量、相加,並將值賦予b;
33             int b = (int.Parse(c2)) + (int.Parse(d2)) + (int.Parse(e2));
34             Console.WriteLine("--------------------------------------------------------------");
35 
36             //輸出;
37             Console.Write("「第三個學生的姓名:」");
38             string a3 = Console.ReadLine();
39             Console.Write("「第三個學生的年齡:」");
40             string b3 = Console.ReadLine();
41             Console.Write("第三個學生的語文成績:");
42             string c3 = Console.ReadLine();
43             Console.Write("第三個學生的數學成績:");
44             string d3 = Console.ReadLine();
45             Console.Write("第三個學生的英語成績:");
46             string e3 = Console.ReadLine();
47             
48             //將string字符串類型變量轉換爲int整型變量、相加,並將值賦予c;
49             int c=(int.Parse(c3))+(int.Parse(d3))+(int.Parse(e3));
50             Console.WriteLine("--------------------------成績展現----------------------------");
51 
52             //輸出字符串以及string字符串類型的變量;
53             Console.WriteLine("「一、" + a1 + "的語文成績是:" + "" + c1 + "" + "" + "數學成績是:" + "" + d1 + "" + "" + "英語成績是:" + "" + e1 + "" + "總分是:" + "" + a + "" + "");
54             Console.WriteLine("「二、" + a2 + "的語文成績是:" + "" + c2 + "" + "" + "數學成績是:" + "" + d2 + "" + "" + "英語成績是:" + "" + e2 + "" + "總分是:" + "" + b + "" + "");
55             Console.WriteLine("「三、" + a3 + "的語文成績是:" + "" + c3 + "" + "" + "數學成績是:" + "" + d3 + "" + "" + "英語成績是:" + "" + e3 + "" + "總分是:" + "" + c + "" + "");
56 
57             //將string字符串類型的變量轉換爲int整型類型的變量、相加,並將值賦予cz,dz,ez;
58             int cz = (int.Parse(c1)) + (int.Parse(c2)) + (int.Parse(c3));
59             int dz = (int.Parse(d1)) + (int.Parse(d2)) + (int.Parse(d3));
60             int ez = (int.Parse(e1)) + (int.Parse(e2)) + (int.Parse(e3));
61             //強制轉換string字符串類型的變量爲decimal浮點型變量、相加,並將值賦予cp,sp,yp,以方便求得平均值;
62             decimal cp = ((Convert.ToDecimal(c1)) + (Convert.ToDecimal(c2)) + (Convert.ToDecimal(c3)) / 3);
63             decimal sp = ((Convert.ToDecimal(d1)) + (Convert.ToDecimal(d2)) + (Convert.ToDecimal(d3)) / 3);
64             decimal yp = ((Convert.ToDecimal(e1)) + (Convert.ToDecimal(e2)) + (Convert.ToDecimal(e3)) / 3); 
65             //用int整型變量類型相加計算和;
66             int zh = cz + dz + ez;
67             
68             
69             //輸出string字符串類型變量和int整型類型變量;
70             Console.WriteLine("語文總分是:" + "" + cz + "" + "" + "平均分是:" + "" + cp + "" + "" + ("\n") + "數學總分是:" + "" + dz + "" + "" + "平均分是:" + "" + sp + "" + "" + ("\n") + "英語總分是:" + "" + ez + "" + "" + "平均分是:" + "" + yp + "" + "" + ("\n"));
71             //輸出decimal浮點型變量,並利用代碼("\n")進行快捷換行;
72             Console.WriteLine(cp+("\n")+sp+("\n")+yp);
73             Console.WriteLine(zh);
74             Console.WriteLine("全部人員的全部科目分數總和是:" + "" + zh + "" + "");
75 
76             //防止閃退;
77             Console.ReadLine();
相關文章
相關標籤/搜索