Question: Given the two attached .txt files containing data about books and online market company names and addresses, produce a report listing books in order by

Given the two attached .txt files containing data about books and online market company names and addresses, produce a report listing books in order by company with indicated totals and statistical information. The first attached text file (books.txt) contains a header line and 100 lines of data. Each of the 100 lines is an inventory record and contains data associated with a single book title listed on an online internet market. The file is tab-delimited. This is a very common format used to exchange text data between systems. HINT: If you open the file with Excel, it is much easier to read and get a look at what the data actually looks like in a columnar fashion. Since Excel is not available on the IDE server, you can clipboard copy/paste the file from the server to a local file and open it in Excel on your local PC if you have Excel. The second attached text file (markets.txt) also contains a header line and a line for each of the markets that appears for the books in the books.txt file. It is also tab-delimited and of the same basic format as the books.txt file. It also may be viewed easier from Excel. Your final project is to produce a formatted readable report to an output file report.txt that lists all of the books and groups them by market. Only title, ISBN, author, quantity, price, and inventory value need be listed for each book. For each market, include the name of the market, the total number of inventory records (the same title may appear more than once) listed for that market, the total quantity of books for that market, the total market value of all of the books for that market, the average book price for that market, and the markets name, company name, and address information from the markets.txt file. At the very end of the report, provide the total number of inventory records for all markets, the total quantity of books for all markets, the total market value of all of the books for all markets, and the average book price for all markets. Save your work in your remote server Visual C++ Projects folder under a new folder called VCFinal. Your final project must be delivered as "ready to build" Visual C++ projects. For grading, your project will be built, run, and inspected. Make sure you include the above input files in your projects default folder. Design Requirements: 1. Reading the books.txt must be done by a function readBooks. The books.txt data must be stored in an array of book structs. The book struct is to contain the data elements per the header line field names from the books.txt file. 2. Reading the markets.txt must be done by a function readMarkets. The markets.txt data must be stored in an array of market structs. The market struct is to contain the data elements per the header line field names from the markets.txt file. 3. If the market of a book is not found in the markets file, display the value UNKNOWN in the company-name and null values in all of the other market report fields.

so far I have:

#include #include #include #include

using namespace std;

struct book { string itemName; string listingID; string sellerSku; string price; double fprice; string quantity; int iquantity; string openDate; string itemNote; string quality; string productID; string market; }; struct market { string productMarket; string name; string address; string city; string date; string country; };

void readBooks(book books[], int &size, int MAX_SIZE); void readMarkets(market markets[], int &size, int MAX_SIZE); void displayData(book books[], market markets[], int &size, int MAX_SIZE);

int main() {

const int MAX_SIZE = 200; int size = 0; int choice; book books[MAX_SIZE]; market markets[MAX_SIZE];

ifstream infile; ifstream outfile;

readBooks (books, size, MAX_SIZE); readMarkets(markets, size, MAX_SIZE); displayData(books, markets, size, MAX_SIZE);

infile.close();

system("pause"); return 0; }

void readBooks(book books[], int &size, int MAX_SIZE) { ifstream infile; infile.open("books.txt"); string line;

while (infile && size < MAX_SIZE) { getline(infile, books[size].itemName, '\t'); getline(infile, books[size].listingID, '\t'); getline(infile, books[size].sellerSku, '\t');

getline(infile, books[size].price, '\t'); books[size].fprice = atof(books[size].price.c_str());

getline(infile, books[size].quantity, '\t'); books[size].iquantity = atoi(books[size].quantity.c_str());

getline(infile, books[size].openDate, '\t'); getline(infile, books[size].itemNote, '\t'); getline(infile, books[size].quality, '\t'); getline(infile, books[size].productID, '\t'); getline(infile, books[size].market, ' '); getline(infile, line); size++; }

cout << "You have successfully populated the array" << endl; infile.close(); }

void readMarkets(market markets[], int & size, int MAX_SIZE) {

ifstream infile; infile.open("markets.txt"); string line;

while (infile && size < MAX_SIZE) {

getline(infile, markets[size].productMarket = atoi(line.c_str()), '\t');

getline(infile, markets[size].name = atoi(line.c_str()), '\t');

getline(infile, markets[size].address = atoi(line.c_str()), '\t');

getline(infile, markets[size].city = atoi(line.c_str()), '\t');

getline(infile, markets[size].date = atoi(line.c_str()), '\t');

getline(infile, markets[size].country = atoi(line.c_str()), '\t');

}

cout << "You have successfully read the file." << endl;

infile.close();

}

void displayData(book books[], market markets[], int &size, int MAX_SIZE) {

for (int i = 0; i < size; i++) { cout << endl; cout << "Book Number: " << (i + 1) << endl; cout << "Book title: " << books[i].itemName << endl; cout << "Listing ID: " << books[i].listingID << endl; cout << "Seller Sku: " << books[i].sellerSku << endl; cout << "Book price: " << books[i].fprice << endl; cout << "Quantity : " << books[i].iquantity << endl; cout << "Open Date: " << books[i].openDate << endl; cout << "Quality: " << books[i].quality << endl; cout << "Product ID: " << books[i].productID << endl; cout << "Market sellers: " << books[i].market << endl; }

if (size != 0) cout << "You have successfully printed the array" << endl; else cout << "Array is empty. Read the file first" << endl;

}

All the data is read into arrays properly. How do I sort the tabbed information into a new array function for calculations and printing

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!