need help with class object arrays and member functions

my latest assignment in my intro class is to write a program that uses a class to create an array of class objects, displays the array contents and give a menu for changing the values in the array's objects (inventory system) and i'm having some serious problems..i have to load the object array from parallel arrays.. i've inserted some dummy code to display as i go along, and the parallel arrays show up fine, the cout<< within the constructor shows fine, but my class function displayAllBins keeps showing the constructors defaults.. you see a lot of comment out stuff that i need to wkr on still, but i'm hoping that with some help i can figure that out by getting displayAllBins to work... ok here's my code..
first the class cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//********************************************************************
//PROGRAM 4
//********************************************************************
#include <iostream>
#include <iomanip>
#include <fstream>
#include <math.h>
#include <windows.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include "prog4classesandfuncts.h"
//#include "ConsoleIOManager.h"

using namespace std;
//********************************************************************
//CLASSES
//********************************************************************

//********************************************************************
//Class InvBin
//********************************************************************
     InvBin::InvBin (string d = "empty", int q = 0)//2-parameter constructor
     {description = d; qty = q;}             //with default values

// It will also have the following public member functions. They
//will be used by the BinManager class, not the client program.

//void setDescription( string d );
//string getDescription();
//void setQty ( int q );
//int getQty();

//********************************************************************
//Class BinManager
//********************************************************************

    BinManager::BinManager()                    // default constructor
    { numBins = 0;}


    BinManager::BinManager(int size, string d[ ], int q[ ])
    {
       // 3-Parameter constructor:: Recieves number of  
      //bins in use and parallelarrays of item names and 
      //quantities. Uses this info. to store values in the 
      //elements of the bin array. Remember, these elements 
      //are InvBin objects.
      int index;
      cout<<"constructor"<<endl;
        for( index=0 ; index < size ; index++ )
      {
            InvBin bin(d[index], q[index]);
           cout<<fixed<<left<<index +1<<"   ";
            cout<<setw(20)<<bin.getDescription();
            cout<<"    "<<bin.getQty()<<endl;
            
           
      }
Sleep(2000);
   }

// the class will also have the following public member functions:

  //   string getDescription(int index);  //returns name of one item
  //   int getQuantity(int index) ;       // returns qty of one item
    // string DisplayAllBins() ;   //returns string having one line 
                                  //for each item
 //    bool addParts(int binIndex, int q); //these returns true if the
 //   bool removeParts(int binIndex, int q); //action was done and false
                                       // if it could not be done-
                                     //see validation information





//******************************************************************
//FUNCTIONS
//******************************************************************

//***************class InvBin***************************

void InvBin::setDescription ( string d )
{ description = d ;
    
}

string InvBin::getDescription()
{  
   return description;
}

void InvBin::setQty(int q)
{
 qty = q ;
}

int InvBin::getQty( )
{
    return qty;
}

/*
//*************class BinManager******************

string getDescription ( int index )    
    {bin[index].d = d[index]
    return bin[index].d
    }
    
    ;


int getQuantity (int index)
{
   
        for( index=0 ; index < 10 ; index++ )
      {
         {InvBin::bin[index].q = q[index]};
      }
};
*/
string BinManager::DisplayAllBins()
{
       int i;
       cout<< "Current Inventory: "<<endl;
       cout<<"still not working"<<endl;
       for (i=0; i<9;i++)
       {
           cout<<fixed<<left<<i<<setw(20);
           cout<<bin[i].getDescription();
            cout<<"    "<<bin[i].getQty()<<endl;
       }
       Sleep(4000);
return 0 ;
};


here's the class header file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef PROG4CLASSESANDFUNCTS_H
#define PROG4CLASSESANDFUNCTS_H


#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <math.h>
#include <windows.h>
#include <string>
#include <cstdlib>



using namespace std;
//********************************************************************
//CLASSES
//********************************************************************
//************************************************************
//
//************************************************************
//********************************************************************
//Class InvBin
//********************************************************************
class InvBin
{
private:
     string description;  // item name
     int qty;                     // Quantity of items
                                      // in this bin
public:
     InvBin (string d , int q );//2-parameter constructor
               //with default values

// It will also have the following public member functions. They
//will be used by the BinManager class, not the client program.

void setDescription( string d );
string getDescription();
void setQty ( int q );
int getQty();
};

//********************************************************************
//Class BinManager
//********************************************************************
class BinManager
{
private:
   InvBin bin[30];                 //array of InvBin objects
   int numBins;                   // number of bins
                               //currently in use

public:
    BinManager();                    // default constructor


    BinManager(int size, string d[], int q[]);
  
// the class will also have the following public member functions:

     string getDescription(int index);  //returns name of one item
     int getQuantity(int index) ;       // returns qty of one item
     string DisplayAllBins() ;   //returns string having one line 
                                  //for each item
     bool addParts(int binIndex, int q); //these returns true if the
     bool removeParts(int binIndex, int q); //action was done and false
                                      // if it could not be done-
                                     //see validation information
};



#endif 

to continue... here's my main and the output..


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <iomanip>
#include <fstream>
#include <math.h>
#include <windows.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include "prog4classesandfuncts.h"
//#include "ConsoleIOManager.h"

//***************************************************************
//  Usings
//*****************************************************************
using namespace std;
//***************************************************************
//  Main Functioin
//***************************************************************
int main()
{
   
   string d[9]={"Regular pliers",
            "N.nose pliers",
            "screwdriver",
            "P.head screwdriver",
            "Wrench-large",
            "Wrench-small",
            "Drill",
            "Cordless drill",
            "Hand saw" };
     int q[9]={25,5,25,6,7,18,51,16,12};
     
     int i;
     cout<<"parrallels"<<endl;
     for (i=0; i<9; i++)
     {
         cout<<fixed<<left<<setw(20);
         cout<< d[i]<<"     "<<q[i]<<endl;
     }
     Sleep(5000);
     
     BinManager::BinManager binMan(9,d,q);
     //string getDescription(int index);
     //int getQuantity(int index) ;
      binMan.DisplayAllBins();
     Sleep(2000);
     
     
     
};


i left in comments that might help and left out what i thought was extraneous for now.. and last but not least, the output..


parrallels
Regular pliers           25
N.nose pliers            5
screwdriver              25
P.head screwdriver       6
Wrench-large             7
Wrench-small             18
Drill                    51
Cordless drill           16
Hand saw                 12
constructor
1   Regular pliers          25
2   N.nose pliers           5
3   screwdriver             25
4   P.head screwdriver      6
5   Wrench-large            7
6   Wrench-small            18
7   Drill                   51
8   Cordless drill          16
9   Hand saw                12
Current Inventory:
still not working
0empty                   0
1empty                   0
2empty                   0
3empty                   0
4empty                   0
5empty                   0
6empty                   0
7empty                   0
8empty                   0

Topic archived. No new replies allowed.