I think it is time to look into "How to get trackinfo".
I did an update to my code:
Code:
#include <iostream>
#include <vector>
#include <string>
// You may not modify XTrackInfo
class XTrackInfo
{
std::string m_TrackName;
int m_Length;
public:
XTrackInfo() {}
XTrackInfo(std::string TrackName, int Length):
m_TrackName(std::move(TrackName)),
m_Length(Length)
{}
void SetTrackName(std::string TrackName) { m_TrackName = std::move(TrackName); }
void SetTrackLength(int Length) { m_Length = Length; }
const std::string& GetTrackName() const { return m_TrackName; }
int GetTrackLength() const { return m_Length; }
};
class XMusicCd
{
private:
// You may not modify these member variables
std::string m_Author;
std::vector<XTrackInfo> m_TrackInfo;
public:
// You may not modify these member functions
XMusicCd() {}
XMusicCd(std::string Author, std::vector<XTrackInfo> Tracks):
m_Author(std::move(Author)),
m_TrackInfo(std::move(Tracks))
{}
void SetAuthor(std::string Author) { m_Author = std::move(Author); }
const std::string& GetAuthor() const { return m_Author; }
XTrackInfo GetTracks(Tracks) const{}
int GetLength() const; // Left incomplete on purpose; you will implement it later
void AddTrack(XTrackInfo NewTrack){
//m_TrackInfo.emplace_back(NewTrack.GetTrackName(),NewTrack.GetTrackLength());
m_TrackInfo.emplace_back(std::move(NewTrack));
}
// Add additional functions to this class as necessary to make it compile.
};
void PrintCdContents(const XMusicCd& Cd)
{
// Implement this function such that it compiles
// Also, to be explicit, you may not add any tracks to the CD in here. That is not the purpose of this function. You may also not change the signature of the function.
// You shall specifically not modify the CD object by calling any setters.
//Cd.
std::cout << "Author : " << Cd.GetAuthor() << "\n";
std::cout << "\n" << std::endl;
std::cout << "Track Info" << std::endl;
for (auto it = NewTrack.begin(), end = NewTrack.end(); it != end; ++it)
{
std::cout << *it << " ";
}
// How can I acess the trackinfo vector inside of Cd class?
//
}
int main()
{
// You may not change this function
XMusicCd MyCd;
MyCd.SetAuthor("Hello World");
MyCd.AddTrack(XTrackInfo("This is a test", 100));
MyCd.AddTrack(XTrackInfo("This is a test 2", 200));
PrintCdContents(MyCd);
}
It doesn't work, why? I don't figure out how can I create an acessor to the Tracks vector which belongs to cd class.
I think that I need to create a function getTracks which will return the Track contents. Probably the function type will be XTrackInfo type.