This is all I have. I think the fields are item, price, inventory, and items ord
ID: 3807072 • Letter: T
Question
This is all I have. I think the fields are item, price, inventory, and items ordered
In C++
Please help. ASAP
General Description: For this project, you will write a program that keeps track of inventory for a camera store. The data is located in the file InventoryFile.txt on the S: drive. While the program is running, the information should be stored in a doubly linked list.
1. The information for each item will be stored in a struct
a. The definition will be in a separate file called item.h
2. The total inventory will be stored in a list
a. The definition of the list class will be in a file called dlist.h
3. The program should be able to perform the following functions
a. Print the inventory
b. Print the inventory in reverse order
c. Add an item to the inventory
d. Delete an item from inventory
e. Change any info for an item
4. The program will run until the user chooses an option to exit
5. The list is not in alphabetical order, so you will need to put it in order.
6. Whenever you change a name or if you add an item the list must stay in order.
7. When you are done, the list will be printed to a file called newlist.txt
You must have internal documation
This is what is in file Inventoryfile.txt
Telephoto-Pocket-Camera 54.95 15 20
Mini-Pocket-Camera 24.95 15 12
Polaroid-1Step-Camera 49.95 10 20
Sonar-1Step-Camera 189.95 12 13
Pronto-Camera 74.95 5 15
8MM-Zoom-Movie-Camera 279.99 10 9
8MM-Sound/ZoomMovieCamera 310.55 10 15
35MM-Minolta-SLR-XG-7-Camera 389.00 12 10
35MM-Pentax-SLR-AE-1-Camera 349.95 12 11
35MM-Canon-SLR-ME-Camera 319.90 12 20
35MM-Hi-Matic-Camera 119.95 12 13
35MM-Compact-Camera 89.99 12 20
Zoom-Movie-Projector 129.95 5 7
Zoom-Sound-Projector 239.99 5 9
Auto-Carousel-Projector 219.99 5 10
Carousel-Slide-Projector 114.95 5 4
Pocket-Strobe 14.95 5 4
StrobeSX-10 48.55 10 12
Electonic-Flash-SX-10 28.99 15 10
Tele-Converter 32.99 15 13
28MM-Wide-Angle-Lens 97.99 15 14
135MM-Telephoto-Lens 87.95 15 13
35-105MM-Zoom-Lens 267.95 5 8
80-200MM-Zoom-Lens 257.95 5 7
Explanation / Answer
// dlist.h
// ====
#ifndef _DLIST_H_
#define _DLIST_H_
#include <string>
/**
* Since all inventory items are nothing but plain fields it would be a mess
* to use class for such a simple purpose.
*/
struct Inventory {
std::string name;
float field1;
int field2;
int field3;
};
/**
* This is a single node in a doubly linked list.
*/
struct Node {
Node *prev;
Node *next;
Inventory *data;
};
/**
* Inventory db itself is a doubly linked list. i.e it contains necessary
* class methods to handle the data and at the same time handle all nodes.
*/
class Dlist {
Node *head = NULL,
*tail = NULL,
*current = NULL,
*temp = NULL;
int num_nodes = 0;
public:
// Add a new Inventory
void add_inventory(std::string n, float in1,
int in2, int in3);
// Prints the whole inventory.
void print_inventory();
// Prints inventort in reverse.
void print_inventory_rev();
// Delete an item in the inventory.
// void delete_inventory();
};
#endif
// dlist.cpp
// ====
#include "dlist.h"
/** Adds something to doubly linked list **/
void Dlist::add_inventory(std::string n, float in1,
int in2, int in3)
{
// New Inventory object.
Inventory *inv1 = new Inventory;
inv1->name = n;
inv1->field1 = in1;
inv1->field2 = in2;
inv1->field3 = in3;
temp = new Node;
temp->prev = current;
temp->next = NULL;
temp->data = inv1;
// If it is not the first iteration we have to link the
// last objects next to this object.
if (current != NULL)
current->next = temp;
current = temp;
// If no previous / current from previous time then
// obviously this is the first time!
if (head == NULL && temp->prev == NULL)
head = current;
// The newly created item will always be the tail.
tail = current;
num_nodes++;
};
/** show inventory **/
void Dlist::print_inventory()
{
Node *iter = head;
for (int i = 0; i < num_nodes; ++i)
{
std::cout << iter->data->name << " "
<< iter->data->field1 << " "
<< iter->data->field2 << " "
<< iter->data->field3 << std::endl;
iter = iter->next;
}
};
/** Show inventory in reverse order **/
void Dlist::print_inventory_rev()
{
Node *iter = tail;
for (int i = 0; i < num_nodes; ++i)
{
std::cout << iter->data->name << " "
<< iter->data->field1 << " "
<< iter->data->field2 << " "
<< iter->data->field3 << std::endl;
iter = iter->prev;
}
};
// main.cpp
// ====
/*
Inventory program in c++.
*/
#include <iostream>
#include "dlist.h"
int main()
{
Dlist *db1 = new Dlist();
db1->add_inventory("Nokia Mobile", 23.33,
12, 12);
db1->add_inventory("Samsung Mobile", 23.33,
12, 12);
db1->print_inventory();
std::cout << "====" << std::endl;
db1->print_inventory_rev();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.