写一个ktv点歌代码
时间: 2024-02-12 15:05:05 浏览: 28
好的,这里是一个简单的KTV点歌系统的C#代码示例:
```csharp
using System;
using System.Collections.Generic;
namespace KTVSongSystem
{
class Song
{
public string Name { get; set; }
public string Singer { get; set; }
public string Language { get; set; }
public int Popularity { get; set; }
public Song(string name, string singer, string language, int popularity)
{
Name = name;
Singer = singer;
Language = language;
Popularity = popularity;
}
public override string ToString()
{
return $"{Name} - {Singer} ({Language})";
}
}
class Program
{
static void Main(string[] args)
{
// 初始化歌曲列表
List<Song> songList = new List<Song>
{
new Song("告白气球", "周杰伦", "中文", 100),
new Song("Shape of You", "Ed Sheeran", "英文", 90),
new Song("Lemon", "米津玄师", "日文", 80),
new Song("좋은 날", "IU", "韩文", 70)
};
while (true)
{
// 显示菜单
Console.WriteLine("KTV点歌系统");
Console.WriteLine("1. 按名称点歌");
Console.WriteLine("2. 按歌手点歌");
Console.WriteLine("3. 按语种点歌");
Console.WriteLine("4. 按热度点歌");
Console.WriteLine("5. 退出");
// 处理用户输入
string choice = Console.ReadLine();
if (choice == "1")
{
Console.Write("请输入歌曲名称:");
string name = Console.ReadLine();
foreach (Song song in songList)
{
if (song.Name == name)
{
Console.WriteLine($"已点歌曲:{song}");
break;
}
}
}
else if (choice == "2")
{
Console.Write("请输入歌手名称:");
string singer = Console.ReadLine();
foreach (Song song in songList)
{
if (song.Singer == singer)
{
Console.WriteLine($"已点歌曲:{song}");
}
}
}
else if (choice == "3")
{
Console.Write("请输入语种名称:");
string language = Console.ReadLine();
foreach (Song song in songList)
{
if (song.Language == language)
{
Console.WriteLine($"已点歌曲:{song}");
}
}
}
else if (choice == "4")
{
Console.WriteLine("按热度排序:");
songList.Sort((x, y) => y.Popularity.CompareTo(x.Popularity));
for (int i = 0; i < songList.Count; i++)
{
Console.WriteLine($"{i+1}. {songList[i]}");
}
Console.Write("请选择要点播的歌曲序号:");
int index = int.Parse(Console.ReadLine()) - 1;
Console.WriteLine($"已点歌曲:{songList[index]}");
}
else if (choice == "5")
{
Console.WriteLine("感谢使用KTV点歌系统!");
break;
}
else
{
Console.WriteLine("无效输入,请重新输入!");
}
}
}
}
}
```
这个示例实现了一个基本的KTV点歌系统,用户可以按名称、歌手、语种、热度来点歌。歌曲列表和点播记录都保存在内存中,可以根据需要进行扩展。请注意,这只是一个简单的示例,实际的KTV点歌系统需要更复杂的功能和更严格的数据管理。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)