Hi there,

I'm trying to write a program to accept some details about mp3 files, and store them in an array. I am also hoping to process some of the parameters of each entry to the array.
I am trying to create an object of type "Track", and then define a method "createTrack" to define some parameters to describe the Object "Track". This is what I've come up with, but needless to say, it doesn't work! :( If anyone could suggest some adjustments, it would be much appreciated!

#include<iostream>
#include<string>
 
using namespace std;
using std::string;
 
class Track{


public:

	Track(void);
		
	void time();
	void createTrack();

};

void Track::createTrack()
{
	string title;
	string artist;
	float duration;

	cout <<"Please enter track title: ";
	cin >> title;

	cout <<"Please enter track artist: ";
	cin >> artist;

	cout <<"Please enter track duration in seconds: ";
	cin >> duration;
}

void Track:time(int duration)
{

	mins = (duration/60);

	secs = (duration%60);

	cout << "The track time is: " << mins << "minutes and" << secs << "seconds" << endl;
}


int main()
{

	for (int i=0; i<5; i++) 
	{
		Track a; //Create a new object of type "Track"
		TrackArray[i] = a.createTrack;	//Call the "createTrack" method on the object 
	}									//"a" and store it in the array "TrackArray[4]"

	TrackArray[1].time;	//Call the "time" method on the 1th entry of the array

	system("Pause");
	return EXIT_SUCCESS;
}

Recommended Answers

All 4 Replies

You can get rid of the line Track(void); Move the following three lines: string title; string artist; float duration; to between the two lines: class Track { and public: Since duration is in seconds, it should probably be int, not float.

Make your time function match its prototype: void Track::time() In main(), declare your track array variable: Track TrackArray[ 5 ]; Get rid of: Track a; and make the next line read: TrackArray[i].createTrack(); Finally, when you call the time() method: TrackArray[1].time(); Your problems are mostly syntactical, but you should also read some more on creating and using classes. Try to find examples (there're tons on the internet).

Hope this helps.

Hi Duoas,

Thanks for your help. I made the changes like you said and it compiled with no errors and just one warning about missing arguement list for:

TrackArray[i].createTrack;

I also had to comment out:

TrackArray[1].time();

as no "Track" objects had been created.

While the program runs, the "createTrack" method isn't implemented:?: . Can you or anyone see why?
Thanks again for your help Duoas,
Ger.

I got it, I wasn't including a constructor for Track.

Apologies for Another post, I didn't mark the last one as a solution. Happy C++'ing! ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.