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.

I need to edit my program to input 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.

Once that is done, generate a report in a separate file(let's call it "inventory_purge_report.txt")image text in transcribed titled "Inventory Purge Report" that looks like the image below

My current is code is below which you can modify

#include

#include

#include

#include

#include

#include

using namespace std;

struct InventoryReport

{

int Item_Number;

string Item_Category;

int mm;

int day;

int year;

float itemCost;

int itemCount;

int itemsSold;

InventoryReport *next;

};

void insert(InventoryReport*& Head, InventoryReport * itemPntr)

{

InventoryReport* prev = NULL;

InventoryReport* curr = NULL;

//If head is empty.

if (Head == NULL)

{

Head = itemPntr;

}

//Compares item numbers at head of list.

else if (Head != NULL && Head->Item_Number > itemPntr->Item_Number)

{

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->Item_Number > itemPntr->Item_Number)

{

prev->next = itemPntr;

itemPntr->next = curr;

break;

}

prev = curr;

curr = curr->next;

}

//Item placed at end of list.

if(curr == NULL)

prev->next = itemPntr;

}

}

string get_month( int month_number){

string month;

switch (month_number)

{

case 0: month = "error";

break;

case 1: month = "Jan.";

break;

case 2: month = "Feb.";

break;

case 3: month = "Mar.";

break;

case 4: month = "Apr.";

break;

case 5: month = "May";

break;

case 6: month = "June";

break;

case 7: month = "July";

break;

case 8: month = "Aug.";

break;

case 9: month = "Sep.";

break;

case 10: month = "Oct.";

break;

case 11: month = "Nov.";

break;

case 12: month = "Dec.";

break;

default: // code to be executed if n doesn't match any cases

month = "error";

}

return month;

}

void print(InventoryReport * Head)

{

ofstream outF;

outF.open("InventoryReport.dat");

float totalRevenue = 0;

//Pointer for date.

time_t t = time(NULL);

tm*timePtr = localtime(&t);

int sub2 = timePtr->tm_mon + 1;

string month = get_month(sub2);

//Print to screen.

cout

tm_mday - 1)

tm_year)+1900

cout

cout

cout

//Print to file.

outF

tm_mday - 1)

tm_year)+1900

outF

outF

outF

InventoryReport * node1 = new InventoryReport;

node1 = Head;

int tMonth = timePtr->tm_mon + 1; //month since january, march would be 2, add 1.

int tDate = timePtr->tm_mday;

int tYear = timePtr->tm_year + 1900; //year since 1900, 2008 would be 108

while (node1 != NULL)

{

//Calculate age of item.

// couttm_year) + 1900year

int years = tYear- node1->year;

float itmRevenue = node1->itemCost*node1->itemsSold;

totalRevenue += itmRevenue;

//if(node1->mm tm_mon) + 6)

int months=tMonth-node1->mm;

int sub = node1->mm;

string month = get_month(sub);

//Print to screen.

cout Item_Number

cout day

year;

cout itemCost

itemsSold

//Print to file.

outF Item_Number

outF day

year;

outF itemCost

itemsSold

node1 = node1->next;

};

//Print to screen.

cout

cout

//Print to file.

outF

outF

outF.close();

}

int main()

{

ifstream inF;

inF.open("item_file.txt");

InventoryReport * newNode = NULL;

InventoryReport * Head = NULL;

//Read in data from file.

while (!inF.eof())

{

newNode = new InventoryReport;

inF >> newNode->Item_Number;

inF >> newNode->Item_Category;

inF >> newNode->mm;

inF >> newNode->day;

inF >> newNode->year;

inF >> newNode->itemCost;

inF >> newNode->itemCount;

inF >> newNode->itemsSold;

insert(Head, newNode);

}

InventoryReport *temp = Head;

print(Head);

inF.close();

return 0;

}

Inventory Purge Report Date: Jan. 25, 2018 in Item Purchase Item % Items Item Item Item Count sold Sold Age Revenue lost Date Jan. 1, 2012 Dec. 1, 2016 Number 6 201.00 2 $500.00 100 9% 232 345 100 7% Total revenue lost $701.00 *Age to the nearest year Compute the total_reven ue lost for each item, [item_cost *(item_count-Items_sold)] revenue fost. After purging the items that match the purge criteria, generate a new Inventory report, see example below

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

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

4. Discuss the role of the nurse in QI and risk management.

Answered: 1 week ago