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("“1、" + a1 + "的语文成绩是:" + "“" + c1 + "”" + "," + "数学成绩是:" + "“" + d1 + "”" + "," + "英语成绩是:" + "“" + e1 + "”" + "总分是:" + "“" + a + "”" + "。"); 54 Console.WriteLine("“2、" + a2 + "的语文成绩是:" + "“" + c2 + "”" + "," + "数学成绩是:" + "“" + d2 + "”" + "," + "英语成绩是:" + "“" + e2 + "”" + "总分是:" + "“" + b + "”" + "。"); 55 Console.WriteLine("“3、" + 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();