Chinaunix首页 | 论坛 | 博客
  • 博客访问: 182482
  • 博文数量: 14
  • 博客积分: 1403
  • 博客等级: 上尉
  • 技术积分: 192
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-18 16:36
文章分类

全部博文(14)

文章存档

2011年(5)

2010年(9)

分类: C/C++

2011-01-09 02:58:02

一直以来对.net都是非常厌恶的,因为要使用.net的程序就需要安装.net包,对于追求简单的我来说,简直不能忍受,所以连带着对c#也没什么好印象。

为了顺应时代进步的潮流,终于还是决定开始学习c#了。

为了方便以后查阅,在这里记录下学习笔记。

首先学习了条件判断语句if和分支判断语句switch的使用,对学生的成绩进行分等。同时使用了随机数自动生成学生成绩。

代码:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace c4_t1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] chengji = new int[20];
            int i;
            Console.Write("请输入学生个数:");
            int m = Convert.ToInt32(Console.ReadLine());
            Console.Write("请输入成绩判定方法,if为1,switch为2:");
            string f = Console.ReadLine();
            Random ra = new Random();

            switch (f)
            {
                case "1":
                    {
                        for (i = 0; i < m; i++)
                        {
                            chengji[i] = ra.Next(0, 100);
                            Console.WriteLine("{0}\t{1}", chengji[i], Lv1(chengji[i]));
                        }
                        Console.WriteLine("成绩判断完毕。");
                        break;
                    }
                case "2":
                    {
                        for (i = 0; i < m; i++)
                        {
                            chengji[i] = ra.Next(0, 100);
                            Console.WriteLine("{0}\t{1}", chengji[i], Lv2(chengji[i]));
                        }
                        Console.WriteLine("成绩判断完毕。");
                        break;
                    }
                default:
                    Console.WriteLine("未知的成绩判定方法。");
                    break;
            }
            System.Threading.Thread.Sleep(1000000);
        }
        ///



        /// 使用switch判定成绩等级

        ///


        /// 成绩分数

        /// 返回成绩等级

        public static char Lv2(int n)
        {
            string t = Convert.ToString(n);
            int m = Convert.ToInt32(t.Substring(0, 1));
            int l = t.Length;
            char c;
            switch (l)
            {
                case 3:
                    c='A';
                    break;
                case 2:
                    {
                        switch (m)
                        {
                            case 9:
                                c='A';
                                break;
                            case 8:
                                c='B';
                                break;
                            case 7:
                                c='C';
                                break;
                            case 6:
                                c='D';
                                break;
                            default:
                                c='E';
                                break;
                        }
                        break;
                    }
                case 1:
                    c='E';
                    break;
                default:
                    c='F';
                    break;
            }
            return c;
        }
        
        ///

        /// 使用if判定成绩等级

        ///


        /// 成绩分数

        /// 返回成绩等级

        public static char Lv1(int n)
        {
            if (n > 89)
            {
                return 'A';
            }
            else if(n>79)
            {
                return 'B';
            }
            else if(n>69)
            {
                return 'C';
            }
            else if(n>59)
            {
                return 'D';
            }
            else
            {
                return 'E';
            }
        }
    }
}


阅读(4103) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~