how to put classes into a 2d array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HarisHohkl
    New Member
    • Jan 2007
    • 8

    how to put classes into a 2d array

    Hi, my programme using visual C++ need 3 classes, 1 for 'item tv', 1 for 'shelf' and the other 'warehouse'. The 'item tv' class will update and display the item number, description, cost and qty of 3 tv. The shelf will capture the item no. and qty of any of the 3 tv of the "item class " and ask where to put the item in the 2D array. It will then display the 2D array, add up the total qty and the cost. The warehouse class will have a address using dymanic menory to create a new address and display the address. How shall i being....Thank
  • macklin01
    New Member
    • Aug 2005
    • 145

    #2
    Well, if you look at the BMP object in EasyBMP.cpp in my EasyBMP C++ bitmap library, you'll find that the pixels are a 2-D array of ebmpBYTE structs:

    Code:
    BMP
    {
     private:
      ebmpBYTE** Pixels;
      // ... 
    };
    I'd recommend studying that example. While the ebmpBYTE's are structs and not objects, the idea is exactly the same. Incidentally, it's also the same as doing a 2-D array of double's or any other type.

    One thing I suppose you'll need to be careful of, however, is that your default constructor and destructor functions for your item class are properly-debugged.

    Best of luck! :) -- Paul

    Comment

    • horace1
      Recognized Expert Top Contributor
      • Nov 2006
      • 1510

      #3
      Originally posted by HarisHohkl
      Hi, my programme using visual C++ need 3 classes, 1 for 'item tv', 1 for 'shelf' and the other 'warehouse'. The 'item tv' class will update and display the item number, description, cost and qty of 3 tv. The shelf will capture the item no. and qty of any of the 3 tv of the "item class " and ask where to put the item in the 2D array. It will then display the 2D array, add up the total qty and the cost. The warehouse class will have a address using dymanic menory to create a new address and display the address. How shall i being....Thank
      implement and test each class in turn, i.e. implement and test tv, when that is working shelf then warehouse, etc. in this way you build a working system knowning that each component it tested and working before you move to the next.

      Comment

      • macklin01
        New Member
        • Aug 2005
        • 145

        #4
        Originally posted by horace1
        implement and test each class in turn, i.e. implement and test tv, when that is working shelf then warehouse, etc. in this way you build a working system knowning that each component it tested and working before you move to the next.
        Best advice I've seen all day! (And way better than mine!) :) -- Paul

        Comment

        • HarisHohkl
          New Member
          • Jan 2007
          • 8

          #5
          Originally posted by horace1
          implement and test each class in turn, i.e. implement and test tv, when that is working shelf then warehouse, etc. in this way you build a working system knowning that each component it tested and working before you move to the next.
          Hi, i have done up my programme, need ur advice on how can i capture the tv classes data and put it to the shelf. is there any way i can sent the code to u?

          Comment

          • HarisHohkl
            New Member
            • Jan 2007
            • 8

            #6
            I've done up the programme, need help to fine tune it, as the shelf classes cannot receive data from the item classes. my shelf classes need to capture the item no and cost of the 3 TV items. Thanks for the time in viewing

            Code:
            #include <iostream.h>
            #include <iomanip.h>
            #include <string.h>
            #include <process.h>
            #include <cstdlib>
            #include <windows.h>
            
            #define  row  5
            #define  col  10
            	 
            										  
            																				  
            class TV												  
            { 
            	int itemno;
            	char description[100];	
            	char model[100];																  
            	double cost;
            	
            	
            															
            public :
            	
            	//	this function will prompt user to key in details
            	
            	void update()
            
            	{	
            		cout << " "<< endl;
            		cout <<"\t"<< "Enter item no: ";
            		cin >>itemno;
            		cout <<"\t"<< "Enter description: ";
            		cin.ignore();
            		cin.getline( description, 100 );
            		cout <<"\t"<<"Enter model: ";
            		cin.getline( model, 100 );
            		cout <<"\t"<< "Enter cost: $";
            		cin >> cost;
            		
            	}
            
            	void display_item()
            
            	{	
            		cout << " "<< endl;
            		cout <<"\t"<< "Item no: " << itemno << endl;
            		cout <<"\t"<< "Description of item: " << description << endl;
            		cout <<"\t"<< "Model: "<<model<<endl;
            		cout <<"\t"<< "Cost of item: $ " << cost << endl;
            		cout << " "<< endl;
            		system("PAUSE");
            	}
            };
            
            
            class shelf
            {	
            	int  warehouseshelf[row][col];
            	double totalcost;
            	int itemno;
            	int quantity;
            
            public:
            	
            	//function to initial all array to 0
            
            	void initial()
            
            	{	
            		int r, c;
            
            		for( r=0; r<5; r++ )
            		{
            			for( c=0; c<10;c++ )
            			{
            				warehouseshelf[r][c] = 0;
            			}
            		}
            	}
            		
            	//	this function will update the shelf quantity
            	
            	void update_shelfs()
            		  
            	{	
            		int i, numitems, r , c, quantity;
            		
            		cout << " "<< endl;
            		cout <<"\t"<< "Enter no of item to update: ";                  
            		cin >> numitems;
            
            	
            		for( i= 0; i < numitems; i++ ) 	  
            		{
            			cout <<"\t"<< "Enter which row to update for item: ";            
            			cin >> r;
            
            			cout <<"\t"<< "Enter which column to update for item: "; 										   		  
            			cin >> c;
            	 
            			cout <<"\t"<< "Enter no of quantity to update for item: ";    	 
            	
            			cin >> quantity;
            							   	  
            			warehouseshelf[r][c] = quantity;								  
            	
            		}
            		
            		cout <<"\t"<< "Update completed................." << endl;
            		
            		system("PAUSE");
            
            	}	
            	
            	void display_shelfs()
            
            	{	
            		int r, c;
            		
            		for( r=0; r<5; r++ )
            
            		{
            			for( c=0; c<10; c++ )
            			{
            				cout <<"\t"<<warehouseshelf[r][c]<<"\t";				
            			}
            		}
            		cout << " "<< endl;
            		system("PAUSE");
            	}
            
            	void display_total_all_items_stored()
            
            	{	
            		int sum  = 0;
            		int r, c;									   
            		double cost;
            		for( r=0; r<5; r++ )
            		{
            			for( c=0; c<10; c ++ )
            			{
            				sum = sum + warehouseshelf[r][c];
            				totalcost= sum*cost;
            			}
            		}
            		
            		cout <<"\t"<< "Total sum of items is = " << sum << endl;
            			system("PAUSE");
            	}
            
            	void display_total_value()
            	{
            		cout <<"\t"<< "Total value is = $" << totalcost << endl;
            		system("PAUSE");
            	}
            };
            
            class warehouse
            {
            
            public:
            
            		// function to update address
            
            	char *update_address (void)
            	{	
            		char tempaddress[200];
            		cout <<"\t"<< "Enter address: ";
            		cin.getline (tempaddress, 200);
            		cout << " "<< endl;
            		cout <<"\t"<<"Address for the warehouse is "<<tempaddress <<endl;
            		cout << " "<< endl;
            		int size = strlen (tempaddress);
            		char *test = new char[size];
            		strcpy (test, tempaddress);
            
            		return test;
            	}
            };
            
            
            	//function to show display menu
            
            	void display_menu()
            
            	{	
            		cout << " "<< endl;
            		cout <<"\t"<< "Select option " << endl;
            		cout <<"\t"<< "-----------------------" << endl;
            		cout <<"\t"<< "1) Update item details " << endl;
            		cout <<"\t"<< "2) Display item details " << endl;
            		cout <<"\t"<< "3) Update warehouse address" << endl;
            		cout <<"\t"<< "4) Add items to the warehouse shelf" << endl;
            		cout <<"\t"<< "5) Display warehouse detail" << endl;
            		cout <<"\t"<< "6) Find total number of items in warehouse" << endl;
            		cout <<"\t"<< "7) Find total value in warehouse" << endl;
            		cout <<"\t"<< "8) Exit "<<endl;
            		cout <<"\t"<< "-----------------------" << endl;
            		cout <<"\t"<< "Enter option: ";	
            		
            	}
            	
            	void select_choice()
            
            	{	
            		cout << " "<< endl;
            		cout <<"\t"<<"Select TV  "<<endl;
            		cout <<"\t"<< "-----------------------" << endl;
            		cout <<"\t"<<"1 for TV1"<<endl;
            		cout <<"\t"<<"2 for TV2"<<endl;
            		cout <<"\t"<<"3 for TV3"<<endl;
            		cout <<"\t"<< "-----------------------" << endl;
            		cout <<"\t"<< "Enter Brand using 1-3: ";
            	}
            	
            
            
            	
            int main(void)
            {	int i;
            	int choice;
            	char *address;
            
            	
            	TV	brand[3];
            	shelf s1;
            	s1.initial();
            	warehouse w1;
            	
            	
            	do
            	{	
            		system("cls");
            		display_menu();
            		cin >> choice;
            		cin.ignore();
            		switch( choice )
            		{	
            			case 1:	system("cls");
            								
            					{	cout << " "<< endl;
            						cout <<"\t"<<"Update item details" << endl;
            						cout <<"\t"<<"-----------------------"<<endl;
            						select_choice();
            						
            						do 
            						{	
            							cin >>i;
            				 
            							if (i==0||i>3)
            								{	
            									cout <<" "<<endl;
            									cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
            								}
            							else 
            								{
            									brand[i-1].update();
            								}
            						}
            						while (i==0||i>3);
            					}
            				
            			break;
            
            			case 2:	system("cls");
            
            				{	cout << " "<< endl;
            					cout <<"\t"<<"Display item details" << endl;
            					cout <<"\t"<<"-----------------------"<<endl;
            					select_choice();
            
            				do 
            					{
            						cin >>i;
            				 
            						if (i==0||i>3)
            							{	
            								cout <<" "<<endl;
            								cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
            							}
            						else 
            							{
            								brand[i-1].display_item();
            							}
            					}
            				while (i==0||i>3);
            				}
            
            			break;
            
            			case 3:	system("cls");
            
            				cout << " "<< endl;
            				cout <<"\t"<<"Update address" << endl;
            				cout <<"\t"<<"-----------------------"<<endl;
            				cout <<" "<<endl;				
            				address = w1.update_address();
            				system("PAUSE");
            				//cout<< address << endl;
            				break;
            
            			case 4:	system("cls");
            
            				{	cout << " "<< endl;
            					cout <<"\t"<<"Update Warehouse Shelfs" << endl;
            					cout <<"\t"<<"-----------------------"<<endl;
            					select_choice();
            				do 
            					{
            						cin >>i;
            				 
            						if (i==0||i>3)
            							{	
            								cout <<" "<<endl;
            								cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
            							}
            						else 
            							{	cout << " "<< endl;
            								s1.update_shelfs();
            							}
            					}
            				while (i==0||i>3);
            				}
            
            			break;
            
            			case 5:	system("cls");
            
            				{	cout << " "<< endl;
            					cout <<"\t"<<"Display Warehouse Selfs" << endl;
            					cout <<"\t"<<"-----------------------"<<endl;
            							{	
            								cout << " "<< endl;
            								s1.display_shelfs();
            							}
            				}
            
            			break;
            
            			case 6:	system("cls");
            
            				{	cout << " "<< endl;
            					cout <<"\t"<<"Display Total Items" << endl;
            					cout <<"\t"<<"-----------------------"<<endl;
            			
            							{
            								cout<<" "<<endl;
            								s1.display_total_all_items_stored();
            							}
            				}
            
            			break;
            
            
            			case 7: system("cls");
            
            				{	cout << " "<< endl;
            					cout <<"\t"<<"Display Total Value" << endl;
            					cout <<"\t"<<"-----------------------"<<endl;
            					
            						{
            							cout<<" "<<endl;
            							s1.display_total_value();
            						}
            				
            				}
            
            			break;
            
            
            			case 8: 
            				cout <<" "<<endl;
            				setcolor (12);
            				cout <<"\t"<< "Bye Bye. See you again"<<endl;
            				cout<<" "<<endl;
            			break;
            
            			default:
            				cout<<" "<<endl;
            				setcolor (12);
            				cout <<"\t"<<"Invalid choice.Pls re-enter again"<<endl;
            				system("PAUSE");
            		}
            	}	 while( choice != 8 );
            
            	return 0;
            }
            Last edited by horace1; Jan 28 '07, 04:44 PM. Reason: inserted code tags

            Comment

            • horace1
              Recognized Expert Top Contributor
              • Nov 2006
              • 1510

              #7
              done a few mods to add item to shelf and display same - not sure if this is what you require???
              Code:
              #include <iostream.h>
              #include <iomanip.h>
              #include <string.h>
              #include <process.h>
              #include <cstdlib>
              #include <windows.h>
              
              #define  row  4
              #define  col  5
              	 
              										 																				  
              class TV												  
              { 
              public :  // ** made public for now
              	int itemno;
              	char description[100];	
              	char model[100];																  
              	double cost;
              	int quantity;  // ** added
              	
              															
              public :
              	
              	//	this function will prompt user to key in details
              	
              	void update()
              
              	{	
              		cout << " "<< endl;
              		cout <<"\t"<< "Enter item no: ";
              		cin >>itemno;
              		cout <<"\t"<< "Enter description: ";
              		cin.ignore();
              		cin.getline( description, 100 );
              		cout <<"\t"<<"Enter model: ";
              		cin.getline( model, 100 );
              		cout <<"\t"<< "Enter cost: $";
              		cin >> cost;
              		quantity=0;   // ** initialise
              	}
              
              	void display_item()
              
              	{	
              		cout << " "<< endl;
              		cout <<"\t"<< "Item no: " << itemno << endl;
              		cout <<"\t"<< "Description of item: " << description << endl;
              		cout <<"\t"<< "Model: "<<model<<endl;
              		cout <<"\t"<< "Cost of item: $ " << cost << endl;
              		cout << " "<< endl;
              		system("PAUSE");
              	}
              };
              
              
              class shelf
              {	
              	int  warehouseshelf[row][col];  // ** initialise to 0 here
                  TV  *warehouseshelfTVs[row][col];// ** added TVs
              	double totalcost;
              	int itemno;
              	int quantity;
              
              public:
              void initial()
              	{	
              		int r, c;
              		for( r=0; r<row; r++ )
              			for( c=0; c<col;c++ )
              				{ warehouseshelf[r][c] = 0; warehouseshelfTVs[r][c] = (TV *) 0; }
              	}
              			
              	//	this function will update the shelf quantity
              	
              	void update_shelfs(TV *brand)
              		  
              	{	
              		int i, numitems, r , c, quantity;
              		
              		cout << " "<< endl;
              	//	cout <<"\t"<< "Enter no of item to update: ";        ** what is this for?          
              	//	cin >> numitems;
              	
              	//	for( i= 0; i < numitems; i++ ) 	  
              		{
              			cout <<"\t"<< "Enter which row to update for item: ";            
              			cin >> r;
              
              			cout <<"\t"<< "Enter which column to update for item: "; 										   		  
              			cin >> c;
              	 
              			cout <<"\t"<< "Enter no of quantity to update for item: ";    	 
              	
              			cin >> quantity;
              						   	  
                          warehouseshelfTVs[r][c]=brand;   // ** added TV to shelf
              			warehouseshelf[r][c] = quantity;								  
              	
              		}
              		
              		cout <<"\t"<< "Update completed................." << endl;
              		
              		system("PAUSE");
              
              	}	
              	
              	void display_shelfs()
              
              	{	
              		int r, c;
              		
              		for( r=0; r<row; r++ )
              
              		{
              			for( c=0; c<col; c++ )
              			{
                           if(warehouseshelfTVs[r][c] == 0)         // ** check if item on shelf
                           	cout <<"\t"<<warehouseshelf[r][c] << " " <<  "none\t";				
                           else
              				cout <<"\t"<<warehouseshelf[r][c] << " " <<  warehouseshelfTVs[r][c]->itemno<<"\t";				
              			}
              		cout << " "<< endl;
              		}
              		system("PAUSE");
              	}
              
              	void display_total_all_items_stored()
              
              	{	
              		int sum  = 0;
              		int r, c;									   
              		double cost;
              		for( r=0; r<row; r++ )
              		{
              			for( c=0; c<col; c ++ )
              			{
              				sum = sum + warehouseshelf[r][c];
              				totalcost= sum*cost;
              			}
              		}
              		
              		cout <<"\t"<< "Total sum of items is = " << sum << endl;
              			system("PAUSE");
              	}
              
              	void display_total_value()
              	{
              		cout <<"\t"<< "Total value is = $" << totalcost << endl;
              		system("PAUSE");
              	}
              };
              
              class warehouse
              {
              
              public:
              
              		// function to update address
              
              	char *update_address (void)
              	{	
              		char tempaddress[200];
              		cout <<"\t"<< "Enter address: ";
              		cin.getline (tempaddress, 200);
              		cout << " "<< endl;
              		cout <<"\t"<<"Address for the warehouse is "<<tempaddress <<endl;
              		cout << " "<< endl;
              		int size = strlen (tempaddress);
              		char *test = new char[size];
              		strcpy (test, tempaddress);
              
              		return test;
              	}
              };
              
              
              	//function to show display menu
              
              	void display_menu()
              
              	{	
              		cout << " "<< endl;
              		cout <<"\t"<< "Select option " << endl;
              		cout <<"\t"<< "-----------------------" << endl;
              		cout <<"\t"<< "1) Update item details " << endl;
              		cout <<"\t"<< "2) Display item details " << endl;
              		cout <<"\t"<< "3) Update warehouse address" << endl;
              		cout <<"\t"<< "4) Add items to the warehouse shelf" << endl;
              		cout <<"\t"<< "5) Display warehouse detail" << endl;
              		cout <<"\t"<< "6) Find total number of items in warehouse" << endl;
              		cout <<"\t"<< "7) Find total value in warehouse" << endl;
              		cout <<"\t"<< "8) Exit "<<endl;
              		cout <<"\t"<< "-----------------------" << endl;
              		cout <<"\t"<< "Enter option: ";	
              		
              	}
              	
              	void select_choice()
              
              	{	
              		cout << " "<< endl;
              		cout <<"\t"<<"Select TV  "<<endl;
              		cout <<"\t"<< "-----------------------" << endl;
              		cout <<"\t"<<"1 for TV1"<<endl;
              		cout <<"\t"<<"2 for TV2"<<endl;
              		cout <<"\t"<<"3 for TV3"<<endl;
              		cout <<"\t"<< "-----------------------" << endl;
              		cout <<"\t"<< "Enter Brand using 1-3: ";
              	}
              	
              
              
              	
              int main(void)
              {	int i;
              	int choice;
              	char *address;
              
              	
              	TV	brand[3];
              	shelf s1;
              	s1.initial();
              	warehouse w1;
              	
              	
              	do
              	{	
              		system("cls");
              		display_menu();
              		cin >> choice;
              		cin.ignore();
              		switch( choice )
              		{	
              			case 1:	system("cls");
              								
              					{	cout << " "<< endl;
              						cout <<"\t"<<"Update item details" << endl;
              						cout <<"\t"<<"-----------------------"<<endl;
              						select_choice();
              						
              						do 
              						{	
              							cin >>i;
              				 
              							if (i==0||i>3)
              								{	
              									cout <<" "<<endl;
              									cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
              								}
              							else 
              								{
              									brand[i-1].update();
              								}
              						}
              						while (i==0||i>3);
              					}
              				
              			break;
              
              			case 2:	system("cls");
              
              				{	cout << " "<< endl;
              					cout <<"\t"<<"Display item details" << endl;
              					cout <<"\t"<<"-----------------------"<<endl;
              					select_choice();
              
              				do 
              					{
              						cin >>i;
              				 
              						if (i==0||i>3)
              							{	
              								cout <<" "<<endl;
              								cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
              							}
              						else 
              							{
              								brand[i-1].display_item();
              							}
              					}
              				while (i==0||i>3);
              				}
              
              			break;
              
              			case 3:	system("cls");
              
              				cout << " "<< endl;
              				cout <<"\t"<<"Update address" << endl;
              				cout <<"\t"<<"-----------------------"<<endl;
              				cout <<" "<<endl;				
              				address = w1.update_address();
              				system("PAUSE");
              				//cout<< address << endl;
              				break;
              
              			case 4:	system("cls");
              
              				{	cout << " "<< endl;
              					cout <<"\t"<<"Update Warehouse Shelfs" << endl;
              					cout <<"\t"<<"-----------------------"<<endl;
              					select_choice();
              				do 
              					{
              						cin >>i;
              				 
              						if (i==0||i>3)
              							{	
              								cout <<" "<<endl;
              								cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
              							}
              						else 
              							{	cout << " "<< endl;
              								//brand[i-1].display_item();
              								s1.update_shelfs(&brand[i-1]);  // ** pass in TV item
              							}
              					}
              				while (i==0||i>3);
              				}
              
              			break;
              
              			case 5:	system("cls");
              
              				{	cout << " "<< endl;
              					cout <<"\t"<<"Display Warehouse Selfs" << endl;
              					cout <<"\t"<<"-----------------------"<<endl;
              							{	
              								cout << " "<< endl;
              								s1.display_shelfs();
              							}
              				}
              
              			break;
              
              			case 6:	system("cls");
              
              				{	cout << " "<< endl;
              					cout <<"\t"<<"Display Total Items" << endl;
              					cout <<"\t"<<"-----------------------"<<endl;
              			
              							{
              								cout<<" "<<endl;
              								s1.display_total_all_items_stored();
              							}
              				}
              
              			break;
              
              
              			case 7: system("cls");
              
              				{	cout << " "<< endl;
              					cout <<"\t"<<"Display Total Value" << endl;
              					cout <<"\t"<<"-----------------------"<<endl;
              					
              						{
              							cout<<" "<<endl;
              							s1.display_total_value();
              						}
              				
              				}
              
              			break;
              
              
              			case 8: 
              				cout <<" "<<endl;
              			//	setcolor (12);
              				cout <<"\t"<< "Bye Bye. See you again"<<endl;
              				cout<<" "<<endl;
              			break;
              
              			default:
              				cout<<" "<<endl;
              		//		setcolor (12);
              				cout <<"\t"<<"Invalid choice.Pls re-enter again"<<endl;
              				system("PAUSE");
              		}
              	}	 while( choice != 8 );
              
              	return 0;
              }

              Comment

              • HarisHohkl
                New Member
                • Jan 2007
                • 8

                #8
                thanks for the help, but how come it can't display the total amount for the tv??[

                QUOTE=horace1]done a few mods to add item to shelf and display same - not sure if this is what you require???
                Code:
                #include <iostream.h>
                #include <iomanip.h>
                #include <string.h>
                #include <process.h>
                #include <cstdlib>
                #include <windows.h>
                
                #define  row  4
                #define  col  5
                	 
                										 																				  
                class TV												  
                { 
                public :  // ** made public for now
                	int itemno;
                	char description[100];	
                	char model[100];																  
                	double cost;
                	int quantity;  // ** added
                	
                															
                public :
                	
                	//	this function will prompt user to key in details
                	
                	void update()
                
                	{	
                		cout << " "<< endl;
                		cout <<"\t"<< "Enter item no: ";
                		cin >>itemno;
                		cout <<"\t"<< "Enter description: ";
                		cin.ignore();
                		cin.getline( description, 100 );
                		cout <<"\t"<<"Enter model: ";
                		cin.getline( model, 100 );
                		cout <<"\t"<< "Enter cost: $";
                		cin >> cost;
                		quantity=0;   // ** initialise
                	}
                
                	void display_item()
                
                	{	
                		cout << " "<< endl;
                		cout <<"\t"<< "Item no: " << itemno << endl;
                		cout <<"\t"<< "Description of item: " << description << endl;
                		cout <<"\t"<< "Model: "<<model<<endl;
                		cout <<"\t"<< "Cost of item: $ " << cost << endl;
                		cout << " "<< endl;
                		system("PAUSE");
                	}
                };
                
                
                class shelf
                {	
                	int  warehouseshelf[row][col];  // ** initialise to 0 here
                    TV  *warehouseshelfTVs[row][col];// ** added TVs
                	double totalcost;
                	int itemno;
                	int quantity;
                
                public:
                void initial()
                	{	
                		int r, c;
                		for( r=0; r<row; r++ )
                			for( c=0; c<col;c++ )
                				{ warehouseshelf[r][c] = 0; warehouseshelfTVs[r][c] = (TV *) 0; }
                	}
                			
                	//	this function will update the shelf quantity
                	
                	void update_shelfs(TV *brand)
                		  
                	{	
                		int i, numitems, r , c, quantity;
                		
                		cout << " "<< endl;
                	//	cout <<"\t"<< "Enter no of item to update: ";        ** what is this for?          
                	//	cin >> numitems;
                	
                	//	for( i= 0; i < numitems; i++ ) 	  
                		{
                			cout <<"\t"<< "Enter which row to update for item: ";            
                			cin >> r;
                
                			cout <<"\t"<< "Enter which column to update for item: "; 										   		  
                			cin >> c;
                	 
                			cout <<"\t"<< "Enter no of quantity to update for item: ";    	 
                	
                			cin >> quantity;
                						   	  
                            warehouseshelfTVs[r][c]=brand;   // ** added TV to shelf
                			warehouseshelf[r][c] = quantity;								  
                	
                		}
                		
                		cout <<"\t"<< "Update completed................." << endl;
                		
                		system("PAUSE");
                
                	}	
                	
                	void display_shelfs()
                
                	{	
                		int r, c;
                		
                		for( r=0; r<row; r++ )
                
                		{
                			for( c=0; c<col; c++ )
                			{
                             if(warehouseshelfTVs[r][c] == 0)         // ** check if item on shelf
                             	cout <<"\t"<<warehouseshelf[r][c] << " " <<  "none\t";				
                             else
                				cout <<"\t"<<warehouseshelf[r][c] << " " <<  warehouseshelfTVs[r][c]->itemno<<"\t";				
                			}
                		cout << " "<< endl;
                		}
                		system("PAUSE");
                	}
                
                	void display_total_all_items_stored()
                
                	{	
                		int sum  = 0;
                		int r, c;									   
                		double cost;
                		for( r=0; r<row; r++ )
                		{
                			for( c=0; c<col; c ++ )
                			{
                				sum = sum + warehouseshelf[r][c];
                				totalcost= sum*cost;
                			}
                		}
                		
                		cout <<"\t"<< "Total sum of items is = " << sum << endl;
                			system("PAUSE");
                	}
                
                	void display_total_value()
                	{
                		cout <<"\t"<< "Total value is = $" << totalcost << endl;
                		system("PAUSE");
                	}
                };
                
                class warehouse
                {
                
                public:
                
                		// function to update address
                
                	char *update_address (void)
                	{	
                		char tempaddress[200];
                		cout <<"\t"<< "Enter address: ";
                		cin.getline (tempaddress, 200);
                		cout << " "<< endl;
                		cout <<"\t"<<"Address for the warehouse is "<<tempaddress <<endl;
                		cout << " "<< endl;
                		int size = strlen (tempaddress);
                		char *test = new char[size];
                		strcpy (test, tempaddress);
                
                		return test;
                	}
                };
                
                
                	//function to show display menu
                
                	void display_menu()
                
                	{	
                		cout << " "<< endl;
                		cout <<"\t"<< "Select option " << endl;
                		cout <<"\t"<< "-----------------------" << endl;
                		cout <<"\t"<< "1) Update item details " << endl;
                		cout <<"\t"<< "2) Display item details " << endl;
                		cout <<"\t"<< "3) Update warehouse address" << endl;
                		cout <<"\t"<< "4) Add items to the warehouse shelf" << endl;
                		cout <<"\t"<< "5) Display warehouse detail" << endl;
                		cout <<"\t"<< "6) Find total number of items in warehouse" << endl;
                		cout <<"\t"<< "7) Find total value in warehouse" << endl;
                		cout <<"\t"<< "8) Exit "<<endl;
                		cout <<"\t"<< "-----------------------" << endl;
                		cout <<"\t"<< "Enter option: ";	
                		
                	}
                	
                	void select_choice()
                
                	{	
                		cout << " "<< endl;
                		cout <<"\t"<<"Select TV  "<<endl;
                		cout <<"\t"<< "-----------------------" << endl;
                		cout <<"\t"<<"1 for TV1"<<endl;
                		cout <<"\t"<<"2 for TV2"<<endl;
                		cout <<"\t"<<"3 for TV3"<<endl;
                		cout <<"\t"<< "-----------------------" << endl;
                		cout <<"\t"<< "Enter Brand using 1-3: ";
                	}
                	
                
                
                	
                int main(void)
                {	int i;
                	int choice;
                	char *address;
                
                	
                	TV	brand[3];
                	shelf s1;
                	s1.initial();
                	warehouse w1;
                	
                	
                	do
                	{	
                		system("cls");
                		display_menu();
                		cin >> choice;
                		cin.ignore();
                		switch( choice )
                		{	
                			case 1:	system("cls");
                								
                					{	cout << " "<< endl;
                						cout <<"\t"<<"Update item details" << endl;
                						cout <<"\t"<<"-----------------------"<<endl;
                						select_choice();
                						
                						do 
                						{	
                							cin >>i;
                				 
                							if (i==0||i>3)
                								{	
                									cout <<" "<<endl;
                									cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
                								}
                							else 
                								{
                									brand[i-1].update();
                								}
                						}
                						while (i==0||i>3);
                					}
                				
                			break;
                
                			case 2:	system("cls");
                
                				{	cout << " "<< endl;
                					cout <<"\t"<<"Display item details" << endl;
                					cout <<"\t"<<"-----------------------"<<endl;
                					select_choice();
                
                				do 
                					{
                						cin >>i;
                				 
                						if (i==0||i>3)
                							{	
                								cout <<" "<<endl;
                								cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
                							}
                						else 
                							{
                								brand[i-1].display_item();
                							}
                					}
                				while (i==0||i>3);
                				}
                
                			break;
                
                			case 3:	system("cls");
                
                				cout << " "<< endl;
                				cout <<"\t"<<"Update address" << endl;
                				cout <<"\t"<<"-----------------------"<<endl;
                				cout <<" "<<endl;				
                				address = w1.update_address();
                				system("PAUSE");
                				//cout<< address << endl;
                				break;
                
                			case 4:	system("cls");
                
                				{	cout << " "<< endl;
                					cout <<"\t"<<"Update Warehouse Shelfs" << endl;
                					cout <<"\t"<<"-----------------------"<<endl;
                					select_choice();
                				do 
                					{
                						cin >>i;
                				 
                						if (i==0||i>3)
                							{	
                								cout <<" "<<endl;
                								cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
                							}
                						else 
                							{	cout << " "<< endl;
                								//brand[i-1].display_item();
                								s1.update_shelfs(&brand[i-1]);  // ** pass in TV item
                							}
                					}
                				while (i==0||i>3);
                				}
                
                			break;
                
                			case 5:	system("cls");
                
                				{	cout << " "<< endl;
                					cout <<"\t"<<"Display Warehouse Selfs" << endl;
                					cout <<"\t"<<"-----------------------"<<endl;
                							{	
                								cout << " "<< endl;
                								s1.display_shelfs();
                							}
                				}
                
                			break;
                
                			case 6:	system("cls");
                
                				{	cout << " "<< endl;
                					cout <<"\t"<<"Display Total Items" << endl;
                					cout <<"\t"<<"-----------------------"<<endl;
                			
                							{
                								cout<<" "<<endl;
                								s1.display_total_all_items_stored();
                							}
                				}
                
                			break;
                
                
                			case 7: system("cls");
                
                				{	cout << " "<< endl;
                					cout <<"\t"<<"Display Total Value" << endl;
                					cout <<"\t"<<"-----------------------"<<endl;
                					
                						{
                							cout<<" "<<endl;
                							s1.display_total_value();
                						}
                				
                				}
                
                			break;
                
                
                			case 8: 
                				cout <<" "<<endl;
                			//	setcolor (12);
                				cout <<"\t"<< "Bye Bye. See you again"<<endl;
                				cout<<" "<<endl;
                			break;
                
                			default:
                				cout<<" "<<endl;
                		//		setcolor (12);
                				cout <<"\t"<<"Invalid choice.Pls re-enter again"<<endl;
                				system("PAUSE");
                		}
                	}	 while( choice != 8 );
                
                	return 0;
                }
                [/QUOTE]

                Comment

                • horace1
                  Recognized Expert Top Contributor
                  • Nov 2006
                  • 1510

                  #9
                  Originally posted by HarisHohkl
                  thanks for the help, but how come it can't display the total amount for the tv??[
                  I only modified update_shelfs() and display_shelfs( ) and the code which called them, i.e. options 1, 2, 4 and 5 now appear to do something. If they do what you require you now need to look at display_total_a ll_items_stored () and display_total_v alue()

                  Comment

                  • HarisHohkl
                    New Member
                    • Jan 2007
                    • 8

                    #10
                    for the display total item, it can add up all but not for the total value. how can i ask the programme to go to the item classess to capture the cost of the item for each indivual tv and multiply it to get the total???? thanks[

                    QUOTE=horace1]I only modified update_shelfs() and display_shelfs( ) and the code which called them, i.e. options 1, 2, 4 and 5 now appear to do something. If they do what you require you now need to look at display_total_a ll_items_stored () and display_total_v alue()[/QUOTE]

                    Comment

                    • HarisHohkl
                      New Member
                      • Jan 2007
                      • 8

                      #11
                      Originally posted by horace1
                      I only modified update_shelfs() and display_shelfs( ) and the code which called them, i.e. options 1, 2, 4 and 5 now appear to do something. If they do what you require you now need to look at display_total_a ll_items_stored () and display_total_v alue()
                      Hi, i still can't figure out how to capture the total cost of the three different item and add up the total. Please help me.... need to submit it by wednesday. thanks

                      Comment

                      Working...