I am back with another <list> question....

This is a discussion on I am back with another <list> question.... within the C++ Programming forums, part of the General Programming Boards category; Last week I was trying to figure out how to declare a list global in my .h files. Well thanks ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    131

    Another <list> question....

    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
    Last edited by chadsxe; 07-12-2005 at 12:52 PM. Reason: Updated code.....

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    131
    Updated...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hey guys, back again with a question
    By Velocity in forum C++ Programming
    Replies: 10
    Last Post: 10-19-2008, 02:27 PM
  2. Windows Rant followed by installation question
    By confuted in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 06-21-2003, 04:42 PM
  3. Question????
    By gvector1 in forum C++ Programming
    Replies: 5
    Last Post: 04-18-2003, 11:04 AM
  4. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 02:57 PM
  5. Question type program for beginners
    By Kirdra in forum C++ Programming
    Replies: 7
    Last Post: 09-15-2002, 05:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21