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.
#include<iostream>
#include<string>
#include<iomanip>
#include<fstream>
usingnamespace std;
// Program function declarations
#include "Functions.h"
#include "Item.h"
// Maximum array major dimension
constint 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 partint 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?
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?