zoukankan      html  css  js  c++  java
  • 第九讲 C#练习题

    1、接收一个整数N 如果N是正数就输出1·N

    如果是负数就提示出错输出

    由丰老师提供 -_-~


    2、编一个程序,从三个红球,五个白球,六个黑球中任意取出八个球,且其中必须有白球,输出所有可能的方案。

    3、编一个程序,楼梯有n阶阶梯,每次只能走一阶或者两阶,问,有多少种走法?

    以上由王珂老师提供。


    4、小超市

    100 9.5
    200 9
    300 8.5
    400 8

    每次输入实际金额 显示折后价 并且显示本次节省多少钱

    5、网吧充值
    利用while循环一直执行
    定义会员机构体
    在循环外部定义一个集合用于存放会员结构体(用户名、密码、余额)
    每次循环执行一次询问
    (会员管理(新增会员、删除会员、余额查询(利用用户名查询)),充值管理(充值服务、扣费服务))


    会员2元一小时

    10元送2元,
    20元送5元,
    50元送20元,
    100元送50元,
    200元送150元。
    300元以上充多少送多少
    我冲多少钱 能玩多少小时 请提供具体信息。


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

    namespace ConsoleApplication1
    {
        class Program
        {
            struct huiyuan
            {
                public string name;
                public string password;
                public double yue;
            }
            static void Main(string[] aaa)
            {
                Console.BackgroundColor = ConsoleColor.White;
                Console.ForegroundColor = ConsoleColor.Black;
                Console.Clear();
                ArrayList Ul=new ArrayList();
                while (true)
                {

                    try
                    {
                    Console.WriteLine("请输入您要执行的操作:(1、会员管理 2、充值管理)");
                   int x=Convert.ToInt32( Console.ReadLine());
                   m(x, Ul);
                    }
                    catch (Exception)
                    {
                       
                       
                    }
                }


            }
            static void m(int x, ArrayList al)
            {
                switch (x)
                {
                    case 1:
                        Console.WriteLine("1、添加会员 2、删除会员 3、余额查询");
                        int xx =Convert.ToInt32( Console.ReadLine());
                        huiyuanfuwu(xx, al);
                        break;
                    case 2:
                        Console.WriteLine("1、充值服务 2、扣费服务");
                        int xxx = Convert.ToInt32(Console.ReadLine());
                        chongzhiguanli(xxx,al);
                        break;
                    default:
                        break;
                }
            }

             static void chongzhiguanli(int x,ArrayList al)
            {
                switch (x)
                {
                    case 1:
                        Console.Write("请输入要充值的用户名:");
                        string sname = Console.ReadLine();
                        foreach (huiyuan item in al)
                        {
                            if (item.name==sname)
                            {
                               
                                Console.WriteLine("当前余额为:"+item.yue);
                                Console.Write("请输入充值金额:");
                                double m=Convert.ToInt32(Console.ReadLine());
                                chongzhi(m,al,sname);
                                break;

                            }
                        }
                        break;
                    default:
                        break;
                }
            }

             static void chongzhi(double m, ArrayList al,string sname)
             {
                 double x = 0;//奖励金额
                

                 if (m>=10&&m<20)
                 {
                     x = 2;
                 }
                 else if (m >= 20 && m < 50)
                 {
                     x = 5;
                 }
                 else if (m >= 50 && m < 100)
                 {
                     x = 20;
                 }
                 else if (m >= 100 && m < 200)
                 {
                     x = 50;
                 }
                 else if (m >= 200 && m < 300)
                 {
                     x = 150;
                 }
                 else if (m >= 300)
                 {
                     x = m;
                 }
                 else
                 {
                     x = 0;
                 }
                 huiyuan temp=new huiyuan();
                 for (int i = 0; i < al.Count; i++)
                 {
                     temp=((huiyuan)al[i]);
                     if (temp.name==sname)
                     {
                        
                         temp.yue += Convert.ToDouble(m + x);
                         Console.WriteLine("本次充值成功,充值金额为" + m + "。奖励金额为:" + x + ".充值后余额为:" + temp.yue);
                         al.Insert(i, temp);
                         al.RemoveAt(i + 1);
                         break;
                     }
                    
                 }
                
             }
            static void huiyuanfuwu(int x, ArrayList al)
            {
                switch (x)
                {
                    case    1:
                        huiyuan h = new huiyuan();
                        Console.Write("请输入用户名:");
                        h.name = Console.ReadLine();
                        Console.Write("请输入密码:");
                        h.password = Console.ReadLine();
                        h.yue = 0;
                        al.Add(h);
                        break;
                    case 2:
                        Console.Write("请输入要删除的用户名:");
                        string dname = Console.ReadLine();
                        foreach (huiyuan item in al)
                        {
                            if (item.name==dname)
                            {
                                al.Remove(item);
                                Console.WriteLine("删除成功!");
                                break;
                            }
                        }

                        break;
                    case 3:
                        Console.Write("请输入要查询的用户名:");
                        string sname = Console.ReadLine();
                        foreach (huiyuan item in al)
                        {
                            if (item.name==sname)
                            {
                               
                                Console.WriteLine("当前余额为:"+item.yue);
                            }
                        }
                        break;
                    default:
                        break;
                }
            }

        }
    }


     

  • 相关阅读:
    Linux Commands
    sizeof操作符的使用详解
    在Vim中使用cscope
    MySQL学习笔记
    Online judge for leetcode
    使用Vim,让你工作效率更高
    Ext JS笔记
    安装J2EE开发环境
    这些都是什么啊
    QrCode二维码的实现原理
  • 原文地址:https://www.cnblogs.com/Kare/p/4330358.html
Copyright © 2011-2022 走看看