好好学C# 2021-09-25 16:35 采纳率: 66.7%
浏览 43
已结题

一个叫号机程序C#,不知道函数怎么写对C#不是很懂

using System.Text;

namespace QueueMachine
{

//设计一个叫号机程序,输入1表示有人进队,输入2表示有人离开队列接受服务,3表示列出队列的成员和成员数目,0表示退出程序。
//已给定主程序,要求将三个函数补充完整
class Program
{

    static void addQueue(Queue q)
    {
        //要求输入一个名字,将此人加入到队列中
    
    }

    static void leaveQueue(Queue q)
    {
        //要求从队列中出来一个人,比如接受服务

    }


    static void listQueue(Queue q)
    {
        //输出队列中一共有多少人,并输出每个人名字
    }


    static void Main(string[] args)
    {
        int i=0;
        Queue q = new Queue(50);

        Console.WriteLine("This is a queue machine."+
            "You can type the following digits: \n"+
            "\t1 for entering the queue, \n"+
            "\t2 for leaving the queue, \n"+
            "\t3 for listing the members in the queue,\n"+
            "\t0 for exiting:");
        do
        {
            i = Convert.ToInt32(Console.ReadLine());
            if (i == 1)
            {
                addQueue(q);
            }
            else if (i == 2)
            {
                leaveQueue(q);
            }
            else if (i == 3)
            {
                listQueue(q);
            }
            else if(i==0)
            {
                 break;
            }
            else 
                Console.WriteLine("wrong input");

        } while (true);
  • 写回答

1条回答 默认 最新

  • CSDN专家-showbo 2021-09-25 16:55
    关注

    这样?有帮助麻烦点个采纳【本回答右上角】,谢谢~~有其他问题可以继续交流~

    img

    using System;
    using System.Text;
    using System.Collections;
    namespace QueueMachine
    {
        //设计一个叫号机程序,输入1表示有人进队,输入2表示有人离开队列接受服务,3表示列出队列的成员和成员数目,0表示退出程序。
        //已给定主程序,要求将三个函数补充完整
        class Program
        {
            static void addQueue(Queue q)
            {
                //要求输入一个名字,将此人加入到队列中
                Console.Write("请输入姓名:");
                var s = Console.ReadLine();
                q.Enqueue(s);
                Console.WriteLine(s + "加入队列成功");
            }
            static void leaveQueue(Queue q)
            {
                //要求从队列中出来一个人,比如接受服务
                var s = q.Dequeue();
                Console.WriteLine(s + "=》接受服务");
            }
    
            static void listQueue(Queue q)
            {
                //输出队列中一共有多少人,并输出每个人名字
                foreach (var s in q) Console.WriteLine(s);
            }
    
            static void Main(string[] args)
            {
                int i = 0;
                Queue q = new Queue(50);
                Console.WriteLine("This is a queue machine." +
                    "You can type the following digits: \n" +
                    "\t1 for entering the queue, \n" +
                    "\t2 for leaving the queue, \n" +
                    "\t3 for listing the members in the queue,\n" +
                    "\t0 for exiting:");
                do
                {
                    i = Convert.ToInt32(Console.ReadLine());
                    if (i == 1)
                    {
                        addQueue(q);
                    }
                    else if (i == 2)
                    {
                        leaveQueue(q);
                    }
                    else if (i == 3)
                    {
                        listQueue(q);
                    }
                    else if (i == 0)
                    {
                        break;
                    }
                    else
                        Console.WriteLine("wrong input");
                } while (true);
            }
        }
    }
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月3日
  • 已采纳回答 9月25日
  • 创建了问题 9月25日

悬赏问题

  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面