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. Right now I'm struggling on getting the Item Age which is computed by todays date(from the system) - the Item Purchase Date

My code:

/* Name: Jeavon White Assignment: Create an Ordered Single Linked List Due Date: 1/23/2018

*/ #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

//Print to file. outF tm_mday - 1) tm_year)+1900

outF

outF

InventoryReport * node1 = new InventoryReport; node1 = Head;

while (node1 != NULL) { //Calculate age of item. int age = (timePtr->tm_year) + 1900 - node1->year; float itmRevenue = node1->itemCost*node1->itemsSold; totalRevenue += itmRevenue;

if(node1->mm tm_mon) + 6) age += 1; int sub = node1->mm; string month = get_month(sub);

//Print to screen. cout Item_Number day year;

cout itemCost itemsSold

//Print to file. outF Item_Number 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.dat1.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;

}

image text in transcribed

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

Deductive And Object Oriented Databases Second International Conference Dood 91 Munich Germany December 18 1991 Proceedings Lncs 566

Authors: Claude Delobel ,Michael Kifer ,Yoshifumi Masunaga

1st Edition

3540550151, 978-3540550150

More Books

Students also viewed these Databases questions

Question

Contrast parental and peer influences during adolescence.

Answered: 1 week ago