Hi! I'm working on writing a code that's due in a few hours.
The code, when given an input like:
1 Stores:
Local Grocery
East Lansing
Apples,10,$4.76
1 items on my shopping list:
1 Apples
will return a number of informational statements about these things. My code is close to working on a few of the test cases, however, later on the inputs become more difficult, such as:
6 Stores:
Local Grocery
East Lansing
Apples,10,$4.76
Sandwich,2,$1.99
Olive Bread,3,$2.99
Milk,7,$1.25
Eggs,40,$0.78
Candy,4,$0.51
Fast Food Dispenser
Lansing
Soda,3,$1.01
Burger,2,$2.00
Fries,100,$0.50
Electronics R Here
Ann Arbor
Bargain Phone,2,$200.00
S Phone,4,$650.00
Fruit Phone,2,$700.00
TV,10,$4000.00
Corner Store
East Lansing
Milk,30,$2.00
Eggs,2,$0.50
Candy,6,$1.00
Soda,5,$1.56
Bargain Phone,3,$185.00
Sparty's
East Lansing
Candy,10,$0.85
Soda,4,$1.50
Sandwich,3,$2.99
Stolen Goods
Neighbor's House
Candy,3,$0.00
TV,4,$4.00
5 items on my shopping list:
105 Candy
5 Soda
1 S Phone
10 TV
1 Burger
An example of the correct outputs should contain this information:
Store Related Information (ordered by in-file order):
There are 6 store(s).
Local Grocery has 6 distinct items.
Fast Food Dispenser has 3 distinct items.
Electronics R Here has 4 distinct items.
Corner Store has 5 distinct items.
Sparty's has 3 distinct items.
Stolen Goods has 2 distinct items.
Item Related Information (ordered alphabetically):
There are 13 distinct item(s) available for purchase.
There are 10 Apples(s).
There are 5 Bargain Phone(s).
There are 2 Burger(s).
There are 23 Candy(s).
There are 42 Eggs(s).
There are 100 Fries(s).
There are 2 Fruit Phone(s).
There are 37 Milk(s).
There are 3 Olive Bread(s).
There are 4 S Phone(s).
There are 5 Sandwich(s).
There are 12 Soda(s).
There are 14 TV(s).
Shopping:
Trying to order 105 Candy(s).
4 store(s) sell Candy.
Total price: $16.54
Order 3 from Stolen Goods in Neighbor's House
Order 4 from Local Grocery in East Lansing
Order 10 from Sparty's in East Lansing
Order 6 from Corner Store in East Lansing
Trying to order 5 Soda(s).
3 store(s) sell Soda.
Total price: $6.03
Order 3 from Fast Food Dispenser in Lansing
Order 2 from Sparty's in East Lansing
Trying to order 1 S Phone(s).
1 store(s) sell S Phone.
Total price: $650.00
Order 1 from Electronics R Here in Ann Arbor
Trying to order 10 TV(s).
2 store(s) sell TV.
Total price: $24016.00
Order 4 from Stolen Goods in Neighbor's House
Order 6 from Electronics R Here in Ann Arbor
Trying to order 1 Burger(s).
1 store(s) sell Burger.
Total price: $2.00
Order 1 from Fast Food Dispenser in Lansing
Be sure to bring $24690.57 when you leave for the stores.
My code so far can produce the number of stores and distinct items, though I'm having trouble with the Shopping: part of the output.
cout << "Store Related Information (ordered by in-file order):" << endl;
cout << "There are " << storenum << " store(s)." << endl;
for(vector<string> i: bigtemp){
cout << i[0] << " has " << (i.size()-3) << " distinct items." << endl;
}
cout << "" << endl;
int totaldistinct=0;
for(vector<string> i: items){
totaldistinct += (i.size()/3);
}
cout << "Item Related Information (ordered alphabetically):" << endl;
cout << "There are " << totaldistinct << " distinct item(s) available for purchase." << endl;
int counter = 0;
for(vector<string> i: newitems){
if(!i.empty()){
cout << "There are " << i[1] << " " << i[0] << "(s)." << endl;
if(i[0]==newvecs[1]){
counter += 1;
}
}
}
cout << "" << endl;
cout << "Shopping:" << endl;
cout << "Trying to order " << newvecs[0] << " " << newvecs[1] << "(s)." << endl;
cout << counter << " store(s) sell " << newvecs[1] << "." << endl;
double price = 0;
string location = "bad";
string store = "wrong";
price = 6.6666666;
int tally = 0;
for(vector<string> i: newitems){
if(newvecs[1] == i[0]){
for(vector<string> x: bigtemp){
location = x[1];
store = x[0];
}
}
tally += 1;
}
cout << "Total price: $" << price << endl;
cout << "Order " << newvecs[0] << " from " << store << " in " << location << endl;
cout << "" << endl;
cout << "Be sure to bring $" << price << " when you leave for the stores." << endl;
}
I'm thinking that my next step should be to create a 3D vector that will have a vector containing each store and then, inside each store, another vector for each set of information and lastly, inside the information vector, a vector for each part of each item.
Very sorry for how lengthy the question is and the lack of formatting in the code!
Is making a 3d vector the best way to store all of this information?
Would there be a better way to move forward from here?
Is making a 3d vector the best way to store all of this information?
Probably not. Using multidimensional vectors will get complicated/confusing very quickly. Think about using a class or two to hold the information, and then possibly a vector of those classes.
class 1:
Store Related Information
Would contain things like store name, address, etc., along with a vector of inventory (class 2)
class 2:
Item Related Information (ordered alphabetically):
There are 13 distinct item(s) available for purchase.
Would contain things line item description, item number, quantity on hand, etc.
class 3:
Order 3 from Stolen Goods in Neighbor's House
Would contain things like delivery address, customer name, etc., along with a list of items ordered ( a vector of inventory)