Assignment Help (Classes/Arrays)

Hey guys,

First time poster here. I've been working on an assignment involving classes and arrays that has me stuck. I was hoping someone might be able to give me some advice.

I am 99% sure I have the class set up properly. The thing that has me stuck is part of the assignment requires that I take several seperate arrays and establish a single array that works in all functions in their place.

I'll try and keep it short instead of posting all my code and just show you the part where I am stuck.

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
#include<iostream>
#include<string>
#include<iomanip>
#include<fstream>

using namespace std;

// Program function declarations
#include "Functions.h"
#include "Item.h"

// Maximum array major dimension
const int MAX_PARTS = 6;

//	Number used to update item quantity
int quanNum; 
//-----------------------------------------------------------------------------

int main()
{

     // Class Array
     Item itms[MAX_PARTS];

    // declare parallel arrays for record values
    int partAndQuantity[MAX_PARTS][2] = {0};    // 2-dim for part# and qty
    double price[MAX_PARTS] = {0.0};            // price of part
    string description[MAX_PARTS] = {""};       // description of part


    int recordCount = 0;                        // record counter

    ifstream inFile("Inventory.dat");

    // read first data item in a record
    inFile >> partAndQuantity[recordCount][0];

    // while not end-of-file and still room in array
    while(inFile && recordCount < MAX_PARTS)
    {
        // read remaining data items for this record
        inFile >> partAndQuantity[recordCount][1];
        inFile >> price[recordCount];
        inFile.ignore(1);                           // skip space
        getline(inFile, description[recordCount]);

        // keep track of how many records
        recordCount++;

        // if we have room in the array,
        // try to read first item for next record
        if(recordCount < MAX_PARTS)
            inFile >> partAndQuantity[recordCount][0];
    }

    inFile.close();


So I bolded the part that has me stuck so far, as you can see there are multiple arrays used to read data from a file, I basically need to use the Item itms as a replacement for the other arrays to end up only using a single array throughout the program. I can't figure out how, anytime I try something like replacing previous arrays( partAndQuantity[MAX_PARTS][2] = {0}; ) with something like (itms[MAX_PARTS][2] = {0};) I get nothing but errors.

Is there any advice you can give me to get me started?

Thank you!
it's all OK, i've tried it on my comp, and it's ok.
If you realy think something's not good, post the rest of the code and the headers
Yes the code that is in place now is okay, it was part of a previous assignment.
The new assignment involves replacing the current arrays with a single array (which I have been trying with "Item itms", however anytime I try it seems to fail to work.

Would you be able to give me an example of how I would use my class array to replace the current arrays in that code?

Thanks!
Topic archived. No new replies allowed.