Last week I was trying to figure out how to declare a list global in my .h files. Well thanks to some help hear I figured out that problem, but now have come across a whole new one. Since then I realized I needed to overhaul my whole program. What I am trying to accomplish is to be able to make list of CD names and then a artist that is directly related to that CD. So what I have come up with is a list of a list.
This is my Control file
Code:
#include "CdInfo.h"
#include "Controller.h"
#include "Artist.h"
#include "Menu.h"
#include "SubMenu.h"
#include <iostream>
#include <string>
using namespace std;
//*********************MAIN*CONTROL********************
//Takes input from user and processes it
void Controller::CommandControl(int input)
{
Menu menu;
Artist artist;
if (input == 1)
{
menu.Info(); //Displays info about program
}
else if (input == 2)
{
CdInfoMenu();
}
else if (input == 3)
{
cout << "Goodbye" << endl; //End Program
}
else if (input == 4)
{
DisplayArtistList();
}
else
{
cout << input << ": is not a valid command" << endl;
}
}
//*******************CD*INFO**********************
//Takes input from user (CdInfo) and processes it
void Controller::CdInfoMenu()
{
int input;
Menu menu;
Artist artist;
SubMenu submenu;
submenu.CdInfo();
cout << endl << "Enter your choose from the Cd Info Menu now:" << flush;
cin >> input;
if (input == 1)
{
artist.AddCdName();
myArtist.push_back(artist);
DisplayArtistList();
}
else if (input == 2)
{
DisplayArtistList();
}
else if (input == 3)
{
menu.MainMenu();
}
else
{
cout << input << ": is not a valid command" << endl;
}
}
//********************ARTIST**********************
//Adds Artist Name
void Controller::AddArtBandName()
{
string artName;
cout << endl << "Enter the bands name: " << flush;
cin >> artName;
Artist *artist = new Artist(artName);
myArtist.push_back( *(new Artist(artName)) );
//Informs user what they just added
cout << "\tAdded : " << artName << endl << endl ;
}
Controller::Controller()
{
}
And this is my Artist file
Code:
#include "Artist.h"
#include "Controller.h"
#include <iostream>
#include <string>
#include "Controller.h"
// Constructor
Artist::Artist(string lv_artName)
{
artName = lv_artName;
}
//Default Constructor
Artist::Artist(void)
{
}
//Holds artName
void Artist::setArtBandName(string lv_artName)
{
artName = lv_artName;
}
string Artist::getArtBandName()
{
return artName;
}
//Adds Cd Name
void Artist::AddCdName()
{
string cdName;
cout << "Enter Cd's Name:" << flush;
cin >> cdName;
CdInfo *cdInfo = new CdInfo(cdName);
myCdInfo.push_back( *(new 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;
//A do while loop might be needed
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;
}
}
UPDATE...
So I have messed around a little and this is what I (and the help from someone else) have come up with. Everything compiles and runs, but when I start to add to the list more then it displays back in a very weird manner. I have checked over everything and still can't come up with the reason why. When it displays back it show multiple instances of the CD list with user data in the wrong place. Any suggestions......
Thanks
Chad