Thread: Displaying values from one class in another...

  1. #1
    System-7
    Join Date
    Nov 2005
    Posts
    65

    Exclamation Displaying values from one class in another...

    I've created these two classes and I have to display the information that is in the first class. I am unsure as how to do this since it is contained in the private part of the class. I want to go and display the cPRODUCT's private info in the cINVENTORY class's addProduct() method.

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    class cPRODUCT
    {
    	private:
    		long nSerialNum;
    		string ProductDesc;
    		float fWholesale;
    		float fRetailcost;
    		int nInStock;
    	public:
    		cPRODUCT(void) 
    		{ 
    			nSerialNum = 0;
    			ProductDesc = "";
    			fWholesale = 0;
    			fRetailcost = 0;
    			nInStock = 0;
    		}
    		void enterProdInfo(void)
    		{
    			const int MINIMUM_SERIAL_NUMBER = 100000;
    			const int MAXIMUM_SERIAL_NUMBER = 999999;
    			cout << "Please enter the product's six digit serial number: ";
    			cin >> nSerialNum;	
    
    			cout << "Please enter the product description: ";
    			cin >> ProductDesc;
    
    			cout << "Please enter the wholesale price: ";
    			cin >> fWholesale;
    	
    			
    			cout << "Please enter an appropriate amount: ";
    			cin >> fWholesale;
    			}	
    
    			cout << "Please enter the number of items in stock: ";
    			cin >> nInStock;
    		}
    		float calcRetail(void)
    		{	
    			return fRetailcost;
    		}
    		void displayProd(void)
    		{
    			cout << ProductDesc;
    		}
    		float getWholesale(void)
    		{
    			return fWholesale;
    		}
    		int getInStock(void)
    		{
    			return nInStock;
    		}
    		bool isExpensive(void)
    		{
    		}
    };
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    class cINVENTORY
    {
    	private: 
    		cPRODUCT Products[100];
    		short nNumProdTypes;
    		float fTotalWhole;
    		float fTotalRetail;
    		int nOverallItems;
    	public:
    		cINVENTORY(void)
    		{
    			Products[100];
    			nNumProdTypes = 0;
    			fTotalWhole = 0;
    			fTotalRetail = 0;
    			nOverallItems = 0;
    		}
    		void addProduct(int* i, float* fTotalWhole)
    		{
    			float fWholesaleCost = 0;
    			
    			//Fill the Products array
    			Products[*i].enterProdInfo();
    			nNumProdTypes++;
    
    			//Do Calculations (Total Wholesale, Retail, and InStock)
    			fWholesaleCost = Products[*i].getWholesale();
    			*fTotalWhole += fWholesaleCost;
    		}
    		void resetInventory()
    		{	
    		}
    		void displayInventory(int* i)
    		{
    		}
    };
    I really appreciate any help you guys can give.

    Thanks,

    ...Dan

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Can't you just create a display member function in cProduct and call that from cInventory?
    Code:
    for (int i=0; i<nOverallItems; i++)
    {
       Products[i].Display();
    }

  3. #3
    System-7
    Join Date
    Nov 2005
    Posts
    65
    i keep on missing these simple solutions, lol. Thanks for the help. First time with classes, so hard to get used to the whole private, public thing.

    ...Dan

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  2. Replies: 3
    Last Post: 10-31-2005, 12:05 PM
  3. Displaying my glut output in my own class window.
    By Queatrix in forum Windows Programming
    Replies: 0
    Last Post: 10-19-2005, 10:09 AM
  4. Displaying numerical values in a window
    By drb2k2 in forum C++ Programming
    Replies: 1
    Last Post: 04-08-2003, 12:05 PM