C++ program, item.cpp implementation.




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.
C++ program, item.cpp implementation. Implementation: You are supposed to write three classes, called Item, Node and In...
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 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> { 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 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 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 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 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. 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 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 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...