Professional Documents
Culture Documents
DSAlabtasks
DSAlabtasks
Registration No:
SOLUTION:
#include <iostream>
class Node {
public:
string product_name;
float price;
int quantity_in_stock;
string supplier;
Node* next;
Node() {
product_name = "";
price = 0.0;
quantity_in_stock = 0;
supplier = "";
next = nullptr;
this->product_name = product_name;
this->price = price;
this->quantity_in_stock = quantity_in_stock;
this->supplier = supplier;
next = nullptr;
};
class Inventory {
public:
Node* head;
Inventory() {
head = nullptr;
if (head == nullptr) {
head = product;
} else {
current_node = current_node->next;
current_node->next = product;
void display_inventory() {
current_node = current_node->next;
};
int main() {
Inventory inventory;
inventory.add_product(product1);
inventory.add_product(product2);
inventory.add_product(product3);
inventory.display_inventory();
return 0;
OUTPUT:
SOLUTION:
#include <iostream>
class Node {
public:
string product_name;
float price;
int quantity_in_stock;
string supplier;
Node* next;
Node() {
product_name = "";
price = 0.0;
quantity_in_stock = 0;
supplier = "";
next = nullptr;
}
class Inventory {
public:
Node* head;
Inventory() {
head = nullptr;
}
void display_inventory() {
Node* current_node = head;
while (current_node != nullptr) {
cout << "Product Name: " << current_node->product_name << endl;
int main() {
Inventory inventory;
inventory.add_product(product1);
inventory.add_product(product2);
inventory.add_product(product3);
return 0;
}
OUTPUT: