QuestionQuestion

Part 1: The Program
Write a program using stacks and queues to control the inventory of the Gadget Supply Company.

The Gadget Supply Company receives shipments of gadgets at various costs. The store's policy is to charge a 45% markup and to sell gadgets received later before gadgets that were received earlier. This is a LIFO (last-in-first-out) policy.

Data Structure Overview
The program will also require implementation of both a stack and a queue. Both should be implemented using dynamic memory allocation and linked lists.

You must implement the data structures from scratch (no use of templates from the STL allowed).

Minimally, you must write the routines createEmptyStack, isEmptyStack, isFullStack, push, and pop for the stack. All access to the stack should be done using only these routines.

Minimally you must write the routines createEmptyQueue, isEmptyQueue, isFullQueue, enQueue, and deQueue for the queue. All access to the queue should be done using only these routines.

Data Input
The input file will contain two types of records: purchase records and sales records. Each record will appear on one line. The records will be listed in date order (i.e. earlier records will appear in the file before later records), but purchase and sales records will be mixed in with each other.

Purchase Records
Each purchase record will contain data about incoming gadgets purchased that are to be added to the inventory

Purchase record nodes will contain the above purchase record data, along with a link to the next node in the stack.

For example:
quantityPurchased
costPerGadget
nextPurchase

Sales Records
Each sales record will contain data about sales of widgets to remove from the inventory.

Each sales record will contain:
The letter 'S' indicating a sale
The quantity sold
The 6-digit invoice number from the sale

Sample record:
S 50 111111

Sales record nodes will contain the above sales record data, along with a link to the next node in the queue.
For example:
quantitySold
invoiceNum
nextSale

Program Processing

1. The input data file will be passed into the program as a command line argument.
When the program begins, confirm that a filename was supplied as an input argument, and confirm that the named file exists.
If a filename was not supplied, or the supplied filename does not exist, issue an error message and exit the program gracefully.

2. Given a valid input data file, create an empty purchase record stack and an empty sales record queue. For example:
purchaseStack
salesQueue
quantitySold invoiceNum nextSale
0
NULL
0
NULL
NULL
count stackTop
count queueFront queueBack

3. Read the data from the input data file.
a. For each purchase read the data from the file into a purchase record (struct). Display a message to the screen.

Sample message:
50 gadgets received at $1.50 each - Total Cost: $ 75.00
Then add the purchase record to the top of the inventory stack. Since gadgets will be accessed and sold from the top of the stack, this will cause gadgets received later to be sold before gadgets that were received earlier.

b. For each sale read the data from the file into a sales record (struct).
Add the record to the end of the sales queue. Since sales records will be processed by extracting records from the front of the queue, customer's sales will be handled in the order received.

NOTE: If memory allocation fails at any time while reading the file and inserting records onto the stack/queue, issue an error message, and exit the program gracefully.

4. After all purchase and sales records have been read from the file, process the sales records from the sales queue one at a time, matching them to inventory in the purchase stack.

This means that for each record in the sales queue:
a. Pop a record off the purchase inventory stack, one at a time, until the total sale can be filled (or the stack is empty).
b. Compute the sales price of each set of widgets (remember the 45% markup) and print a message (see below).

Sample:
If 200 gadgets were sold in one sale on invoice 222222, and there were 50 gadgets in the stack from a shipment with a cost of $1.25, 100 at $1.10, and 50 at $1.00, the following would print:
Sold on invoice 222222:
50 gadgets sold at $1.50 each – Total received: $ 75.00
100 gadgets sold at $1.32 each - Total received: $ 132.00
50 gadgets sold at $1.20 each - Total received: $ 60.00
----- --------
200 gadgets TOTAL SALE $ 267.00

NOTE: The program should compute a total for the sale when the gadgets came from multiple purchases only (i.e. no total is computed if the entire sale can be filled from one purchase).

c. If there are leftover gadgets from the last purchase record that are not needed for the sale, be sure to push a purchase record back onto the stack. The record will contain data about the remaining gadgets that were not sold.

d. If there are an insufficient number of gadgets in stock to fulfill a sale, sell as many as are available, and print a warning about how many gadgets were short.

Sample:
If 80 gadgets were sold in one sale on invoice 333333, and there were only 50 gadgets left in the stack from a shipment with a cost of $1.20, the following would print:
Sold on invoice 333333:
50 gadgets sold at $1.44 each – Total received $ 72.00
30 gadgets SHORT on invoice 333333

5. If sales remain in the queue, after the purchase stack becomes empty, display information about all remaining unfilled short orders.
Sample output for unfilled orders:

If there were two sale records remaining in the sales queue, but the purchase stack was empty, the following would print:
Sales orders that could not be filled:
63 gadgets SHORT on invoice 123456
20 gadgets SHORT on invoice 234567

6. Display information about remaining gadgets in the inventory before the program exits:
Sample output:
Remaining Inventory:
50 gadgets received at $1.70 each
67 gadgets received at $1.60 each
50 gadgets received at $1.50 each
-----
167 gadgets remain in the inventory
OR (if stack is empty):
No remaining inventory

Test Plan
In addition to writing the program, you will also create a test plan for this program. Your test plan should include input data that will adequately test all aspects of your program. For each test in your plan, include:
- the rationale for each test
- the input data that will be used for test - the output you expect to see
Be sure to test your program, using your test plan, to find any deficiencies!

Additional Notes
The program must be modular (i.e. broken down into logical functions) and use correct parameter passing. Use of global variables will NOT be allowed. And object-oriented programming (classes, objects, templates, STL, etc) may NOT be used.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

// FUNCTIONS:
/*
*      purchaseStack * createEmptyStack();
*      bool isEmptyStack(purchaseStack * theStack);
*      bool isFullStack();
       bool push(purchaseStack * theStack, purchaseRecord newItem);
       purchaseRecord pop(purchaseStack * theStack);
       salesQueue * createEmptyQueue();
       bool isEmptyQueue(salesQueue * thisQueue);
       bool isFullQueue();
       bool enQueue(salesQueue * thisQueue, salesRecord newItem);
       salesRecord deQueue(salesQueue * thisQueue);
       bool readFile(char * fileName, salesQueue * sQueue, purchaseStack * pStack);
       void salesProcess(salesQueue * sQueue, purchaseStack * pStack);
       void afterProcessing(salesQueue * sQueue, purchaseStack * pStack);
*
*/

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <new>
#include <iomanip>
using namespace std;

/* Purchase record nodes
*/
struct purchaseRecord {
    int quantityPurchased ;
    double costPerGadget;
    struct purchaseRecord * nextPurchase;
};

struct purchaseStack{
    int count;
    purchaseRecord * stackTop;
};...
$80.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats