第九講 C#練習題

來源:互聯網
上載者:User

標籤:

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、會員管理\t2、儲值管理)");
               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、添加會員\t2、刪除會員\t3、餘額查詢");
                    int xx =Convert.ToInt32( Console.ReadLine());
                    huiyuanfuwu(xx, al);
                    break;
                case 2:
                    Console.WriteLine("1、儲值服務\t2、計費服務");
                    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;
            }
        }

    }
}


 

第九講 C#練習題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.