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

Please provide the c++ code and a screenshot of the working program. I really ne

ID: 3809658 • Letter: P

Question

Please provide the c++ code and a screenshot of the working program. I really need this.
Thank you You need to write a program to keep inventory for a ware store five different way You will write a program to store the inventory in d)an unsorted doubly linked list, (2) a sorted doubly linked an unsorted array, (4) sorted array, and (5) position array Ge. use index/subscript to access record, e.g. Record 83 would be loaded into array index location 83). Make the arrays big enough to store 100 records Each record will contain: Record (in), Tool Name (string), Quantity and Cost (double) Your program should initialize the array to 100 empty records. Record Quantity and Cost set to zero and Name set to 'no name' Read in a file of unsorted records to create options (1), 02) and G) and a separate file of sorted records to create options (4) and (5) The program will ask the user to enter the names of the files to use. Use the as the delimiter for the name. For example, the first data line in the file would look like: 83 #Electric Sanderi 7 57.00 Then create a menu that allows you to Update a record (Record cannot be updated), Delete a record, List a record, and list All tools (the ones that are not "no name") Start your inventory with the following information Record H Tool Name uantity Cost 83 Electric Sander 7 57.00 56 Hammer 176 11.99 17 Jig Saw 21 11.00 39 Lawn mower 3 79.50 3 Power saw 18 99.99 77 106 Screwdriver 6.99 11 2150 68 Sledge hammer 1 Wrench 134 750 Perform linear searches to perform the update, delete and list operations (except position array). For each the operation write to an output file the operation and number of comparisons necessary to perform each operation in all five ways. After running your program for various inputs write a summary conclusion on the efficiency of performing the operations in the five ways.

Explanation / Answer

cpp file :

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

using std::cout;
using std::cin;
using std::ios;
using std::fstream;
using std::setw;
using std::setprecision;
using std::cerr;


void initializeFile( fstream & );
void inputData( fstream & );
void listTools( fstream & );
void updateRecord( fstream & );
void insertRecord( fstream & );
void deleteRecord( fstream & );
int instructions( void );

const int LENGTH = 30;

struct Data {
int partNumber;
char toolName[ LENGTH ];
int inStock;
double unitPrice;
};

int main()
{
int choice;
char response;
fstream file( "hardware.dat", ios::in | ios::out );
void ( *f[] )( fstream & ) = { listTools, updateRecord, insertRecord,
deleteRecord };

cout << "Should the file be initialized (Y or N): ";
cin >> response;
if(response == 'Y' || response == 'y')
{

initializeFile(file);
}
inputData(file);
}

void initializeFile( fstream &fRef )
{
Data blankItem = { -1, "", 0, 0.0 };

for ( int i = 0; i < 100; ++i )
fRef.write( (char * )( &blankItem ), sizeof( Data ) );
}

void inputData( fstream &fRef )
{
Data temp;
cout << "Enter the partnumber (0 - 99, -1 to end input): ";
cin >> temp.partNumber;

{
while ( temp.partNumber != -1 )
cout << "Enter the tool name: ";
//cin.ignore(); // ignore the newline on the input stream
cin.get( temp.toolName, LENGTH );
cout << "Enter quantity and price: ";
cin >> temp.inStock >> temp.unitPrice;
fRef.seekp( ( temp.partNumber ) * sizeof( Data ) );
fRef.write( ( char * )( &temp ), sizeof( Data ) );
cin >> temp.partNumber;
}
}

int instructions( void )
{
int choice;

cout << " Enter a choice: 1 List all tools."
<< " 2 Update record. 3 Insert record."
<< " 4 Delete record. 5 End program. ";

do {
cout << "? ";
cin >> choice;
} while ( choice < 1 || choice > 5 );

return choice;
}

void listTools( fstream &fRef )
{
Data temp;

cout << setw( 7 ) << "Record#" << " " << setiosflags( ios::left )
<< setw( 30 ) << "Tool name" << resetiosflags( ios::left )
<< setw( 13 ) << "Quantity" << setw( 10 ) << "Cost ";

for ( int count = 0; count < 100 && !fRef.eof(); ++count ) {
fRef.seekg( count * sizeof( Data ) );
fRef.read( ( char *)( &temp ), sizeof( Data ) );

if ( temp.partNumber >= 0 && temp.partNumber < 100 ) {
cout.setf( ios::fixed | ios::showpoint );
cout << setw( 7 ) << temp.partNumber << " "
<< setiosflags( ios::left ) << setw( 30 ) << temp.toolName
<< resetiosflags( ios::left ) << setw( 13 ) << temp.inStock
<< setprecision( 2 ) << setw( 10 ) << temp.unitPrice << ' ';
}
}
}

void updateRecord( fstream &fRef )
{
Data temp;
int part;

cout << "Enter the part number for update: ";
cin >> part;
fRef.seekg( part * sizeof( Data ) );
fRef.read( ( char *)( &temp ), sizeof( Data ) );

if ( temp.partNumber != -1 ) {
cout << setw( 7 ) << "Record#" << " " << setiosflags( ios::left )
<< setw( 30 ) << "Tool name" << resetiosflags( ios::left )
<< setw( 13 ) << "Quantity" << setw( 10 ) << "Cost ";

cout.setf( ios::fixed | ios::showpoint );
cout << setw( 7 ) << temp.partNumber << " "
<< setiosflags( ios::left ) << setw( 30 ) << temp.toolName
<< resetiosflags( ios::left ) << setw( 13 ) << temp.inStock
<< setprecision( 2 ) << setw( 10 ) << temp.unitPrice << ' '
<< "Enter the tool name: ";

cin.ignore(); // ignore the newline on the input stream
cin.get( temp.toolName, LENGTH );
cout << "Enter quantity and price: ";
cin >> temp.inStock >> temp.unitPrice;

fRef.seekp( ( temp.partNumber ) * sizeof( Data ) );
fRef.write( ( char *) ( &temp ), sizeof( Data ) );
}
else
cerr << "Cannot update. The record is empty. ";
}

void insertRecord( fstream &fRef )
{
Data temp;
int part;

cout << "Enter the partnumber for insertion: ";
cin >> part;
fRef.seekg( ( part ) * sizeof( Data ) );
fRef.read( ( char * ) ( &temp ), sizeof( Data ) );

if ( temp.partNumber == -1 ) {
temp.partNumber = part;
cout << "Enter the tool name: ";
cin.ignore(); // ignore the newline on the input stream
cin.get( temp.toolName, LENGTH );
cout << "Enter quantity and price: ";
cin >> temp.inStock >> temp.unitPrice;

fRef.seekp( ( temp.partNumber ) * sizeof( Data ) );
fRef.write( ( char *)( &temp ), sizeof( Data ) );
}
else
cerr << "Cannot insert. The record contains information. ";
}

void deleteRecord( fstream &fRef )
{
Data blankItem = { -1, "", 0, 0.0 }, temp;
int part;

cout << "Enter the partnumber for deletion: ";
cin >> part;

fRef.seekg( part * sizeof( Data ) );
fRef.read( ( char *)( &temp ), sizeof( Data ) );

if ( temp.partNumber != -1 ) {
fRef.seekp( part * sizeof( Data ) );
fRef.write( ( char * )( &blankItem ), sizeof( Data ) );
cout << "Record deleted. ";
}
else
cerr << "Cannot delete. The record is empty. ";

}

hardware.dat File :

Record #: Tool Name:   Quantity: Cost:
3       Electric Sander   07   $57.98
17       Hammer           76   $11.99
24       Jig Saw           21   $11.00
39       Lawn Mower       03   $79.50
56       Power Saw       18   $99.99
68       Screwdriver       106   $06.99
77       Sledge Hammer   11   $21.50
83       Wrench           34   $07.50

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote