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