Question

Write a C++ program to manage a list of inventory items using a linked list. Operations...

Write a C++ program to manage a list of inventory items using a linked list. Operations should include adding a new inventory item at the end of the list, adding a new inventory item at the beginning of the list, removing an inventory item from the beginning of the list, removing an inventory item from the end of the list, removing an inventory item by name, and display the current list of inventory items. Allow the user an option to exit.

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

#include<iostream>

#include<stdlib.h>

using namespace std;

class Inventory

{

public:

string name;

Inventory* next;

};

class List:public Inventory

{

Inventory *first,*last;

public:

List()

{

first=NULL;

last=NULL;

}

void insert(int choice);

void deleteInventory(int choice);

void display();

int search(string value);

};

void List::insert(int choice)

{

Inventory *prev,*cur;

prev=NULL;

cur=first;

string n;

Inventory *temp=new Inventory;

cout<<"\nEnter an Inventory name:";

cin>>n;

temp->name=n;

temp->next=NULL;

switch(choice)

{

case 1:

temp->next=first;

first=temp;

break;

case 2:

last->next=temp;

last=temp;

break;

}

}

void List::deleteInventory(int choice)

{

Inventory *prev=NULL,*cur=first;

int count=1,pos;

string name;

switch(choice)

{

case 1:

if(first!=NULL)

{

cout<<"\nDeleted Element is "<<first->name;

first=first->next;

}

else

cout<<"\nNot Able to Delete";

break;

case 2:

while(cur!=last)

{

prev=cur;

cur=cur->next;

}

if(cur==last)

{

cout<<"\nDeleted Element is: "<<cur->name;

prev->next=NULL;

last=prev;

}

else

cout<<"\nNot Able to Delete";

break;

case 3:

cout<<"\nEnter the name of Inventory:";

cin>>name;

pos = this->search(name);

if (pos == -1) {

cout<<"\nDid not found Inventory:";

break;

}

while(count!=pos)

{

prev=cur;

cur=cur->next;

count++;

}

if(count==pos)

{

cout<<"\nDeleted Element is: "<<cur->name;

prev->next=cur->next;

}

else

cout<<"\nNot Able to Delete";

break;

}

}

void List::display()

{

Inventory *temp=first;

if(temp==NULL)

{

cout<<"\nList is Empty";

}

while(temp!=NULL)

{

cout<<temp->name;

cout<<"-->";

temp=temp->next;

}

cout<<"NULL";

}

int List::search(string value)

{

int pos=0;

bool flag=false;

if(first==NULL)

{

cout<<"List is Empty";

return -1;

}

Inventory *temp;

temp=first;

while(temp!=NULL)

{

pos++;

if(temp->name==value)

{

flag=true;

return pos;

}

temp=temp->next;

}

if(!flag)

{

return -1;

}

}

int main()

{

List l;

int ch;

while(1)

{

cout<<"\n**** MENU ****";

cout<<"\n1:Add Inventory at End\n2:Add Inventory at Beginning\n3:Remove Inventory from End\n4:Remove Inventory from Beginning\n5:Remove Inventory by name\n6: Display Inventories\n7:EXIT\n";

cout<<"\nEnter Your Choice:";

cin>>ch;

switch(ch)

{

case 1:

l.insert(2);

break;

case 2:

l.insert(1);

break;

case 3:

l.deleteInventory(2);

break;

case 4:

l.deleteInventory(1);

break;

case 5:

l.deleteInventory(3);

break;

case 6:

l.display();

break;

case 7:

return 0;

}

}

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Write a C++ program to manage a list of inventory items using a linked list. Operations...
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
  • Write a C++ program to manage a list of students waiting to register for a course...

    Write a C++ program to manage a list of students waiting to register for a course using a linked list. Operations should include adding a new student at the end of the list, adding a new student at the beginning of the list, removing a student from the beginning of the list, removing a student from the end of the list, and removing a student by name. Allow the user an option to exit. NOTE: Functions/Methods must used throughout program....

  • please make sure rubics Program Specifications: Write a C++ program to manage a list of students...

    please make sure rubics Program Specifications: Write a C++ program to manage a list of students waiting to register for a course using a linked list. Operations should include adding a new student at the end of the list, adding a new student at the beginning of the list, removing a student from the beginning of the list, removing a student from the end of the list, and removing a student by name. Allow the user an option to exit....

  • Write a C++ program to manage a Point of Sale System for a Supermarket. The main...

    Write a C++ program to manage a Point of Sale System for a Supermarket. The main user is an employee at the Supermarket. Build Specifications (36 points) 1. The system should load a catalog of all items that the store sells. 2. A user can search the inventory: The user of the system can search the inventory by using the name of the item or by category. 3. A user can sell items once they are found. Or can sell...

  • Write a java program implementing the Linked list. It should be on an small office who...

    Write a java program implementing the Linked list. It should be on an small office who has 5 employees. The program ask the user for ID, First name, Last name and what field the work in(eg: accounting, programmer, HR etc). Each employee (with all the information of that paticular employee) should be placed in one node in the program. The program should repeat and ask the user for all 5 employees information. Also when you display the Linked list it...

  • please write in C++ Write a program that uses a structure to store the following inventory...

    please write in C++ Write a program that uses a structure to store the following inventory data in a file: The data can be either read from a text file or the keyboard Item name (string) Quantity on hand(int) Wholesale cost(double) Retail Cost(double) The program should have a menu that allows the user to perform the following tasks: Add new records to the file Display any record in the file User will provide the name of the item or the...

  • Derive a class called Stack from the linked list described in Assignment 2 (list of Dates)....

    Derive a class called Stack from the linked list described in Assignment 2 (list of Dates). This means the Stack class will inherit all the properties (data and functions) of the linked list. But, since a stack only allows pushing and popping at the front of the list only, you will need to prevent the operations at the back. To do this, derive the Stack class in such a way that the base class (LinkedList) functions become private in the...

  • Java Inventory Management Code Question

    Inventory ManagementObjectives:Use inheritance to create base and child classesUtilize multiple classes in the same programPerform standard input validationImplement a solution that uses polymorphismProblem:A small electronics company has hired you to write an application to manage their inventory. The company requested a role-based access control (RBAC) to increase the security around using the new application. The company also requested that the application menu must be flexible enough to allow adding new menu items to the menu with minimal changes. This includes...

  • C++ program Write a C++ program to manage a hospital system, the system mainly uses file...

    C++ program Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to add, edit, search, and delete record. Write the following functions: 1. hospital_menu: This function will display the following menu and prompt the user to enter her/his option. The system will keep showing the menu repeatedly until the user selects option 'e' from the menu. Arkansas Children Hospital a. Add new patient record b. Search record c....

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

  • C++. Please note the BOLDED ITEMS. You will create a simple linked structure. You will use...

    C++. Please note the BOLDED ITEMS. You will create a simple linked structure. You will use a simple node that has a pointer to a Node. The data for the Node will be a single data member of type char. You will build a structure where the last node you add will point to the first node created, i.e. it will be a circular linked structure. You will create a program that stores characters provided by the user, stored in...

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