Question
The Test File: The code: #include #include #include #include json.hpp using namespace std; using json = nlohmann::json; //// const std::string DATA_FILE_PATH = TestData; namespace MusicMachine
The Test File:
The code:
#include
using namespace std; using json = nlohmann::json;
//// const std::string DATA_FILE_PATH = "TestData\\";
namespace MusicMachine { // Music_Type enum class enum class MUSIC_TYPE { UNKNOWN, CHAMBER, ORCHESTRAL, ROCK, ELECTRONIC, POP, JAZZ, BLUES }; enum class TEMPO { UNKNOWN, SLOW, FAST }; enum class IMPROVISATION { UNKNOWN, SOLO, COLLECTIVE };
enum class VOLUME { NA, QUITE, LOUD, VERYLOUD };
// Music class class Music { public: Music(json& j, MUSIC_TYPE type, TEMPO tempo); MUSIC_TYPE GetMusicType() const; bool IsTempoFast() const; void Play() const; string PrettyPrintClassAttributes() const; protected: string ArtistName; string Location; MUSIC_TYPE MusicType; string Orgin; TEMPO Tempo; };
// Classical class (inherits from Music) class Classical : public Music { public: Classical(json& j, MUSIC_TYPE type, TEMPO tempo); void Play() const; string PrettyPrintClassAttributes() const; private: string Key; string PieceName; };
// NonClassical class (inherits from Music) class NonClassical : public Music { public: NonClassical(json& j, MUSIC_TYPE type, TEMPO tempo); void Play() const; string PrettyPrintClassAttributes() const; private: string SongName; };
// Chamber class (inherits from Classical) class Chamber : public Classical { public: Chamber(json& j); void Play() const; string PrettyPrintClassAttributes() const; private: struct Instrument { string One; string Two; string Three; string Four; }; Instrument Instruments; };
// Orchestral class (inherits from Classical) class Orchestral : public Classical { public: Orchestral(json& j); void Play() const; string PrettyPrintClassAttributes() const; private: vector
class Pop : public NonClassical { public: Pop(json& j); void Play() const; string PrettyPrintClassAttributes() const; private: std::string DateOFRanking; int Top40Ranking; };
class Jazz : public NonClassical { public: Jazz(json& j); void Play() const; string PrettyPrintClassAttributes() const; private: IMPROVISATION Improvisation; };
class Rock : public NonClassical { public: Rock(json& j); void Play() const; std::string PrettyPrintClassAttributes() const; private: int Expletive; bool GuitarsOnly; VOLUME Volume; std::string VolumeToString() const; };
class Electronic : public NonClassical { public: Electronic(json& j); void Play() const; std::string PrettyPrintClassAttributes() const; private: int BeatsPerMinute; };
class Machine { public: const vector
const vector
Machine(string filename);
size_t Parse() const;
private: json jf; vector
}
// //////////////////////////////////////////////////////////////////////////////////////////////// #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include "doctest.h" TEST_CASE("Testing my Music Machine") { SUBCASE("testing the parsing of file - JsonObject6a.json") {
MusicMachine::Machine m(DATA_FILE_PATH + "JsonObject6a.json");
// Invoke the parsing process
CHECK(m.Parse() == 6);
/// Chamber
vector<:chamber> ChamberSongs = m.GetChamberSongs(); for (auto& cs : ChamberSongs) { cs.Play(); cout
/// Orchestral
vector<: orchestral> OrchestralSongs = m.GetOrchestralSongs(); for (auto& cs : OrchestralSongs) { cs.Play(); cout
/// Pop
vector<: pop> PopSongs = m.GetPopSongs(); for (auto& cs : PopSongs) { cs.Play(); cout
/// Jazz
vector<: jazz> JazzSongs = m.GetJazzSongs(); for (auto& cs : JazzSongs) { cs.Play(); cout
/// Rock
vector<: rock> RockSongs = m.GetRockSongs(); for (auto& cs : RockSongs) { cs.Play(); cout
/// Electronic vector<:electronic> ElectroinicSongs = m.GetElectronicSongs(); for(auto& cs : ElectroinicSongs) { cs.Play(); cout
} }
The output:
Notes
There should be 1 test case pass and 13 assertion passed and status would be SUCCESS All code is to be developed in main.cpp. No additional header files will be accepted. Notice the output of both the Play and PrettyPrintClassAttributes member functions. Note: PrettyPrintClassAttributes does not print but returns a string to be printed. Also do not use algrothim header
Playing Chamber music... Tchaikovsky Russia,https://chamber.music.example.com,String Quartet No. 1,G minor Violin Cello.Flute,Bassoona Playing Orchestral music... Beethoven,Germany,htttps://orchestral.music,example.com,Symphony No.5,C minocilielin Viola Timpani,Snare drum. Cymbals.Xylophene French hero, Piano, Hare Playing Pop music... Justin Beiber,United States,https//pop.music.example.com,Ghost,02/12/2022,12 Playing Jazz music... Miles Davis.United States,https://rock.music.example.com,School's Out,0,Loud Playing Electronic music... Kraftwerk,Germany,https://electronic.music.example.com,Prologue,141Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started