Question

C++ program, item.cpp implementation.

Implementation: You are supposed to write three classes, called Item, Node and Inventory respectively Item is a plain data clThe following diagram illustrates the data structure maintained by your Inventory class: Inventory Node Item head id item 300For all nodes in the list except the last node, the next field of the node at position pos will point to the next node. TheneThe following table explains each of the members that you will need to implement. Description Class Access Member id int name

Implementation: You are supposed to write three classes, called Item, Node and Inventory respectively Item is a plain data class with item id, name, price and quantity information accompanied by getters and setters Node is a plain linked list node class with Item pointer and next pointer (with getters/setters) Inventory is an inventory database class that provides basic linked list operations, delete load from file / formatted print functionalities. The majority of implementation will be done in this class as well as find / add /
The following diagram illustrates the data structure maintained by your Inventory class: Inventory Node Item head id item 30001 DietCoke next name price 1.99 35 quantity item id 30002 CokeZero next name price 1.98 32 quantity item id 40001 Milk1Gal next name price 2.49 _quantity 30 nullptr The top left corner of the above figure shows the only private data member of the Inventory class: _head, a pointer to the first node in the linked list. The value is nullptr if the list is empty. Just to the right of these two data members is a column (in blue) of list nodes linked. Each node of the (singly) linked list has a next field, and an item field storing a pointer to an Item object. The Item object that the item field of each node points to are displayed (in green) to the right. The types of the four fields are int, string, double, and int, respectively
For all nodes in the list except the last node, the next field of the node at position pos will point to the next node. Thenext field of the last node will point to nullptr Note that the order of the items is last-come-first-out. That is, the most recently added node is at the head. We do not manage a tail pointer this time Files you will submit: stockmgmt.cpp item.h contains your main function contains the Item class declaration contains the Item class member function definitions contains the Node/Inventory class declaration contains the Node/Inventory class member function definitions item.cpp inventory.h inventory.cpp
The following table explains each of the members that you will need to implement. Description Class Access Member id int name: string price: double Private ID Private Item name Item price Quantity of item in stock Creates an item using the values given by the parameters. Private quantity: int Itemint, Private Public const string&, double, int) int getID() const Item Public Accessor, returns the ID
0 0
Add a comment Improve this question Transcribed image text
Answer #1

This class contains the item class definitions and declarations:

#include<string>

using namespace std;

class Item

{

private:

int _id;

string _name;

double _price;

int _quantity;

public:

Item(int _id,const string& _name,double _price,int _quantity);

void setId(int id)

{ _id=id;}

void setprice(double amount)

{ _price=amount;}

void setquantity(int quant)

{ _quanitity = quant;}

void getId(int id)

{ return _id;}

void getprice(double amount)

{ return _price;}

void getquantity(int quant)

{ return _quantity;}

The class i'am going to write is the Inventory class and consists of all the class member function definitions and initializations. Here we use stack methods as last come first out method is used here.

template<class T>

class dynstack

{

private:

struct StackNode;

{

T value;

Stacknode *next;

};

Stacknode *top;

public:

Dynstack()

{ top = null; }

void push(T);

void pop(T &);

bool isEmpty();

};

template <class t>

voidDynstack<T>::push(T num)

{

Stacknode *newNode;

newNode = new Stacknode;

newNode ->value = num;

if(isEmpty())

{

top = newNode;

newNode->next = Null

}

else

{

newNOde->next = top;

top = newNode;

}

}

template<class T>

void Dynstack<T>::pop(T &num)

{

Stacknode *temp;

if(isempty())

{

cout<<"The stack is empty";

}

else

{

num = top->value;

temp = top->next;

top = temp;

}

}

template <class T>

bool Dynstack<T>::isEmpty()

{

bool status;

if(!top)

status = true;

else

status = false;

return status;

}

main function:

#include<iostream>

#include "Item.h"

#include"Dynstack.h"

using namespace std;

int main()

{

DynStack<Item>stack; #create a stack

Item item; #create an object

int choice;

char _name;

double _price;

int _quantity;

do

{

count<"Inventory Menu";

cout<<"1.ENter a part in to the inventory";

cout<<"2.take a part from the inventory";

cout<<"3.Quit";

cout<<"Please take a choice";

cin>>choice;

while(<choice<1||choice>3)

{

cout<<"please enter the choice";

cin<<"choice';

}

swich(choice)

{

case 1 :

cout<<"Enter the items Name";

cin>>_name;

item.setname(_name);

cout<<"Enter the price";

item.setprice(_price);

count<<"Enter the quantity";

item.setquantity(_quantity);

stack.push(item);

break;

case 2:

cout<<"You have chosen to take a part from inventory";

if(stack.isEmpty())

count<<"No parts to be removed;

else

{

stack.pop(item);

cout<<"The part removed was";

cout<<"Name"<<item.getname();

cout<<"Price"<<item.getprice();

cout<<"Quantity"<<item.getquantity();

}

break;

case 3:

while(!stack.isEmpty())

{

stack.pop(item);

cout<<"The part left in ithe inventory";

cout<<"Name"<<item.getname();

cout<<"Price"<<item.getprice();

cout<<"quantity"<<item.getquantity();

}

}

}

}

hope this helps! Please revert if any help needed.

Add a comment
Know the answer?
Add Answer to:
C++ program, item.cpp implementation. Implementation: You are supposed to write three classes, called Item, Node and In...
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++ program, inventory.cpp implementation Mostly need the int load(istream&) function. Implementation: You are supp...

    C++ program, inventory.cpp implementation Mostly need the int load(istream&) function. Implementation: You are supposed to write three classes, called Item, Node and Inventory respectively Item is a plain data class with item id, name, price and quantity information accompanied by getters and setters Node is a plain linked list node class with Item pointer and next pointer (with getters/setters) Inventory is an inventory database class that provides basic linked list operations, delete load from file / formatted print functionalities. The...

  • Problem Statement This problem provides you with a linked list composed of node objects chained together...

    Problem Statement This problem provides you with a linked list composed of node objects chained together via node pointers. Each node has a next pointer which points to the next node in the chain. The last node is identified by having a NULL (or nullptr) next pointer. The linked lists for this problem store string data. Your task: identify the longest string stored in the linked list. If two strings are of the same length, return the string that occurred...

  • In Java The following Java implementation of a class Node is given: private class Node<Object> {...

    In Java The following Java implementation of a class Node is given: private class Node<Object> { Node() { this(null, null); } Node(Object d) { this(d, null); } Node(Object d, Node n) { data = d; next = n; } Object data; Node next; } Assume that a singly linked list is implemented with a header node, but no tail node, and that it maintains only a reference to the header node. Using the class Node described above, write a MySingleLinkedList...

  • can you guys please help me with these questions thank you 9.Given a Double Linked-List that...

    can you guys please help me with these questions thank you 9.Given a Double Linked-List that contains the values in order: 1,2,3,4,5; and the following class declarations: class List private: Node* head; public: PrintBackwards (); class Node{ friend class List; private: int value; Node* next; Node* prev; Write the algorithm PrintBackwards that prints the whole list backwards. So your functionshould output: “ 5,4,3,2,1" Extra Credit if you instead implement the algorithm for a single linked-list (i.e. only using the Node*...

  • Implement the following in java. 1. An insertAtBeginning(Node newNode) function, that inserts a node at the...

    Implement the following in java. 1. An insertAtBeginning(Node newNode) function, that inserts a node at the beginning(root) of the linked list. 2. A removeFromBeginning() function, that removes the node from the beginning of the linked list and assigns the next element as the new beginning(root). 3. A traverse function, that iterates the list and prints the elements in the linked list. For the insertAtBeginning(Node newNode) function: 1. Check if the root is null. If it is, just assign the new...

  • a Java code Complete the provided code by adding a method named sum() to the LinkedList...

    a Java code Complete the provided code by adding a method named sum() to the LinkedList class. The sum() method should calculate the sum of all of the positive numbers stored in the linked list. The input format is the number of items in the list, followed by each of the items, all separated by spaces. Construction of the linked list is provided in the template below. The output should print the sum of the positive values in the list....

  • Objectives Familiarize the student with: implementing data structures in C++; dynamic allocation of C++ objects. Scenario...

    Objectives Familiarize the student with: implementing data structures in C++; dynamic allocation of C++ objects. Scenario There are some classic data structures in computer science. One example of this that you've seen in the lectures is called the stack. In the next few exercises, we'll build yet another classic data structure, the linked list. To be exact, we'll be building the singly linked list. The building block of a singly linked list is a node, which consists of two parts:...

  • I RE: Singly Linked List, Stack, and Queue Implementation Suppose, you have the following Node clas....

    I RE: Singly Linked List, Stack, and Queue Implementation Suppose, you have the following Node clas. public class Node ! int id; Node next: public Node (int id) ( this.id id: Write program codes for the traditional: 1) append int id), prepend(int id), removeFirstNodeO. displayAlINodesO, and findById(int id) operations for a singly linked list 2) pushint id), pop), peek0, displayAllNodes0 operations for a stack 3) enQueue(int id), deQueuel), displayAINodes() operations for a gueue Please make sure that you declare separate...

  • linked list operation /*************************************************************************************** This function creates a new node with the information give as a...

    linked list operation /*************************************************************************************** This function creates a new node with the information give as a parameter and looks for the right place to insert it in order to keep the list organized ****************************************************************************************/ void insertNode(string first_name, string last_name, string phoneNumber) { ContactNode *newNode; ContactNode *nodePtr; ContactNode *previousNode = nullptr; newNode = new ContactNode; /***** assign new contact info to the new node here *****/ if (!head) // head points to nullptr meaning list is empty { head = newNode;...

  • Write a C++ program that includes the following: Define the class Student in the header file Stu...

    Write a C++ program that includes the following: Define the class Student in the header file Student.h. #ifndef STUDENT_H #define STUDENT_H #include <string> #include <iostream> using namespace std; class Student { public: // Default constructor Student() { } // Creates a student with the specified id and name. Student(int id, const string& name) { } // Returns the student name. string get_name() const { } // Returns the student id. int get_id () const { } // Sets the student...

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