Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

*It would be appreciated if you could take a picture or snapshot and put it up.

ID: 3812544 • Letter: #

Question

*It would be appreciated if you could take a picture or snapshot and put it up. I need help to write a C++ program to keep track of a store inventory. The store sells various items. For each item in the store, the following information is kept: item ID, item name, number of pieces ordered, number of pieces currently in the store, number of pieces sold, manufacturer’s price for the item, and the store’s selling price. At the end of each week, the store manager would like to see a report in the following form:

YOUOWEIT Hardware Store:

4444

3333

.

.

.

Circular Saw

Cooking Range

150

50

150

50

40

20

45.00

450.00

125.00

850.00

---

The total inventory is the total selling value of all of the items currently in the store. The total number of items is the sum of the number of pieces of all of the items in the store. Your program must be menu driven, giving the user various choices, such as checking whether an item is in the store, selling an item, and printing the report. After inputting the data, sort it according to the item’s names. Also, after an item is sold, update the appropriate counts. Initially, the number of pieces (of an item) in the store is the same as the number of pieces ordered, and the number of pieces of an item sold is zero. Input to the program is a file consisting of data in the following form:

itemID

itemName

Ordered In Store Sold Manufacturer Price Selling Price

Your program should use seven vectors to store the inventory information and it must implement the following functions:

(a) A function to read the data file (text file) and store the information in seven vectors

(b) A function to display the following menu:

1. Print report

2. Print sorted report (by Item Name)

3. Check an item is in the store (by Item ID)

4. Sell an item

5. Add item to the inventory

6. Save file

7. Quit (this option should automatically save the content of the seven vectors before existing program)

(c) A function to print the content of seven vectors similar to the report shown above

(d) A function to print one item information

(e) A function to sort the content of the seven vectors in ascending order by item name (be sure to swap the contents of the other six vectors as you sort the vector containing the item name)

(f) A function to save the content of the seven vectors to the original text file (Be sure to store them in a similar format as the original file).

(g) A function to search for an item (by Item ID) and calls the print item function to display the result (if it exists) as follows:

itemName:

Ordered:

In Store:

Sold:

Manufacturer Price:

Selling Price:

(h) A function to sell an item. After an item is sold, update the appropriate counts.

(i) A function to add inventory. This function should ask the user for Item ID and if the item exists it updates the ordered and the in store counts. Otherwise, the user must enter all information required by the database (itemName, Ordered, In Store, Manufacturer Price, and Selling Price). Note: Sold count is zero.

Item ID Item Name Ordered In Store Sold Manufacturer Price Selling Price

4444

3333

.

.

.

Circular Saw

Cooking Range

150

50

150

50

40

20

45.00

450.00

125.00

850.00

Total Inventory: $#########.## Total number of items in the store: -----

---

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

Explanation / Answer

Hi, I've managed to write most of the functions for you for this question. I'm running out of time so can't complete the sorting one. You will need to convert each letter of the string to either upper or lower case for comparision of strings; can't use the vector::sort() function as other vectors also need to be simultaneously sorted. Below are the functions that I could complete. Do let me know if you need more help.

#include <iostream>
#include<fstream>
#include<iomanip> //this is included for using setw() and right, left to correctly left/right justify the output
//setw() sets the width which will be available for the output
#include<string>
#include<vector>


using namespace std;

vector<int> itemID;
vector<string> itemName;
vector<long> ordered;
vector<long> inStore;
vector<long> sold;
vector<double> manuPrice; //manufacturer price
vector<double> selPrice; //selling price

bool readfile()
{
ifstream infl("input.txt"); //open input file for reading
if(!infl)
{
cout<<"Unable to open data file... ";
return false;
}

int id;
string name;
string line;
long ord, inSt,sld;
double mp,sp;
while(infl>>id>>name>>ord>>inSt>>sld>>mp>>sp)//start reading one record, exit loop at EOF
{ //add item id and item name to the resp. vectors
itemID.push_back(id);
itemName.push_back(name);
ordered.push_back(ord);
inStore.push_back(inSt);
sold.push_back(sld);
manuPrice.push_back(mp);
selPrice.push_back(sp);
}
return true;
}
void showMenu()
{
cout<<"Enter the number of your choice of activity from below:-"<<endl;
cout<<"1. Print Report"<<endl<<"2. Print Sorted Report (By Item Name)"<<endl;
cout<<"3. Check an item is in the store (by Item Id)"<<endl<<"4. Sell an item"<<endl;
cout<<"5. Add item to the inventory"<<endl<<"6. Save the file"<<endl;
cout<<"7. Quit"<<endl;
cout<<"Enter your choice : ";
}
void printReport()
{
//create iterators for each vector
vector<int>::iterator itemID_iter;
vector<string>::iterator itemName_iter;
vector<long>::iterator ordered_iter;
vector<long>::iterator inStore_iter;
vector<long>::iterator sold_iter;
vector<double>::iterator manuPrice_iter; //manufacturer price
vector<double>::iterator selPrice_iter; //selling price

//display headings
cout<<setw(10)<<left<<"Item ID"<<setw(20)<<"Item Name"<<setw(10)<<right<<"Ordered"<<setw(10)<<"In Store"<<setw(10)<<"Sold"<<setw(25)<<"Manufacturer Price"<<setw(25)<<"Selling Price"<<endl;
//display the data on each line
for(itemID_iter=itemID.begin();itemID_iter!=itemID.end();itemID_iter++)
{
cout<<setw(10)<<left<<*itemID_iter<<setw(20)<<*itemName_iter<<setw(10)<<right<<*ordered_iter<<setw(10)<<*inStore_iter<<setw(10)<<*sold_iter<<setw(25)<<*manuPrice_iter<<setw(25)<<*selPrice_iter<<endl;
itemName_iter++;
ordered_iter++;
inStore_iter++;
sold_iter++;
manuPrice_iter++;
selPrice_iter++;
}
}

void printItem(int id) //print one item info given its id
{
//create iterators for each vector
vector<int>::iterator itemID_iter;
vector<string>::iterator itemName_iter;
vector<long>::iterator ordered_iter;
vector<long>::iterator inStore_iter;
vector<long>::iterator sold_iter;
vector<double>::iterator manuPrice_iter; //manufacturer price
vector<double>::iterator selPrice_iter; //selling price

//find the item
for(itemID_iter=itemID.begin();*itemID_iter!=id && itemID_iter!=itemID.end();itemID_iter++)
{
itemName_iter++;
ordered_iter++;
inStore_iter++;
sold_iter++;
manuPrice_iter++;
selPrice_iter++;
}
//print item details if item found
if(*itemID_iter==id)
cout<<"Item Name :"<<*itemName_iter<<endl<<"Ordered :"<<*ordered_iter<<endl<<"In Store :"<<*inStore_iter<<endl<<"Sold :"<<*sold_iter<<endl<<"Manufacturer Price :"<<*manuPrice_iter<<endl<<"Selling Price :"<<*selPrice_iter<<endl;
else
cout<<"Item Not Found"<<endl;
}

void sortbyname()
{
//use any sorting technique you like
}

void saveFile()//save the vectors to the data file
{
ofstream ofl("input.txt"); //open input file for writing
if(!ofl)
{
cout<<"Unable to open data file... ";
return;
}
//create iterators for each vector
vector<int>::iterator itemID_iter;
vector<string>::iterator itemName_iter;
vector<long>::iterator ordered_iter;
vector<long>::iterator inStore_iter;
vector<long>::iterator sold_iter;
vector<double>::iterator manuPrice_iter; //manufacturer price
vector<double>::iterator selPrice_iter; //selling price

for(itemID_iter=itemID.begin();itemID_iter!=itemID.end();itemID_iter++)
{
ofl<<*itemID_iter<<endl<<*itemName_iter<<endl; //write item id and name on separate lines and go to next line to write the rest of the record
ofl<<*ordered_iter<<" "<<*inStore_iter<<" "<<*sold_iter<<" "<<*manuPrice_iter<<" "<<*selPrice_iter<<endl; //write the rest of the record and go to next line
//go to next record
itemName_iter++;
ordered_iter++;
inStore_iter++;
sold_iter++;
manuPrice_iter++;
selPrice_iter++;
}

}
void sellItem(int id)//sell an item based on its id
{
//create iterators for required vectors
vector<int>::iterator itemID_iter;
vector<long>::iterator inStore_iter;
vector<long>::iterator sold_iter;

//find the item
for(itemID_iter=itemID.begin();*itemID_iter!=id && itemID_iter!=itemID.end();itemID_iter++)
{
inStore_iter++;
sold_iter++;
}
//update the in store and sold counts for the item
(*inStore_iter)--;
(*sold_iter)++;
}

void addInventory(int id)
{
//create iterators for each vector
vector<int>::iterator itemID_iter;
vector<string>::iterator itemName_iter;
vector<long>::iterator ordered_iter;
vector<long>::iterator inStore_iter;
vector<long>::iterator sold_iter;
vector<double>::iterator manuPrice_iter; //manufacturer price
vector<double>::iterator selPrice_iter; //selling price

//find the item
for(itemID_iter=itemID.begin();*itemID_iter!=id && itemID_iter!=itemID.end();itemID_iter++)
{
itemName_iter++;
ordered_iter++;
inStore_iter++;
sold_iter++;
manuPrice_iter++;
selPrice_iter++;
}
//if item found update the ordered and instore counts
if(*itemID_iter==id)
{
int ord; //items ordered
cout<<"Enter the number of items ordered : ";
cin>>ord;
(*ordered_iter)+=ord;
(*inStore_iter)+=ord;
}
else //if item not found, create a new record
{
string name;
long ord, inSt,sld;
double mp,sp;
cout<<"Creating new record for item"<<endl;
itemID.push_back(id);
cout<<"Enter Item Name : ";
itemName.push_back(name);
cout<<"Enter number of ordered items :";
ordered.push_back(ord);
inSt=ord; //in the beginning in store items = ordered items
inStore.push_back(inSt);
sld=0; //in the beginning sold=0
sold.push_back(sld);
cout<<"Enter Manufacturer price :";
cin>>mp;
manuPrice.push_back(mp);
cout<<"Enter Selling price :";
cin>>sp;
selPrice.push_back(sp);
}

}

Hope this helps!