some songs

  Recently, i feel great love in YiFeng Lin's songs. his songs are quit personality, and good taste, what is more, the songs are all talking about sth common without commercialize. i love the style

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是用 C++ 实现音乐信息管理系统的代码示例: ``` #include <iostream> #include <vector> #include <algorithm> using namespace std; struct Song { string name; string singer; string creator; string category; string year; string style; int likes; int play_count; }; class MusicLibrary { vector<Song> songs; vector<Song> favorites; public: void addSong(Song song) { songs.push_back(song); } void removeSong(int index) { songs.erase(songs.begin() + index); } void updateSong(int index, Song song) { songs[index] = song; } vector<Song> searchSong(string keyword) { vector<Song> result; for (Song song : songs) { if (song.name.find(keyword) != string::npos || song.singer.find(keyword) != string::npos || song.category.find(keyword) != string::npos || song.year.find(keyword) != string::npos || song.style.find(keyword) != string::npos) { result.push_back(song); } } return result; } vector<Song> sortBySongName() { vector<Song> result = songs; sort(result.begin(), result.end(), [](const Song& a, const Song& b) { return a.name < b.name; }); return result; } void viewAllSongs(bool showAllInfo) { for (Song song : songs) { if (showAllInfo) { cout << "Name: " << song.name << endl; cout << "Singer: " << song.singer << endl; cout << "Creator: " << song.creator << endl; cout << "Category: " << song.category << endl; cout << "Year: " << song.year << endl; cout << "Style: " << song.style << endl; cout << "Likes: " << song.likes << endl; cout << "Play Count: " << song.play_count << endl; } else { cout << song.name << " - " << song.singer << endl; } } } void addSongToFavorites(int index) { favorites.push_back(songs[index]); } void removeSongFromFavorites(int index) { favorites.erase(favorites.begin() + index); } vector<Song> searchSongInFavorites(string keyword) { vector<Song> result; for (Song song : favorites) { if (song.name.find(keyword) != string::npos || song.singer.find(keyword) != string::npos || song.category.find(keyword) != string::npos || song.year.find(keyword) != string::npos || song.style.find(keyword) != string::npos) { result.push_back(song); } } return result; } vector<Song> sortByPlayCount() { vector<Song> result = songs; sort(result.begin(), result.end(), [](const Song& a, const Song& b) { return a.play_count > b.play_count; }); return result; } }; int main() { MusicLibrary library; // Add some songs to the library Song song1 = {"Song 1", "Singer 1", "Creator 1", "Category 1", "Year 1", "Style 1", 10, 100}; Song song2 = {"Song 2", "Singer 2", "Creator 2", "Category 2", "Year 2", "Style 2", 20, 200}; Song song3 = {"Song 3", "Singer 3", "Creator 3", "Category 3", "Year 3", "Style 3", 30, 300}; library.addSong(song1); library.addSong(song2); library.addSong(song3); // Search for a song vector<Song> searchResult = library.searchSong("2"); cout << "Search Result:" << endl; for (Song song : searchResult) { cout << song.name << " - " << song.singer << endl; } cout << endl; // Sort songs by name vector<Song> sortedBySongName = library.sortBySongName(); cout << "Songs sorted by name:" << endl; for (Song song : sortedBySongName) { cout << song.name << " - " << song.singer << endl; } cout << endl; // View all songs cout << "All songs:" << endl; library.viewAllSongs(false); cout << endl; // Add a song to favorites library.addSongToFavorites(0); cout << "Favorites:" << endl; for (Song song : library.searchSongInFavorites("")) { cout << song.name << " - " << song.singer << endl; } cout << endl; // Remove a song from favorites library.removeSongFromFavorites(0); cout << "Favorites:" << endl; for (Song song : library.searchSongInFavorites("")) { cout << song.name << " - " << song.singer << endl; } cout << endl; // Sort songs by play count vector<Song> sortedByPlayCount = library.sortByPlayCount(); cout << "Songs sorted by play count:" << endl; for (Song song : sortedByPlayCount) { cout << song.name << " - " << song.play_count << endl; } cout << endl; return 0; } ``` 在这个示例代码中,我们定义了一个Song结构体来表示每首歌曲的信息,以及一个MusicLibrary类来管理所有的歌曲和收藏夹。MusicLibrary类中实现了增、删、改、查、排序、浏览等功能,以及收藏夹的相关操作。我们在main函数中使用这个类来演示了这些功能的使用。 请注意,这只是一个示例代码,您可能需要根据自己的需求进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值