I am having problems with the variable named tot_time. I've used cout statements to debug and that's the only variable that is not initializing to zero. It's giving me something like 27000.
Do I need to keep the counter somewhere else? Maybe as a function somewhere? I've looked at this too long and I am stuck.
Thanks for any help or suggestions.
Here's my .cpp file.
Code:
// Constructor that initializes class CompactDisc
CompactDisc::CompactDisc() {
// initialize members
name = " ";
title = " ";
artist = " ";
seconds = 0;
no_of_songs = 0;
tot_time = 0;
track = 0;
total = 0;
}
// Function that adds track to cd
int CompactDisc::AddTrack(String na, int sec) {
seconds = sec;
name = na;
tot_time = tot_time + seconds;
if ((tot_time >= 4440) || (no_of_songs > 10)) {
tot_time = tot_time - seconds;
return 0;
}
else {
no_of_songs += 1;
array[no_of_songs] = name;
array_sec[no_of_songs] = seconds;
return 1;
}
}
Here's my .h file.
Code:
class CompactDisc {
public:
CompactDisc(); //constructor
CompactDisc(String, String); //constructor that takes artist and title of album
int AddTrack(String, int); //adds track and returns value of 1 if doesn't exceed limits
void PrintTrack(int); // accepts track number to print
int TrackCount(); // returns # of tracks added to cd
int track; // counter for track #
int total;
private:
String title; //title of album
String artist; //artist of album
String name; //name of song
int seconds; //time
String array [10]; // array to store songs for corresponding track #
int array_sec[10]; // array to store times for each song
int tot_time; // counter for total time on compact disc
int no_of_songs; // index for array that holds number of songs on compact disc
};