I have a program that is a crude CD database. It first asks the user to enter a CD name in which it stores into a list, then at the users on accord they can enter an artist name into another list that is a list of the CD name. So its a list of a list. I think I have it working correct but I am always open for opinions on improvment. Anyways what I am working on at the moment is giving the user the option to search out a CD from the list and display back that CD name and artist. Hear is what I have so far..
This is in a Class called Controller
Code:
//Adds Artist Name
void Controller::AddArtBandName() {
string artName;
cout << endl << "Enter the bands name: " << flush;
cin >> artName;
myArtist.push_back( (artName));
cout << "\tAdded : " << artName << endl << endl ;
}
//Displays Artist List
void Controller::DisplayArtistList(){
cout << endl << "List of Artist: " << endl;
list<Artist>::iterator iter;
for(iter = myArtist.begin(); iter != myArtist.end(); iter++)
{
cout << (*iter).getArtBandName()<<endl;
(*iter).DisplayCdList();
}
}
void Controller::FindCd(){
string search;
cout <<" Enter name of CD you want to find " << endl;
cout <<" WARNING " << endl;
cout <<" THIS SEARCH IS CASE SENSITIVE " << endl;
cin >> search;
}
this is in a class called Artist
Code:
//Adds Cd Name
void Artist::AddCdName(){
string cdName;
cout << "Enter Cd's Name:" << flush;
cin >> cdName;
myCdInfo.push_back(CdInfo(cdName));
cout << "\tAdded : " << cdName << endl << endl;
OptionArtistInfo();
}
//Display Cd List
void Artist::DisplayCdList(){
cout << endl << "Cd List:" << endl;
list<CdInfo>::iterator iter;
for(iter = myCdInfo.begin(); iter != myCdInfo.end(); iter++)
cout << (*iter).getCdName() << endl;
}
void Artist::OptionArtistInfo(){
int input;
cout << "Would you like to add Artist info for the cd : " << endl;
cout << "\tType 1 for yes or 2 for no : " << flush;
cin >> input;
switch (input)
{
case 1:
cout << endl << "Enter the bands name: " << flush;
cin >> artName;
break;
case 2:
cout << "Returning to main menu" << endl;
break;
default:
cout << input << " : Is not a valid command" << endl;
cout << " 1 and 2 are valid commands " << endl;
}
}
The FindCd function in the Controller class is were I am trying to search through the Cd list and find a Cd based on the users input. For now I just want it to display back that Cd and the Artist Name associated with it. To be honest I have no clue how to go about this. I am guessing a for if loop of some sorts. Can anyone help put me on the correct path.....
Thanks
Chad