473,396 Members | 1,777 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
Jan 26 '07 #1
10 1850
macklin01
145 100+
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:

Expand|Select|Wrap|Line Numbers
  1. BMP
  2. {
  3.  private:
  4.   ebmpBYTE** Pixels;
  5.   // ... 
  6. };
  7.  
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
Jan 26 '07 #2
horace1
1,510 Expert 1GB
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.
Jan 26 '07 #3
macklin01
145 100+
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
Jan 26 '07 #4
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?
Jan 27 '07 #5
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

Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <iomanip.h>
  3. #include <string.h>
  4. #include <process.h>
  5. #include <cstdlib>
  6. #include <windows.h>
  7.  
  8. #define  row  5
  9. #define  col  10
  10.  
  11.  
  12.  
  13. class TV                                                  
  14.     int itemno;
  15.     char description[100];    
  16.     char model[100];                                                                  
  17.     double cost;
  18.  
  19.  
  20.  
  21. public :
  22.  
  23.     //    this function will prompt user to key in details
  24.  
  25.     void update()
  26.  
  27.     {    
  28.         cout << " "<< endl;
  29.         cout <<"\t"<< "Enter item no: ";
  30.         cin >>itemno;
  31.         cout <<"\t"<< "Enter description: ";
  32.         cin.ignore();
  33.         cin.getline( description, 100 );
  34.         cout <<"\t"<<"Enter model: ";
  35.         cin.getline( model, 100 );
  36.         cout <<"\t"<< "Enter cost: $";
  37.         cin >> cost;
  38.  
  39.     }
  40.  
  41.     void display_item()
  42.  
  43.     {    
  44.         cout << " "<< endl;
  45.         cout <<"\t"<< "Item no: " << itemno << endl;
  46.         cout <<"\t"<< "Description of item: " << description << endl;
  47.         cout <<"\t"<< "Model: "<<model<<endl;
  48.         cout <<"\t"<< "Cost of item: $ " << cost << endl;
  49.         cout << " "<< endl;
  50.         system("PAUSE");
  51.     }
  52. };
  53.  
  54.  
  55. class shelf
  56. {    
  57.     int  warehouseshelf[row][col];
  58.     double totalcost;
  59.     int itemno;
  60.     int quantity;
  61.  
  62. public:
  63.  
  64.     //function to initial all array to 0
  65.  
  66.     void initial()
  67.  
  68.     {    
  69.         int r, c;
  70.  
  71.         for( r=0; r<5; r++ )
  72.         {
  73.             for( c=0; c<10;c++ )
  74.             {
  75.                 warehouseshelf[r][c] = 0;
  76.             }
  77.         }
  78.     }
  79.  
  80.     //    this function will update the shelf quantity
  81.  
  82.     void update_shelfs()
  83.  
  84.     {    
  85.         int i, numitems, r , c, quantity;
  86.  
  87.         cout << " "<< endl;
  88.         cout <<"\t"<< "Enter no of item to update: ";                  
  89.         cin >> numitems;
  90.  
  91.  
  92.         for( i= 0; i < numitems; i++ )       
  93.         {
  94.             cout <<"\t"<< "Enter which row to update for item: ";            
  95.             cin >> r;
  96.  
  97.             cout <<"\t"<< "Enter which column to update for item: ";                                                      
  98.             cin >> c;
  99.  
  100.             cout <<"\t"<< "Enter no of quantity to update for item: ";         
  101.  
  102.             cin >> quantity;
  103.  
  104.             warehouseshelf[r][c] = quantity;                                  
  105.  
  106.         }
  107.  
  108.         cout <<"\t"<< "Update completed................." << endl;
  109.  
  110.         system("PAUSE");
  111.  
  112.     }    
  113.  
  114.     void display_shelfs()
  115.  
  116.     {    
  117.         int r, c;
  118.  
  119.         for( r=0; r<5; r++ )
  120.  
  121.         {
  122.             for( c=0; c<10; c++ )
  123.             {
  124.                 cout <<"\t"<<warehouseshelf[r][c]<<"\t";                
  125.             }
  126.         }
  127.         cout << " "<< endl;
  128.         system("PAUSE");
  129.     }
  130.  
  131.     void display_total_all_items_stored()
  132.  
  133.     {    
  134.         int sum  = 0;
  135.         int r, c;                                       
  136.         double cost;
  137.         for( r=0; r<5; r++ )
  138.         {
  139.             for( c=0; c<10; c ++ )
  140.             {
  141.                 sum = sum + warehouseshelf[r][c];
  142.                 totalcost= sum*cost;
  143.             }
  144.         }
  145.  
  146.         cout <<"\t"<< "Total sum of items is = " << sum << endl;
  147.             system("PAUSE");
  148.     }
  149.  
  150.     void display_total_value()
  151.     {
  152.         cout <<"\t"<< "Total value is = $" << totalcost << endl;
  153.         system("PAUSE");
  154.     }
  155. };
  156.  
  157. class warehouse
  158. {
  159.  
  160. public:
  161.  
  162.         // function to update address
  163.  
  164.     char *update_address (void)
  165.     {    
  166.         char tempaddress[200];
  167.         cout <<"\t"<< "Enter address: ";
  168.         cin.getline (tempaddress, 200);
  169.         cout << " "<< endl;
  170.         cout <<"\t"<<"Address for the warehouse is "<<tempaddress <<endl;
  171.         cout << " "<< endl;
  172.         int size = strlen (tempaddress);
  173.         char *test = new char[size];
  174.         strcpy (test, tempaddress);
  175.  
  176.         return test;
  177.     }
  178. };
  179.  
  180.  
  181.     //function to show display menu
  182.  
  183.     void display_menu()
  184.  
  185.     {    
  186.         cout << " "<< endl;
  187.         cout <<"\t"<< "Select option " << endl;
  188.         cout <<"\t"<< "-----------------------" << endl;
  189.         cout <<"\t"<< "1) Update item details " << endl;
  190.         cout <<"\t"<< "2) Display item details " << endl;
  191.         cout <<"\t"<< "3) Update warehouse address" << endl;
  192.         cout <<"\t"<< "4) Add items to the warehouse shelf" << endl;
  193.         cout <<"\t"<< "5) Display warehouse detail" << endl;
  194.         cout <<"\t"<< "6) Find total number of items in warehouse" << endl;
  195.         cout <<"\t"<< "7) Find total value in warehouse" << endl;
  196.         cout <<"\t"<< "8) Exit "<<endl;
  197.         cout <<"\t"<< "-----------------------" << endl;
  198.         cout <<"\t"<< "Enter option: ";    
  199.  
  200.     }
  201.  
  202.     void select_choice()
  203.  
  204.     {    
  205.         cout << " "<< endl;
  206.         cout <<"\t"<<"Select TV  "<<endl;
  207.         cout <<"\t"<< "-----------------------" << endl;
  208.         cout <<"\t"<<"1 for TV1"<<endl;
  209.         cout <<"\t"<<"2 for TV2"<<endl;
  210.         cout <<"\t"<<"3 for TV3"<<endl;
  211.         cout <<"\t"<< "-----------------------" << endl;
  212.         cout <<"\t"<< "Enter Brand using 1-3: ";
  213.     }
  214.  
  215.  
  216.  
  217.  
  218. int main(void)
  219. {    int i;
  220.     int choice;
  221.     char *address;
  222.  
  223.  
  224.     TV    brand[3];
  225.     shelf s1;
  226.     s1.initial();
  227.     warehouse w1;
  228.  
  229.  
  230.     do
  231.     {    
  232.         system("cls");
  233.         display_menu();
  234.         cin >> choice;
  235.         cin.ignore();
  236.         switch( choice )
  237.         {    
  238.             case 1:    system("cls");
  239.  
  240.                     {    cout << " "<< endl;
  241.                         cout <<"\t"<<"Update item details" << endl;
  242.                         cout <<"\t"<<"-----------------------"<<endl;
  243.                         select_choice();
  244.  
  245.                         do 
  246.                         {    
  247.                             cin >>i;
  248.  
  249.                             if (i==0||i>3)
  250.                                 {    
  251.                                     cout <<" "<<endl;
  252.                                     cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
  253.                                 }
  254.                             else 
  255.                                 {
  256.                                     brand[i-1].update();
  257.                                 }
  258.                         }
  259.                         while (i==0||i>3);
  260.                     }
  261.  
  262.             break;
  263.  
  264.             case 2:    system("cls");
  265.  
  266.                 {    cout << " "<< endl;
  267.                     cout <<"\t"<<"Display item details" << endl;
  268.                     cout <<"\t"<<"-----------------------"<<endl;
  269.                     select_choice();
  270.  
  271.                 do 
  272.                     {
  273.                         cin >>i;
  274.  
  275.                         if (i==0||i>3)
  276.                             {    
  277.                                 cout <<" "<<endl;
  278.                                 cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
  279.                             }
  280.                         else 
  281.                             {
  282.                                 brand[i-1].display_item();
  283.                             }
  284.                     }
  285.                 while (i==0||i>3);
  286.                 }
  287.  
  288.             break;
  289.  
  290.             case 3:    system("cls");
  291.  
  292.                 cout << " "<< endl;
  293.                 cout <<"\t"<<"Update address" << endl;
  294.                 cout <<"\t"<<"-----------------------"<<endl;
  295.                 cout <<" "<<endl;                
  296.                 address = w1.update_address();
  297.                 system("PAUSE");
  298.                 //cout<< address << endl;
  299.                 break;
  300.  
  301.             case 4:    system("cls");
  302.  
  303.                 {    cout << " "<< endl;
  304.                     cout <<"\t"<<"Update Warehouse Shelfs" << endl;
  305.                     cout <<"\t"<<"-----------------------"<<endl;
  306.                     select_choice();
  307.                 do 
  308.                     {
  309.                         cin >>i;
  310.  
  311.                         if (i==0||i>3)
  312.                             {    
  313.                                 cout <<" "<<endl;
  314.                                 cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
  315.                             }
  316.                         else 
  317.                             {    cout << " "<< endl;
  318.                                 s1.update_shelfs();
  319.                             }
  320.                     }
  321.                 while (i==0||i>3);
  322.                 }
  323.  
  324.             break;
  325.  
  326.             case 5:    system("cls");
  327.  
  328.                 {    cout << " "<< endl;
  329.                     cout <<"\t"<<"Display Warehouse Selfs" << endl;
  330.                     cout <<"\t"<<"-----------------------"<<endl;
  331.                             {    
  332.                                 cout << " "<< endl;
  333.                                 s1.display_shelfs();
  334.                             }
  335.                 }
  336.  
  337.             break;
  338.  
  339.             case 6:    system("cls");
  340.  
  341.                 {    cout << " "<< endl;
  342.                     cout <<"\t"<<"Display Total Items" << endl;
  343.                     cout <<"\t"<<"-----------------------"<<endl;
  344.  
  345.                             {
  346.                                 cout<<" "<<endl;
  347.                                 s1.display_total_all_items_stored();
  348.                             }
  349.                 }
  350.  
  351.             break;
  352.  
  353.  
  354.             case 7: system("cls");
  355.  
  356.                 {    cout << " "<< endl;
  357.                     cout <<"\t"<<"Display Total Value" << endl;
  358.                     cout <<"\t"<<"-----------------------"<<endl;
  359.  
  360.                         {
  361.                             cout<<" "<<endl;
  362.                             s1.display_total_value();
  363.                         }
  364.  
  365.                 }
  366.  
  367.             break;
  368.  
  369.  
  370.             case 8: 
  371.                 cout <<" "<<endl;
  372.                 setcolor (12);
  373.                 cout <<"\t"<< "Bye Bye. See you again"<<endl;
  374.                 cout<<" "<<endl;
  375.             break;
  376.  
  377.             default:
  378.                 cout<<" "<<endl;
  379.                 setcolor (12);
  380.                 cout <<"\t"<<"Invalid choice.Pls re-enter again"<<endl;
  381.                 system("PAUSE");
  382.         }
  383.     }     while( choice != 8 );
  384.  
  385.     return 0;
  386. }
  387.  
Jan 28 '07 #6
horace1
1,510 Expert 1GB
done a few mods to add item to shelf and display same - not sure if this is what you require???
Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <iomanip.h>
  3. #include <string.h>
  4. #include <process.h>
  5. #include <cstdlib>
  6. #include <windows.h>
  7.  
  8. #define  row  4
  9. #define  col  5
  10.  
  11.  
  12. class TV                                                  
  13. public :  // ** made public for now
  14.     int itemno;
  15.     char description[100];    
  16.     char model[100];                                                                  
  17.     double cost;
  18.     int quantity;  // ** added
  19.  
  20.  
  21. public :
  22.  
  23.     //    this function will prompt user to key in details
  24.  
  25.     void update()
  26.  
  27.     {    
  28.         cout << " "<< endl;
  29.         cout <<"\t"<< "Enter item no: ";
  30.         cin >>itemno;
  31.         cout <<"\t"<< "Enter description: ";
  32.         cin.ignore();
  33.         cin.getline( description, 100 );
  34.         cout <<"\t"<<"Enter model: ";
  35.         cin.getline( model, 100 );
  36.         cout <<"\t"<< "Enter cost: $";
  37.         cin >> cost;
  38.         quantity=0;   // ** initialise
  39.     }
  40.  
  41.     void display_item()
  42.  
  43.     {    
  44.         cout << " "<< endl;
  45.         cout <<"\t"<< "Item no: " << itemno << endl;
  46.         cout <<"\t"<< "Description of item: " << description << endl;
  47.         cout <<"\t"<< "Model: "<<model<<endl;
  48.         cout <<"\t"<< "Cost of item: $ " << cost << endl;
  49.         cout << " "<< endl;
  50.         system("PAUSE");
  51.     }
  52. };
  53.  
  54.  
  55. class shelf
  56. {    
  57.     int  warehouseshelf[row][col];  // ** initialise to 0 here
  58.     TV  *warehouseshelfTVs[row][col];// ** added TVs
  59.     double totalcost;
  60.     int itemno;
  61.     int quantity;
  62.  
  63. public:
  64. void initial()
  65.     {    
  66.         int r, c;
  67.         for( r=0; r<row; r++ )
  68.             for( c=0; c<col;c++ )
  69.                 { warehouseshelf[r][c] = 0; warehouseshelfTVs[r][c] = (TV *) 0; }
  70.     }
  71.  
  72.     //    this function will update the shelf quantity
  73.  
  74.     void update_shelfs(TV *brand)
  75.  
  76.     {    
  77.         int i, numitems, r , c, quantity;
  78.  
  79.         cout << " "<< endl;
  80.     //    cout <<"\t"<< "Enter no of item to update: ";        ** what is this for?          
  81.     //    cin >> numitems;
  82.  
  83.     //    for( i= 0; i < numitems; i++ )       
  84.         {
  85.             cout <<"\t"<< "Enter which row to update for item: ";            
  86.             cin >> r;
  87.  
  88.             cout <<"\t"<< "Enter which column to update for item: ";                                                      
  89.             cin >> c;
  90.  
  91.             cout <<"\t"<< "Enter no of quantity to update for item: ";         
  92.  
  93.             cin >> quantity;
  94.  
  95.             warehouseshelfTVs[r][c]=brand;   // ** added TV to shelf
  96.             warehouseshelf[r][c] = quantity;                                  
  97.  
  98.         }
  99.  
  100.         cout <<"\t"<< "Update completed................." << endl;
  101.  
  102.         system("PAUSE");
  103.  
  104.     }    
  105.  
  106.     void display_shelfs()
  107.  
  108.     {    
  109.         int r, c;
  110.  
  111.         for( r=0; r<row; r++ )
  112.  
  113.         {
  114.             for( c=0; c<col; c++ )
  115.             {
  116.              if(warehouseshelfTVs[r][c] == 0)         // ** check if item on shelf
  117.                  cout <<"\t"<<warehouseshelf[r][c] << " " <<  "none\t";                
  118.              else
  119.                 cout <<"\t"<<warehouseshelf[r][c] << " " <<  warehouseshelfTVs[r][c]->itemno<<"\t";                
  120.             }
  121.         cout << " "<< endl;
  122.         }
  123.         system("PAUSE");
  124.     }
  125.  
  126.     void display_total_all_items_stored()
  127.  
  128.     {    
  129.         int sum  = 0;
  130.         int r, c;                                       
  131.         double cost;
  132.         for( r=0; r<row; r++ )
  133.         {
  134.             for( c=0; c<col; c ++ )
  135.             {
  136.                 sum = sum + warehouseshelf[r][c];
  137.                 totalcost= sum*cost;
  138.             }
  139.         }
  140.  
  141.         cout <<"\t"<< "Total sum of items is = " << sum << endl;
  142.             system("PAUSE");
  143.     }
  144.  
  145.     void display_total_value()
  146.     {
  147.         cout <<"\t"<< "Total value is = $" << totalcost << endl;
  148.         system("PAUSE");
  149.     }
  150. };
  151.  
  152. class warehouse
  153. {
  154.  
  155. public:
  156.  
  157.         // function to update address
  158.  
  159.     char *update_address (void)
  160.     {    
  161.         char tempaddress[200];
  162.         cout <<"\t"<< "Enter address: ";
  163.         cin.getline (tempaddress, 200);
  164.         cout << " "<< endl;
  165.         cout <<"\t"<<"Address for the warehouse is "<<tempaddress <<endl;
  166.         cout << " "<< endl;
  167.         int size = strlen (tempaddress);
  168.         char *test = new char[size];
  169.         strcpy (test, tempaddress);
  170.  
  171.         return test;
  172.     }
  173. };
  174.  
  175.  
  176.     //function to show display menu
  177.  
  178.     void display_menu()
  179.  
  180.     {    
  181.         cout << " "<< endl;
  182.         cout <<"\t"<< "Select option " << endl;
  183.         cout <<"\t"<< "-----------------------" << endl;
  184.         cout <<"\t"<< "1) Update item details " << endl;
  185.         cout <<"\t"<< "2) Display item details " << endl;
  186.         cout <<"\t"<< "3) Update warehouse address" << endl;
  187.         cout <<"\t"<< "4) Add items to the warehouse shelf" << endl;
  188.         cout <<"\t"<< "5) Display warehouse detail" << endl;
  189.         cout <<"\t"<< "6) Find total number of items in warehouse" << endl;
  190.         cout <<"\t"<< "7) Find total value in warehouse" << endl;
  191.         cout <<"\t"<< "8) Exit "<<endl;
  192.         cout <<"\t"<< "-----------------------" << endl;
  193.         cout <<"\t"<< "Enter option: ";    
  194.  
  195.     }
  196.  
  197.     void select_choice()
  198.  
  199.     {    
  200.         cout << " "<< endl;
  201.         cout <<"\t"<<"Select TV  "<<endl;
  202.         cout <<"\t"<< "-----------------------" << endl;
  203.         cout <<"\t"<<"1 for TV1"<<endl;
  204.         cout <<"\t"<<"2 for TV2"<<endl;
  205.         cout <<"\t"<<"3 for TV3"<<endl;
  206.         cout <<"\t"<< "-----------------------" << endl;
  207.         cout <<"\t"<< "Enter Brand using 1-3: ";
  208.     }
  209.  
  210.  
  211.  
  212.  
  213. int main(void)
  214. {    int i;
  215.     int choice;
  216.     char *address;
  217.  
  218.  
  219.     TV    brand[3];
  220.     shelf s1;
  221.     s1.initial();
  222.     warehouse w1;
  223.  
  224.  
  225.     do
  226.     {    
  227.         system("cls");
  228.         display_menu();
  229.         cin >> choice;
  230.         cin.ignore();
  231.         switch( choice )
  232.         {    
  233.             case 1:    system("cls");
  234.  
  235.                     {    cout << " "<< endl;
  236.                         cout <<"\t"<<"Update item details" << endl;
  237.                         cout <<"\t"<<"-----------------------"<<endl;
  238.                         select_choice();
  239.  
  240.                         do 
  241.                         {    
  242.                             cin >>i;
  243.  
  244.                             if (i==0||i>3)
  245.                                 {    
  246.                                     cout <<" "<<endl;
  247.                                     cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
  248.                                 }
  249.                             else 
  250.                                 {
  251.                                     brand[i-1].update();
  252.                                 }
  253.                         }
  254.                         while (i==0||i>3);
  255.                     }
  256.  
  257.             break;
  258.  
  259.             case 2:    system("cls");
  260.  
  261.                 {    cout << " "<< endl;
  262.                     cout <<"\t"<<"Display item details" << endl;
  263.                     cout <<"\t"<<"-----------------------"<<endl;
  264.                     select_choice();
  265.  
  266.                 do 
  267.                     {
  268.                         cin >>i;
  269.  
  270.                         if (i==0||i>3)
  271.                             {    
  272.                                 cout <<" "<<endl;
  273.                                 cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
  274.                             }
  275.                         else 
  276.                             {
  277.                                 brand[i-1].display_item();
  278.                             }
  279.                     }
  280.                 while (i==0||i>3);
  281.                 }
  282.  
  283.             break;
  284.  
  285.             case 3:    system("cls");
  286.  
  287.                 cout << " "<< endl;
  288.                 cout <<"\t"<<"Update address" << endl;
  289.                 cout <<"\t"<<"-----------------------"<<endl;
  290.                 cout <<" "<<endl;                
  291.                 address = w1.update_address();
  292.                 system("PAUSE");
  293.                 //cout<< address << endl;
  294.                 break;
  295.  
  296.             case 4:    system("cls");
  297.  
  298.                 {    cout << " "<< endl;
  299.                     cout <<"\t"<<"Update Warehouse Shelfs" << endl;
  300.                     cout <<"\t"<<"-----------------------"<<endl;
  301.                     select_choice();
  302.                 do 
  303.                     {
  304.                         cin >>i;
  305.  
  306.                         if (i==0||i>3)
  307.                             {    
  308.                                 cout <<" "<<endl;
  309.                                 cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
  310.                             }
  311.                         else 
  312.                             {    cout << " "<< endl;
  313.                                 //brand[i-1].display_item();
  314.                                 s1.update_shelfs(&brand[i-1]);  // ** pass in TV item
  315.                             }
  316.                     }
  317.                 while (i==0||i>3);
  318.                 }
  319.  
  320.             break;
  321.  
  322.             case 5:    system("cls");
  323.  
  324.                 {    cout << " "<< endl;
  325.                     cout <<"\t"<<"Display Warehouse Selfs" << endl;
  326.                     cout <<"\t"<<"-----------------------"<<endl;
  327.                             {    
  328.                                 cout << " "<< endl;
  329.                                 s1.display_shelfs();
  330.                             }
  331.                 }
  332.  
  333.             break;
  334.  
  335.             case 6:    system("cls");
  336.  
  337.                 {    cout << " "<< endl;
  338.                     cout <<"\t"<<"Display Total Items" << endl;
  339.                     cout <<"\t"<<"-----------------------"<<endl;
  340.  
  341.                             {
  342.                                 cout<<" "<<endl;
  343.                                 s1.display_total_all_items_stored();
  344.                             }
  345.                 }
  346.  
  347.             break;
  348.  
  349.  
  350.             case 7: system("cls");
  351.  
  352.                 {    cout << " "<< endl;
  353.                     cout <<"\t"<<"Display Total Value" << endl;
  354.                     cout <<"\t"<<"-----------------------"<<endl;
  355.  
  356.                         {
  357.                             cout<<" "<<endl;
  358.                             s1.display_total_value();
  359.                         }
  360.  
  361.                 }
  362.  
  363.             break;
  364.  
  365.  
  366.             case 8: 
  367.                 cout <<" "<<endl;
  368.             //    setcolor (12);
  369.                 cout <<"\t"<< "Bye Bye. See you again"<<endl;
  370.                 cout<<" "<<endl;
  371.             break;
  372.  
  373.             default:
  374.                 cout<<" "<<endl;
  375.         //        setcolor (12);
  376.                 cout <<"\t"<<"Invalid choice.Pls re-enter again"<<endl;
  377.                 system("PAUSE");
  378.         }
  379.     }     while( choice != 8 );
  380.  
  381.     return 0;
  382. }
  383.  
Jan 28 '07 #7
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???
Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <iomanip.h>
  3. #include <string.h>
  4. #include <process.h>
  5. #include <cstdlib>
  6. #include <windows.h>
  7.  
  8. #define  row  4
  9. #define  col  5
  10.  
  11.  
  12. class TV                                                  
  13. public :  // ** made public for now
  14.     int itemno;
  15.     char description[100];    
  16.     char model[100];                                                                  
  17.     double cost;
  18.     int quantity;  // ** added
  19.  
  20.  
  21. public :
  22.  
  23.     //    this function will prompt user to key in details
  24.  
  25.     void update()
  26.  
  27.     {    
  28.         cout << " "<< endl;
  29.         cout <<"\t"<< "Enter item no: ";
  30.         cin >>itemno;
  31.         cout <<"\t"<< "Enter description: ";
  32.         cin.ignore();
  33.         cin.getline( description, 100 );
  34.         cout <<"\t"<<"Enter model: ";
  35.         cin.getline( model, 100 );
  36.         cout <<"\t"<< "Enter cost: $";
  37.         cin >> cost;
  38.         quantity=0;   // ** initialise
  39.     }
  40.  
  41.     void display_item()
  42.  
  43.     {    
  44.         cout << " "<< endl;
  45.         cout <<"\t"<< "Item no: " << itemno << endl;
  46.         cout <<"\t"<< "Description of item: " << description << endl;
  47.         cout <<"\t"<< "Model: "<<model<<endl;
  48.         cout <<"\t"<< "Cost of item: $ " << cost << endl;
  49.         cout << " "<< endl;
  50.         system("PAUSE");
  51.     }
  52. };
  53.  
  54.  
  55. class shelf
  56. {    
  57.     int  warehouseshelf[row][col];  // ** initialise to 0 here
  58.     TV  *warehouseshelfTVs[row][col];// ** added TVs
  59.     double totalcost;
  60.     int itemno;
  61.     int quantity;
  62.  
  63. public:
  64. void initial()
  65.     {    
  66.         int r, c;
  67.         for( r=0; r<row; r++ )
  68.             for( c=0; c<col;c++ )
  69.                 { warehouseshelf[r][c] = 0; warehouseshelfTVs[r][c] = (TV *) 0; }
  70.     }
  71.  
  72.     //    this function will update the shelf quantity
  73.  
  74.     void update_shelfs(TV *brand)
  75.  
  76.     {    
  77.         int i, numitems, r , c, quantity;
  78.  
  79.         cout << " "<< endl;
  80.     //    cout <<"\t"<< "Enter no of item to update: ";        ** what is this for?          
  81.     //    cin >> numitems;
  82.  
  83.     //    for( i= 0; i < numitems; i++ )       
  84.         {
  85.             cout <<"\t"<< "Enter which row to update for item: ";            
  86.             cin >> r;
  87.  
  88.             cout <<"\t"<< "Enter which column to update for item: ";                                                      
  89.             cin >> c;
  90.  
  91.             cout <<"\t"<< "Enter no of quantity to update for item: ";         
  92.  
  93.             cin >> quantity;
  94.  
  95.             warehouseshelfTVs[r][c]=brand;   // ** added TV to shelf
  96.             warehouseshelf[r][c] = quantity;                                  
  97.  
  98.         }
  99.  
  100.         cout <<"\t"<< "Update completed................." << endl;
  101.  
  102.         system("PAUSE");
  103.  
  104.     }    
  105.  
  106.     void display_shelfs()
  107.  
  108.     {    
  109.         int r, c;
  110.  
  111.         for( r=0; r<row; r++ )
  112.  
  113.         {
  114.             for( c=0; c<col; c++ )
  115.             {
  116.              if(warehouseshelfTVs[r][c] == 0)         // ** check if item on shelf
  117.                  cout <<"\t"<<warehouseshelf[r][c] << " " <<  "none\t";                
  118.              else
  119.                 cout <<"\t"<<warehouseshelf[r][c] << " " <<  warehouseshelfTVs[r][c]->itemno<<"\t";                
  120.             }
  121.         cout << " "<< endl;
  122.         }
  123.         system("PAUSE");
  124.     }
  125.  
  126.     void display_total_all_items_stored()
  127.  
  128.     {    
  129.         int sum  = 0;
  130.         int r, c;                                       
  131.         double cost;
  132.         for( r=0; r<row; r++ )
  133.         {
  134.             for( c=0; c<col; c ++ )
  135.             {
  136.                 sum = sum + warehouseshelf[r][c];
  137.                 totalcost= sum*cost;
  138.             }
  139.         }
  140.  
  141.         cout <<"\t"<< "Total sum of items is = " << sum << endl;
  142.             system("PAUSE");
  143.     }
  144.  
  145.     void display_total_value()
  146.     {
  147.         cout <<"\t"<< "Total value is = $" << totalcost << endl;
  148.         system("PAUSE");
  149.     }
  150. };
  151.  
  152. class warehouse
  153. {
  154.  
  155. public:
  156.  
  157.         // function to update address
  158.  
  159.     char *update_address (void)
  160.     {    
  161.         char tempaddress[200];
  162.         cout <<"\t"<< "Enter address: ";
  163.         cin.getline (tempaddress, 200);
  164.         cout << " "<< endl;
  165.         cout <<"\t"<<"Address for the warehouse is "<<tempaddress <<endl;
  166.         cout << " "<< endl;
  167.         int size = strlen (tempaddress);
  168.         char *test = new char[size];
  169.         strcpy (test, tempaddress);
  170.  
  171.         return test;
  172.     }
  173. };
  174.  
  175.  
  176.     //function to show display menu
  177.  
  178.     void display_menu()
  179.  
  180.     {    
  181.         cout << " "<< endl;
  182.         cout <<"\t"<< "Select option " << endl;
  183.         cout <<"\t"<< "-----------------------" << endl;
  184.         cout <<"\t"<< "1) Update item details " << endl;
  185.         cout <<"\t"<< "2) Display item details " << endl;
  186.         cout <<"\t"<< "3) Update warehouse address" << endl;
  187.         cout <<"\t"<< "4) Add items to the warehouse shelf" << endl;
  188.         cout <<"\t"<< "5) Display warehouse detail" << endl;
  189.         cout <<"\t"<< "6) Find total number of items in warehouse" << endl;
  190.         cout <<"\t"<< "7) Find total value in warehouse" << endl;
  191.         cout <<"\t"<< "8) Exit "<<endl;
  192.         cout <<"\t"<< "-----------------------" << endl;
  193.         cout <<"\t"<< "Enter option: ";    
  194.  
  195.     }
  196.  
  197.     void select_choice()
  198.  
  199.     {    
  200.         cout << " "<< endl;
  201.         cout <<"\t"<<"Select TV  "<<endl;
  202.         cout <<"\t"<< "-----------------------" << endl;
  203.         cout <<"\t"<<"1 for TV1"<<endl;
  204.         cout <<"\t"<<"2 for TV2"<<endl;
  205.         cout <<"\t"<<"3 for TV3"<<endl;
  206.         cout <<"\t"<< "-----------------------" << endl;
  207.         cout <<"\t"<< "Enter Brand using 1-3: ";
  208.     }
  209.  
  210.  
  211.  
  212.  
  213. int main(void)
  214. {    int i;
  215.     int choice;
  216.     char *address;
  217.  
  218.  
  219.     TV    brand[3];
  220.     shelf s1;
  221.     s1.initial();
  222.     warehouse w1;
  223.  
  224.  
  225.     do
  226.     {    
  227.         system("cls");
  228.         display_menu();
  229.         cin >> choice;
  230.         cin.ignore();
  231.         switch( choice )
  232.         {    
  233.             case 1:    system("cls");
  234.  
  235.                     {    cout << " "<< endl;
  236.                         cout <<"\t"<<"Update item details" << endl;
  237.                         cout <<"\t"<<"-----------------------"<<endl;
  238.                         select_choice();
  239.  
  240.                         do 
  241.                         {    
  242.                             cin >>i;
  243.  
  244.                             if (i==0||i>3)
  245.                                 {    
  246.                                     cout <<" "<<endl;
  247.                                     cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
  248.                                 }
  249.                             else 
  250.                                 {
  251.                                     brand[i-1].update();
  252.                                 }
  253.                         }
  254.                         while (i==0||i>3);
  255.                     }
  256.  
  257.             break;
  258.  
  259.             case 2:    system("cls");
  260.  
  261.                 {    cout << " "<< endl;
  262.                     cout <<"\t"<<"Display item details" << endl;
  263.                     cout <<"\t"<<"-----------------------"<<endl;
  264.                     select_choice();
  265.  
  266.                 do 
  267.                     {
  268.                         cin >>i;
  269.  
  270.                         if (i==0||i>3)
  271.                             {    
  272.                                 cout <<" "<<endl;
  273.                                 cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
  274.                             }
  275.                         else 
  276.                             {
  277.                                 brand[i-1].display_item();
  278.                             }
  279.                     }
  280.                 while (i==0||i>3);
  281.                 }
  282.  
  283.             break;
  284.  
  285.             case 3:    system("cls");
  286.  
  287.                 cout << " "<< endl;
  288.                 cout <<"\t"<<"Update address" << endl;
  289.                 cout <<"\t"<<"-----------------------"<<endl;
  290.                 cout <<" "<<endl;                
  291.                 address = w1.update_address();
  292.                 system("PAUSE");
  293.                 //cout<< address << endl;
  294.                 break;
  295.  
  296.             case 4:    system("cls");
  297.  
  298.                 {    cout << " "<< endl;
  299.                     cout <<"\t"<<"Update Warehouse Shelfs" << endl;
  300.                     cout <<"\t"<<"-----------------------"<<endl;
  301.                     select_choice();
  302.                 do 
  303.                     {
  304.                         cin >>i;
  305.  
  306.                         if (i==0||i>3)
  307.                             {    
  308.                                 cout <<" "<<endl;
  309.                                 cout <<"\t"<<"Wrong choice. Pls enter 1-3: ";
  310.                             }
  311.                         else 
  312.                             {    cout << " "<< endl;
  313.                                 //brand[i-1].display_item();
  314.                                 s1.update_shelfs(&brand[i-1]);  // ** pass in TV item
  315.                             }
  316.                     }
  317.                 while (i==0||i>3);
  318.                 }
  319.  
  320.             break;
  321.  
  322.             case 5:    system("cls");
  323.  
  324.                 {    cout << " "<< endl;
  325.                     cout <<"\t"<<"Display Warehouse Selfs" << endl;
  326.                     cout <<"\t"<<"-----------------------"<<endl;
  327.                             {    
  328.                                 cout << " "<< endl;
  329.                                 s1.display_shelfs();
  330.                             }
  331.                 }
  332.  
  333.             break;
  334.  
  335.             case 6:    system("cls");
  336.  
  337.                 {    cout << " "<< endl;
  338.                     cout <<"\t"<<"Display Total Items" << endl;
  339.                     cout <<"\t"<<"-----------------------"<<endl;
  340.  
  341.                             {
  342.                                 cout<<" "<<endl;
  343.                                 s1.display_total_all_items_stored();
  344.                             }
  345.                 }
  346.  
  347.             break;
  348.  
  349.  
  350.             case 7: system("cls");
  351.  
  352.                 {    cout << " "<< endl;
  353.                     cout <<"\t"<<"Display Total Value" << endl;
  354.                     cout <<"\t"<<"-----------------------"<<endl;
  355.  
  356.                         {
  357.                             cout<<" "<<endl;
  358.                             s1.display_total_value();
  359.                         }
  360.  
  361.                 }
  362.  
  363.             break;
  364.  
  365.  
  366.             case 8: 
  367.                 cout <<" "<<endl;
  368.             //    setcolor (12);
  369.                 cout <<"\t"<< "Bye Bye. See you again"<<endl;
  370.                 cout<<" "<<endl;
  371.             break;
  372.  
  373.             default:
  374.                 cout<<" "<<endl;
  375.         //        setcolor (12);
  376.                 cout <<"\t"<<"Invalid choice.Pls re-enter again"<<endl;
  377.                 system("PAUSE");
  378.         }
  379.     }     while( choice != 8 );
  380.  
  381.     return 0;
  382. }
  383.  
[/quote]
Jan 29 '07 #8
horace1
1,510 Expert 1GB
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_all_items_stored() and display_total_value()
Jan 29 '07 #9
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_all_items_stored() and display_total_value()[/quote]
Jan 29 '07 #10
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_all_items_stored() and display_total_value()
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
Jan 29 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: chris | last post by:
What is a class ?? is it like a function ?? this has allways confused me as i am a newby to programming (since Basic in the 80's) thanks for any insight you can give
2
by: | last post by:
I have this class ------------- class Component { /*class*/ Data *d; /*class*/ Draw *a; }; ------------- from "Component" derive classes like "TextBox", "Button", "Label", "ComboBox" etc from...
8
by: Gonçalo Rodrigues | last post by:
Hi all, I have a template class (call it Object) whose instances have a variable size part - an array of of T objects. But this variable size part is fixed at creation time so instead of...
6
by: David Lozzi | last post by:
Howdy, I'm new to classes. Below is my class User. (is this a reserved namespace or class?) It works great, kind of. If I specify the username and password, the correct firstname and lastname...
7
by: Ron | last post by:
Hello, I have 4 classes that use 4 DTS packages on 4 different tables. So I have Dim cls1 As New clsDTS1, cls2 As New clsDTS2 Dim cls3 As New clsDTS3, cls4 As New clsDTS4 Each class has a...
6
by: Peter Oliphant | last post by:
I just discovered that the ImageList class can't be inherited. Why? What could go wrong? I can invision a case where someone would like to add, say, an ID field to an ImageList, possible so that...
9
by: me | last post by:
Hi All, I am new to Classes and learniing the ropes with VB.NET express Here's my question - say I have a want to manage a list of books. Each book has an Author, Title and ISBN Now, I am...
10
by: Peter Duniho | last post by:
This is kind of a question about C# and kind of one about the framework. Hopefully, there's an answer in there somewhere. :) I'm curious about the status of 32-bit vs 64-bit in C# and the...
12
by: David | last post by:
Hi, I want to be able to make a class only visible within the namespace, i.e. only other classes within the namespace will have access to it. I have tried putting a protected keyword against...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.