m0_50986232 2021-06-18 15:05 采纳率: 84.6%
浏览 40
已采纳

C#(Visual C#控制台应用程序)类创建函数

 

  • 写回答

2条回答 默认 最新

  • CSDN专家-showbo 2021-06-18 15:30
    关注

     

    帮助到你可以点个采纳吗,谢谢~~

    using System;
    namespace ConsoleApp1
    {
        class Customer
        {
            private string cNo { get; set; }
            private string cName { get; set; }
            private int cPoints { get; set; }
            private string cTelephone { get; set; }
            public string CNo { get { return cNo; } }
            public string CName { get { return cName; } }
            public int CPoints { get { return cPoints; }set{ cPoints = value; } }
            public string CTelephone { get { return cTelephone; }set { cTelephone = value; } }
    
            public Customer() { }
            public void Input()
            {
                Console.Write("请输入客户编号:");
                cNo = Console.ReadLine();
                Console.Write("请输入客户姓名:");
                cName = Console.ReadLine();
                Console.Write("请输入客户电话:");
                cTelephone = Console.ReadLine();
                while (true)
                {
                    Console.Write("请选择你的操作,1-增加积分;2-兑换积分,其他则退出--");
                    string op = Console.ReadLine();
    
                    if (op == "1" || op == "2")
                    {
                        Console.Write("请输入要" + (op == "1" ? "增加" : "兑换") + "的积分:");
                        string sScore = Console.ReadLine();
                        int score = 0;
                        if (int.TryParse(sScore, out score))
                        {
                            if (op == "1")
                            {
                                Buy(score);
                                Console.WriteLine("已存入{0}积分", score);
                                Show();
                            }
                            else
                            {
                                Exchange(score);
                                Console.WriteLine("本次兑换{0}积分", score);
                                Show();
                            }
                        }
                        else Console.WriteLine("积分需要为数字,请重新选择操作!");
                    }
                    else
                    {
                        Console.WriteLine("系统选择错误,退出!");
                        break;
                    }
                }
            }
            private void Show() {
                Console.WriteLine("客户编号:" + cNo + ",客户姓名:" + cName + ",客户联系电话:" + cTelephone + ",客户积分:" + cPoints);
            }
            public void Buy(int x)
            {
                this.cPoints += x;
            }
            public void Exchange(int c)
            {
                if (c > cPoints) Console.WriteLine("积分不足!");
                else this.cPoints -= c;
            }
    
        }
        class Program
        {
            static void Main(string[] args)
            {
                var kate = new Customer();
                kate.Input();
    
                Console.WriteLine("请安任意键继续!");
                Console.ReadKey();
            }
        }
    }
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决