Source Code for Challenging Programs

Problem:

For this project you'll be writing a program to help me get the best deals on my shopping list. I've gathered the inventories of a few local stores, so I can track what items they have in stock and how much they are selling things for. With that information [and knowing what I need to purchase], can assemble a list of what I need to purchase from each location. Here's the format for the store's inventories: 4 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

-------------------

Project.cpp

#include <iostream> #include <fstream> #include <string> using namespace std; struct item_list { string item_name; int quantity; float price; }; struct s { string store_name; string location; struct item_list items[10]; }; int main() { ifstream fin("stores.txt"); int n,m; struct s stores[10]; //cout<<"Enter no. of stores"<<endl; fin>>n; for(int i=0;i<n;i++) { //cout<<"Enter store "<<i+1<<" name:"<<endl; fin>>stores[i].store_name; //cout<<"Enter store "<<i+1<<" address:"<<endl; fin>>stores[i].location; //cout<<"Enter how many items in store "<<i+1<<endl; fin>>m; for(int j=0;j<m;j++) { //cout<<"Enter item "<<j+1<<" detais:(item name, no.of items, cost)"<<endl; fin>>stores[i].items[j].item_name; fin>>stores[i].items[j].quantity; fin>>stores[i].items[j].price; } } cout<<"Store Related Information (orderd by in-file order)"<<endl; cout<<"There are "<<n<<"stores"<<endl; for(int i=0;i<n;i++) { cout<<"store "<<i+1<<" details"<<endl; cout<<"store name:"<<stores[i].store_name<<endl; cout<<"store address:"<<stores[i].location<<endl; cout<<"store "<<i+1<<" items:"<<endl; cout<<"item name\t\tno.of items\t\titem cost"<<endl; for(int j=0;j<m;j++) { cout<<stores[i].items[j].item_name<<"\t\t\t"; cout<<stores[i].items[j].quantity<<"\t\t\t"; cout<<"$"<<stores[i].items[j].price<<endl; } } }

stores.txt

2 CornerStore EastLansing 2 Milk 30 2.00 Eggs 2 0.50 Sparty's EastLansing 2 Candy 10 0.85 Soda 4 1.50