Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

res each Design, implement and test a Crt program that reads a series of data re

ID: 3877349 • Letter: R

Question

res each Design, implement and test a Crt program that reads a series of data records from a file and sto record in a linked list (in ascending order by items number). After creating the linked list the program should traverse the list and print the report below. Rubrie Correct,necreueAhwu, : Record Description: Item_ Number //unsigned integer item_category // alpha_numeric 4 chars ex. ELEC-t Item_Purchase Date I/ mm dd yyyy Item Cost Item Count ltems_SOLD nteger // Float /I integer et cae ths mmyta, Inventory Report Item A" Date: lan. 16.2018 -en.RihsD maihe Items 1 Item)Item L Sold JLAge*)Revenue 1 [ lte m Purchase 7 Item 1 Item Cost $200.50 ! Date L Number 232 345 6 $201.00 Jan. 1, 2012 Dec. 1, 2016 100.00 2 500.00 _tua-tten number, are Total revenue $701.00 Age to the nearest year

Explanation / Answer

#include <fstream>
#include <iostream>
#include <string>
#include "SortedLinkList.h"
using namespace std;

struct InventoryReport
{
   //Details
   int item_Number;
   string item_Category;
   string item_purchase_date;
   float item_cost;
   int item_count;
int item_Sold;

InventoryReport *link;
};

typedef InventoryReport* IRPtr;
void insertAtHead( IRPtr&, int, string, string, float,int,int );
void insert( IRPtr&, int, string, string, float,int,int );

int main()
{
// Open file
fstream in( "Please provide you file name here", ios::in );//file name here

// Read and prints lines
int item_Number;
   string item_Category;
   string item_purchase_date;
   float item_cost;
   int item_count;
int item_Sold;

while( in >> item_Number >> item_Category >> item_purchase_date >> item_cost >> item_count>>item_Sold)
{
cout << "item_Number, item_Category, item_purchase_date, item_cost, item_count,item_Sold " << item_Number << " " << item_Category << " " << item_purchase_date << " " << item_cost << " " << item_count << " " <<item_Sold<<endl;
}

// Close file
in.close();

IRPtr head = new InventoryReport;
while( in >> first >> last >> salary >> bonus >> deduction)
{
cout << "item_Number, item_Category, item_purchase_date, item_cost, item_count,item_Sold " << item_Number << " " << item_Category << " " << item_purchase_date << " " << item_cost << " " << item_count << " " <<item_Sold<<endl;
insertAtHead (head, item_Number, item_Category, item_purchase_date, item_cost, item_count,item_Sold );
}


}

void insertAtHead(IRPtr& head, int item_NumberValue, string item_CategoryValue, string item_purchase_dateValue,
float item_costValue,int item_countValue,int item_SoldValue )
{
IRPtr tempPtr= new InventoryReport;

tempPtr->item_Number = item_NumberValue;
tempPtr->item_Category = item_CategoryValue;
tempPtr->item_purchase_date = item_purchase_dateValue;
tempPtr->item_cost = item_costValue;
tempPtr->item_count = item_countValue;
tempPtr->item_Sold = item_SoldValue;
tempPtr->link = head;
head = tempPtr;
}

void insert(IRPtr& afterNode, int item_NumberValue, string item_CategoryValue, string item_purchase_dateValue,
float item_costValue,int item_countValue,int item_SoldValue)
{
IRPtr tempPtr= new InventoryReport;

tempPtr->item_Number = item_NumberValue;
   tempPtr->item_Category = item_CategoryValue;
   tempPtr->item_purchase_date = item_purchase_dateValue;
   tempPtr->item_cost = item_costValue;
   tempPtr->item_count = item_countValue;
tempPtr->item_Sold = item_SoldValue;
   tempPtr->link = head;

tempPtr->link = afterNode->link;
afterNode->link = tempPtr;
}