Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm working on a program that reads a series of data records from a file(screenshot of file below) and stores each record in a linked

I'm working on a program that reads a series of data records from a file(screenshot of file below) and stores each record in a linked list in ascending order by items number and then prints the report.

image text in transcribed

It also inputs a list of item numbers from a file(it will be called purge_items.dat) and from those item numbers listed in the file, I'm to delete the item record if the corresponding item's age is MORE than 5 years old AND the items sold is LESS than 10% if the item_count. However, if the item number is NOT listed in the list from the supplied file, ignore it and go on to the next item number from the purge_items.dat file. This should generate a new inventory report (call it "new_inventory_report.txt") with the purged items removed.

I also need to add "The percent decrease in revenue: %%" to the new inventory report

I need to make two changes, namely change my array of months to switch cases and print another file (call it "purged_files.txt") that just shows the items that were removed from the inventory report because they met the credentials for purging mentioned above.

My current code is below:

#include #include #include #include #include #include #include using namespace std; struct RECORDS { int itemNumber; string itemCategory; int mo; int day; int year; float itemCost; int itemCount; int itemsSold; RECORDS *next; }; void insert(RECORDS*& Head, RECORDS * itemPntr) { RECORDS* prev = NULL; RECORDS* curr = NULL; //If head is empty. if (Head == NULL) { Head = itemPntr; } //Compares item numbers at head of list. else if (Head != NULL && Head->itemNumber > itemPntr->itemNumber) { itemPntr->next = Head; Head = itemPntr; } //If the new item number is less than head item number. //Compares and adds item in middle of list. else { curr = Head; while(curr != NULL) { if (curr->itemNumber > itemPntr->itemNumber) { prev->next = itemPntr; itemPntr->next = curr; break; } prev = curr; curr = curr->next; } //Item placed at end of list. if(curr == NULL) prev->next = itemPntr; } } void print(RECORDS * Head) { ofstream outF; outF.open("invrpt.dat"); float totalRevenue = 0; float totalRevLost = 0; //Array for month conversion. string months[13]; months[0]= "def"; months[1]= "Jan."; months[2]= "Feb."; months[3]= "Mar."; months[4]= "Apr."; months[5]= "May"; months[6]= "June"; months[7]= "July"; months[8]= "Aug."; months[9]= "Sept."; months[10]= "Oct."; months[11]= "Nov."; months[12]= "Dec."; //Pointer for date. time_t t = time(NULL); tm*timePtr = localtime(&t); int sub2 = timePtr->tm_mon + 1; //Print to screen. cout tm_mday) tm_year)+1900 tm_mday) tm_year)+1900 tm_year) + 1900 - node1->year; //Calculate item revenue, total revenue, and revenue lost. float itmRevenue = node1->itemCost*node1->itemsSold; float revLost = node1->itemCost*(node1->itemCount-node1->itemsSold); totalRevLost+= revLost; if(node1->year >= 2018) age = 0; else if (node1->year >= 2017 && node1->mo >= (timePtr->tm_mon) + 6) age = 0; else if ((timePtr->tm_mon) - (node1->mo) + 6 >= 0) age += 1; //Calculate percentage of item sold. int sub = node1->mo; int sold = node1->itemsSold; int cnt = node1->itemCount; int itemPrcnt = (sold * 100)/ cnt; //Print to screen. cout itemNumber day year; cout itemCount itemsSold itemNumber day year; outF itemCount itemsSold / node1->itemCount) next; }; //Print to screen. cout tm_mon + 1; //Print to screen. cout tm_mday) tm_year)+1900 tm_mday) tm_year)+1900 tm_year) + 1900 - node1->year; //Calculate item revenue, total revenue, and revenue lost. float itmRevenue = node1->itemCost*node1->itemsSold; float revLost = node1->itemCost*(node1->itemCount-node1->itemsSold); totalRevLost+= revLost; if(node1->year >= 2018) age = 0; else if (node1->year >= 2017 && node1->mo >= (timePtr->tm_mon) + 6) age = 0; else if ((timePtr->tm_mon) - (node1->mo) + 6 >= 0) age += 1; if ((age >= 5) && (node1->itemsSold itemCount)) { // outF itemNumber next; continue; } //Calculate percentage of item sold. int sub = node1->mo; int sold = node1->itemsSold; int cnt = node1->itemCount; int itemPrcnt = (sold * 100)/ cnt; //Print to screen. cout itemNumber day year; cout itemCount itemsSold itemNumber day year; outF itemCost itemsSold next; }; //Print to screen. cout > newNode->itemNumber; inF >> newNode->itemCategory; inF >> newNode->mo; inF >> newNode->day; inF >> newNode->year; inF >> newNode->itemCost; inF >> newNode->itemCount; inF >> newNode->itemsSold; insert(Head, newNode); } RECORDS *temp = Head; inF.close(); inF2.open("purge_items.dat"); print(Head); while (!inF2.eof()) { newNode = new RECORDS; inF2 >> newNode->itemNumber; } purgePrint(Head); return 0; }

6753 COOL 12 01 2001 67.98 25 18e 6292 ELEC 01 15 1994 56.89 80 01 7581 POPY 01 18 2812 90.9e 20 00 9234 KLIO 03 11 2013 01.09 99 08 1010 PECH 02 01 1999 23.90 89 12 1013 KKIO 01 09 2018 34.55 10 01 1012 IXCo 06 19 2016 23.89 88 e9 0023 VVIU 11 10 2014 90.90 78 12 1111 UUYY 08 08 2011 99.99 100 10 2221 JKLI 09 02 2010 45.90 150 19 9101 PPIO 04 02 2009 34.89 202 02

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

More Books

Students also viewed these Databases questions

Question

3-26. Was the senders purpose realistic?

Answered: 1 week ago