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.

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.

Heres my current code:

#include
#include
#include
#include
#include
#include
#include

using namespace std;

struct InventoryReport
{
int itemNumber;
string Item_Category;
int mo;
int day;
int year;
float Item_Cost;
int Item_Count;
int Item_Sold;
InventoryReport *next;
};

void BuildList(InventoryReport*& Head, InventoryReport * newRecord)
{
InventoryReport* prev = NULL;
InventoryReport* curr = NULL;

//If head is empty.
if (Head == NULL)
{
Head = newRecord;
}
//Compares item numbers at head of list.
else if (Head != NULL && Head->itemNumber > newRecord->itemNumber)
{
newRecord->next = Head;
Head = newRecord;
}
//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 > newRecord->itemNumber)
{
prev->next = newRecord;
newRecord->next = curr;
break;
}
prev = curr;
curr = curr->next;
}
//Item placed at end of list.
if(curr == NULL)
prev->next = newRecord;
}
}

void print(InventoryReport * Head)
{
ofstream outFile;
outFile.open(“invrpt.dat”);
float TotalRevenue = 0;
float Revenue_Lost = 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 s2 = timePtr->tm_mon + 1;

//Print to screen.
cout
<< right << "Date: " << months[s2] << &#39; &#39; << (timePtr->tm_mday)
<< (timePtr->tm_year)+1900

cout

cout

cout

//Print to file.
outFile
<< right << "Date: " << months[s2] << &#39; &#39; << (timePtr->tm_mday)
<< (timePtr->tm_year)+1900

outFile

outFile

outFile

InventoryReport * n = new InventoryReport;
n = Head;

while (n != NULL)
{
//Calculate age of item.
int age = (timePtr->tm_year) + 1900 – n->year;
//Calculate item revenue, total revenue, and revenue lost.
float itmRevenue = n->Item_Cost*n->Item_Sold;
float revLost = n->Item_Cost*(n->Item_Count-n->Item_Sold);
Revenue_Lost+= revLost;

if(n->year >= 2018)
age = 0;
else if (n->year >= 2017 && n->mo >= (timePtr->tm_mon) + 6)
age = 0;
else if ((timePtr->tm_mon) – (n->mo) + 6 >= 0)
age += 1;

//Calculate percentage of item sold.
int s = n->mo;
int sold = n->Item_Sold;
int cnt = n->Item_Count;
int itemPrcnt = (sold * 100)/ cnt;

//Print to screen.
cout << setw(12) << left << n->itemNumber

cout << setw(4) << right << n->day
<< setw(12) << left << n->year;

cout
<< n->Item_Count

<< setw(12) << left << n->Item_Sold

//Print to file.
outFile << setw(12) << left << n->itemNumber

outFile << setw(4) << right << n->day
<< setw(12) << left << n->year;

outFile
<< n->Item_Count
<< setw(12) << left << (n->Item_Sold / n->Item_Count)

n = n->next;
};
//Print to screen.
cout

cout

//Print to file.
outFile

outFile

outFile.close();
}

//Function for printing list AFTER purge/deletions.
void purgePrint(InventoryReport * Head)
{
ofstream outFile;
outFile.open(“invrpt.dat”);
float TotalRevenue = 0;
float Revenue_Lost = 0;
float percentDecrease = 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 s2 = timePtr->tm_mon + 1;

//Print to screen.
cout
<< right << " Date: " << months[s2] << &#39; &#39; << (timePtr->tm_mday)
<< (timePtr->tm_year)+1900

cout

cout

cout

//Print to file.
outFile
<< right << " Date: " << months[s2] << &#39; &#39; << (timePtr->tm_mday)
<< (timePtr->tm_year)+1900

outFile

outFile

outFile

InventoryReport * n = new InventoryReport;
n = Head;

while (n != NULL)
{
//Calculate age of item.
int age = (timePtr->tm_year) + 1900 – n->year;
//Calculate item revenue, total revenue, and revenue lost.
float itmRevenue = n->Item_Cost*n->Item_Sold;
float revLost = n->Item_Cost*(n->Item_Count-n->Item_Sold);
Revenue_Lost+= revLost;

if(n->year >= 2018)
age = 0;
else if (n->year >= 2017 && n->mo >= (timePtr->tm_mon) + 6)
age = 0;
else if ((timePtr->tm_mon) – (n->mo) + 6 >= 0)
age += 1;

if ((age >= 5) && (n->Item_Sold < 0.1 * n->Item_Count))
{
// outFile << n->itemNumber
n= n->next;
continue;
}

//Calculate percentage of item sold.
int s = n->mo;
int sold = n->Item_Sold;
int cnt = n->Item_Count;
int itemPrcnt = (sold * 100)/ cnt;

//Print to screen.
cout << setw(12) << left << n->itemNumber

cout << setw(4) << right << n->day
<< setw(12) << left << n->year;

cout
<< n->Item_Count

<< setw(12) << left << n->Item_Sold

//Print to file.
outFile << setw(12) << left << n->itemNumber

outFile << setw(2) << right << n->day
<< setw(12) << left << n->year;

outFile
<< setprecision(2) << n->Item_Cost
<< setw(12) << left << n->Item_Sold

n = n->next;
};
//Print to screen.
cout

cout

//Print to file.
outFile

outFile

outFile.close();
}

int main()
{
ifstream inFile;
ifstream inFile2;
inFile.open(“item_file.dat1.txt”);

if(inFile2.fail())
cout

InventoryReport * newNode = NULL;
InventoryReport * Head = NULL;
InventoryReport * Tail = NULL;

if (inFile.fail())
{
cout
exit(1);
}

//Read in data from file.
while (!inFile.eof())
{
newNode = new InventoryReport;

inFile >> newNode->itemNumber;
inFile >> newNode->Item_Category;
inFile >> newNode->mo;
inFile >> newNode->day;
inFile >> newNode->year;
inFile >> newNode->Item_Cost;
inFile >> newNode->Item_Count;
inFile >> newNode->Item_Sold;

BuildList(Head, newNode);
}

InventoryReport *temp = Head;
inFile.close();
inFile2.open(“purge_items.dat”);
print(Head);
while (!inFile2.eof())
{
newNode = new InventoryReport;
inFile2 >> 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

"Get 15% discount on your first 3 orders with us"
Use the following coupon
"FIRST15"

Order Now