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...

  • 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...

  • C++ LinkedList I need the code for copy constructor and assignment operator #include <iostream> #include <string> using namespace std; typedef string ItemType; struct Node {    ItemType va...

    C++ LinkedList I need the code for copy constructor and assignment operator #include <iostream> #include <string> using namespace std; typedef string ItemType; struct Node {    ItemType value;    Node *next; }; class LinkedList { private:    Node *head;    // You may add whatever private data members or private member functions you want to this class.    void printReverseRecursiveHelper(Node *temp) const; public:    // default constructor    LinkedList() : head(nullptr) { }    // copy constructor    LinkedList(const LinkedList& rhs);    // Destroys all the dynamically allocated memory    //...

  • 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...

  • 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...

  • Introduction In this lab, you are supposed to implement a graph class with the data structure...

    Introduction In this lab, you are supposed to implement a graph class with the data structure implemented before like linked list and queue. graph The class graph contains three member variables: linkedList *adjacentVertices; //an array of linked list. For a vertice i, adjacentVertices[i] stores the linked list that contains all other vertices connected to vertice i. int numVertices; //The number of vertices in the graph. int maxNumVertices; //The maximum number of vertices the graph can hold. Following public methods are...

  • 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...

  • I need help implemeting the remove_repetitions() Here is a brief outline of an algorithm: A node...

    I need help implemeting the remove_repetitions() Here is a brief outline of an algorithm: A node pointer p steps through the bag For each Item, define a new pointer q equal to p While the q is not the last Item in the bag If the next Item has data equal to the data in p, remove the next Item Otherwise move q to the next Item in the bag. I also need help creating a test program _____________________________________________________________________________________________________________________________________________________ #ifndef...

  • The goal of this task is to reinforce the implementation of container class concepts using linked...

    The goal of this task is to reinforce the implementation of container class concepts using linked lists. Specifically, the task is to create an implementation file using a linked list. You need to use the header files, set3.h and node1.h, and the test program, test_set3.cpp. Your documentation must include the efficiency of each function. Please make your program as efficient and reusable as possible. set3.h #ifndef _SET_H #define _SET_H #include <cstdlib> #include <iostream> class set { public: typedef int value_type;...

  • 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....

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