Question

In C++ General Description: For this project, you will write a program that keeps track of...

In C++

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 Inventory.txt on the S:\ drive. While the program is running, the information should be stored in a 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 linked 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. Display the inventory in alphabetical order by name

b. Display the inventory in reverse alphabetical order

c. Add an item to the inventory

d. Delete an item from inventory

e. Change any info for an item

i. Which means you have to be able to search for a particular 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 output to a file called newlist.txt

8. You must have internal and external documentation: See the handout on Documentation Standards

9. You will demonstrate your working project to me at an appointed time

10. You will hand in a copy of all your files, along with the documentation

This is the inventory

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
Heavy-Duty-Tripod 67.50 5 4
Lightweight-Tripod 19.95 5 10
35MM-Enlarger-Kit 159.99 5 10
40x40-Deluxe-Screen 35.98 5 4
50x50-Deluxe-Screen 44.98 5 10
120-Slide-Tray 4.29 25 17
100-Slide-Tray 2.95 25 33
Slide-Viewer 6.25 15 12
Movie-Editor 55.95 10 12
Condenser-Microphone 59.95 5 10
AA-Alkaline-Battery 0.89 100 80
Gadget-Bag 19.79 20 19
135-24-Color-Film 1.49 50 45
110-12-Color-Film 0.99 50 60
110-24-Color-Film 1.45 50 42
110-12-B/W-Film 0.59 25 37
110-24-B/W-Film 0.95 25 43
126-12-Color-Film 0.89 50 44
126-12-B/W-Film 0.59 25 27
8MM-Film-Cassette 6.89 50 39
16MM-Film-Cassette 11.89 20 25
Combination-Camera-Kit 959.99 12 10

0 0
Add a comment Improve this question Transcribed image text
Answer #1

struct Item{

string name;

double price;

int pixels;

int quantity;

};

dlist.h

#include<iostream>

using namespace std;

#include "item.h"

class DList{

public:

DList *head;

DList();

Item* createItem(string, double, int, int);

void insert(Item *);

void reverse();

int search(string);

void remove(string);

void print();

void write();

int change(string, Item*);

private:

Item *item;

DList *next;

};

dlist.cpp

#include "dlist.h"

DList::DList(){

head = NULL;

}

Item* DList::createItem(string name, double price, int pixels, int quantity){

Item *n_item = new Item;

n_item->name = name;

n_item->price = price;

n_item->pixels = pixels;

n_item->quantity = quantity;

return n_item;

}

void DList::insert(Item *item){

DList *tmpNode = new DList;

tmpNode->item = item;

tmpNode->next = NULL;

DList *currNode = head, *prevNode = NULL;

while (currNode != 0)

{

if (currNode->item->name > tmpNode->item->name)

break;

prevNode = currNode;

currNode = currNode->next;

}

if (prevNode == NULL)

{

head = tmpNode;

}

else

{

prevNode->next = tmpNode;

}

tmpNode->next = currNode;

}

void DList::reverse(){

DList *prev = NULL, *current = head, *next;

while (current != NULL)

{

next = current->next;

current->next = prev;

prev = current;

current = next;

}

head = prev;

}

int DList::search(string item){

DList *temp = head;

while(temp!=NULL){

if(temp->item->name==item)

return 1;

temp = temp->next;

}

return 0;

}

void DList::remove(string item){

if(head!=NULL){

DList *temp = head, *prev = NULL;

while(temp!=NULL){

if(temp->item->name==item)

break;

prev = temp;

temp = temp->next;

}

if(prev==NULL){

prev = head;

head = head->next;

delete prev;

}

else if(temp->next==NULL){

prev->next = NULL;

delete temp;

}

else{

prev->next = temp->next;

delete temp;

}

}

}

void DList::print(){

DList *temp = head;

while(temp!=NULL){

cout<<temp->item->name<<" "<<temp->item->price<<" "<<temp->item->pixels<<" "<<temp->item->quantity<<endl;

temp = temp->next;

}

}

int DList::change(string o_name, Item *item){

DList *temp = head;

while(temp!=NULL){

if(temp->item->name==o_name)

break;

temp = temp->next;

}

if(o_name==item->name){

if(item->price!=-1)

temp->item->price = item->price;

if(item->pixels!=-1)

temp->item->price = item->pixels;

if(item->quantity!=-1)

temp->item->quantity = item->quantity;

return 1;

}

return 0;

}

void DList::write(){

ofstream out("newlist.txt");

DList *temp = head;

while(temp!=NULL){

out<<temp->item->name<<" "<<temp->item->price<<" "<<temp->item->pixels<<" "<<temp->item->quantity<<endl;

temp = temp->next;

}

out.close();

}

main.cpp

#include<iostream>

#include<cstdlib>

#include<fstream>

#include "dlist.cpp"

using namespace std;

int main(){

ifstream in("Inventory.txt");

if(!in.is_open()){

cout<<"Unable to open file"<<endl;

exit(1);

}

string name;

double price;

int pixels, quantity;

DList *list = new DList();

while(!in.eof()){

in>>name>>price>>pixels>>quantity;

list->insert(list->createItem(name, price, pixels, quantity));

}

int option;

do{

cout<<"\nMENU"<<endl;

cout<<"1. Display the inventory in alphabetical order by name"<<endl;

cout<<"2. Display the inventory in reverse alphabetical order"<<endl;

cout<<"3. Add an item to the inventory"<<endl;

cout<<"4. Delete an item to inventory"<<endl;

cout<<"5. Change any info for an item"<<endl;

cout<<"6. Write into file"<<endl;

cout<<"7. exit"<<endl;

cout<<"Choose an option: ";

cin>>option;

switch(option){

case 1:

list->print();

break;

case 2:

list->reverse();

list->print();

list->reverse(); //to changed prev

break;

case 3:

{

cout<<"Adding new item: "<<endl;

cout<<"Enter item name: ";

cin>>name;

cout<<"Enter Price: ";

cin>>price;

cout<<"Enter Pixels";

cin>>pixels;

cout<<"Enter Quantiry";

cin>>quantity;

list->insert(list->createItem(name, price, pixels, quantity));

cout<<"Successfully New Item added to the list"<<endl;

}

break;

case 4:

{

cout<<"Enter item name to delete: ";

cin>>name;

if(list->search(name)){

list->remove(name);

cout<<"Item Successfully removed"<<endl;

}

else

cout<<"Item doesn't exists"<<endl;

}

break;

case 5:

{

string sname;

cout<<"Enter item name to change: ";

cin>>sname;

if(list->search(sname)){

cout<<"enter -1 to leave field"<<endl;

cout<<"item name: ";

cin>>name;

cout<<"Price: ";

cin>>price;

cout<<"Pixels: ";

cin>>pixels;

cout<<"Quantiry: ";

cin>>quantity;

if(!list->change(sname, list->createItem(name, price, pixels, quantity))){

list->remove(sname);

list->insert(list->createItem(name, price, pixels, quantity));

}

cout<<"Successfully changed info"<<endl;

}

else{

cout<<"Invalid item name"<<endl;

}

}

break;

case 6:

list->write();

cout<<"Successfully wirte into newfile.txt";

break;

case 7:

exit(0);

break;

}

}while(option!=7);

}

Add a comment
Know the answer?
Add Answer to:
In C++ General Description: For this project, you will write a program that keeps track of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Write a program that keeps track of inventory The data is located in the file Inventory.txt. ...

    C++ Write a program that keeps track of inventory The data is located in the file Inventory.txt. While the program is running, the information should be stored in a linked list. The information for each item needs be stored in a struct The definition will be in a separate file called items.h The total inventory will be stored in a linked list The definition of the list class will be in a file called linkList.h The program should be able...

  • Project Description In this project, you will design and implement a database for keeping track of...

    Project Description In this project, you will design and implement a database for keeping track of information for an online “SOCIAL NETWORK” system (e.g. a simplified version of Facebook!). You will first design an EER schema diagram for this database application. Then, you will map the EER schema into a relational database schema and implement it on ORACLE or MySQL or some other relational DBMS. Finally, you will load some data into your database (via user Interface) and create some...

  • given below are the project description and their Html and css files i need javascript according...

    given below are the project description and their Html and css files i need javascript according to the project and other files! WEB230 - JavaScript 1 Assignment 6b - Event Delegation Before starting, study the HTML and open it in a browser so that you understand the structure of the document. You will add functionality to perform several tasks in our shopping list app. Clicking the red "X" at the right of an item will delete that item. Clicking on...

  • programming language: C++ *Include Line Documenatations* Overview For this assignment, write a program that will simulate...

    programming language: C++ *Include Line Documenatations* Overview For this assignment, write a program that will simulate a game of Roulette. Roulette is a casino game of chance where a player may choose to place bets on either a single number, the colors red or black, or whether a number is even or odd. (Note: bets may also be placed on a range of numbers, but we will not cover that situation in this program.) A winning number and color is...

  • Program Description You are going to write a C++ program to manage toy salesmen. A salesman's...

    Program Description You are going to write a C++ program to manage toy salesmen. A salesman's data is updated periodically with sales and the time over which the money was collected. When requested, it returns sales per hour. A salesman can be updated many times before his/her sales per hour are requested, so the data needs to be accumulated. When the sales per hour are requested, the sales per hour are calculated and the salesman's accumulated data are set back...

  • For this assignment, you are to write a program, which will calculate the results of Reverse...

    For this assignment, you are to write a program, which will calculate the results of Reverse Polish expressions that are provided by the user. You must use a linked list to maintain the stack for this program. You must handle the following situations (errors): Too many operators (+ - / *) Too many operands (doubles) Division by zero The program will take in a Polish expression that separates the operators and operands by a single space, and terminates the expression...

  • IN C LANGUAGE Write a program that counts the leaves of a given binary tree. Hint: You will make a small (and...

    IN C LANGUAGE Write a program that counts the leaves of a given binary tree. Hint: You will make a small (and smart) update to the add function we discussed in class. a) 25 points Create the following binary trees by creating the nodes (malloc) and setting the related pointers (leftChild, right Child). Make content random. 50 40 60 100 70 45 30 120 47 b) 25 points Display the trees on screen the way we did in slide 9...

  • EX16_XL_CH10_GRADER_ML2_HW - Animal Shelter 1.5 Project Description: You manage a small animal shelter in Dayton, Ohio....

    EX16_XL_CH10_GRADER_ML2_HW - Animal Shelter 1.5 Project Description: You manage a small animal shelter in Dayton, Ohio. Your assistant created an XML document that lists some of the recent small animals that your shelter took in. In particular, the XML document lists the animal type (such as cat); the age, sex, name, color, and date the animal was brought in; and the date the animal was adopted. You want to manage the data in an Excel worksheet, so you will create...

  • 1-Suppose you write an application in which one class contains code that keeps track of the...

    1-Suppose you write an application in which one class contains code that keeps track of the state of a board game, a separate class sets up a GUI to display the board, and a CSS is used to control the stylistic details of the GUI (for example, the color of the board.) This is an example of a.Duck Typing b.Separation of Concerns c.Functional Programming d.Polymorphism e.Enumerated Values 2-JUnit assertions should be designed so that they a.Fail (ie, are false) if...

  • EX16 XL _CH01_GRADER ML2 HW - Real Estate Sales Report 1.3 Project Description: You own a...

    EX16 XL _CH01_GRADER ML2 HW - Real Estate Sales Report 1.3 Project Description: You own a small real estate company in Indianapolis. You track the real estate properties you list for dlients. You want to analyze sales for selected properties. Yesterday, you prepared a workbook with a worksheet for recent sales data and another worksheet listing several properties you listed. You want to calculate the number of days that the houses were on the market and their sales percentage of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT