0% found this document useful (0 votes)
18 views10 pages

DSAlabtasks

The document describes an assignment to create a simple inventory management system for a store using a linked list. The linked list will have nodes where each node represents a product with attributes like name, price, quantity and supplier. The program allows adding new products to the inventory and displaying the current inventory. Sample code is provided to define the node class and inventory class with methods to add products and display inventory. The main function adds sample products and calls the display method.

Uploaded by

maazhu78
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views10 pages

DSAlabtasks

The document describes an assignment to create a simple inventory management system for a store using a linked list. The linked list will have nodes where each node represents a product with attributes like name, price, quantity and supplier. The program allows adding new products to the inventory and displaying the current inventory. Sample code is provided to define the node class and inventory class with methods to add products and display inventory. The main function adds sample products and calls the display method.

Uploaded by

maazhu78
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

SHAHEED ZULFIKAR ALI BHUTTO INSTITUTE OF SCIENCE AND TECHNOLOGY

COMPUTER SCIENCE DEPARTMENT

Total Marks: ____________

Obtained Marks: ____________

DATA STRUCTURES AND ALGORITHM


Assignment # 01

Submitted to: Miss Sidra Safdar _______________________________ _______

Submitted by: Maaz Saleem

Registration No:

DSA BSAI-3A SZABIST-ISB


Q1: Create a simple inventory management system for a store. In this system, you
will use a 2D array where each row represents a product, and each column contains
information such as the product name, price,quantity in stock, and supplier. The
program should allow you to:

1. Add a new product to the inventory.

2. Display the current inventory.

SOLUTION:
#include <iostream>

using namespace std;

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;

DSA BSAI-3A SZABIST-ISB


}

Node(string product_name, float price, int quantity_in_stock, string supplier) {

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;

void add_product(Node* product) {

if (head == nullptr) {

head = product;

} else {

Node* current_node = head;

DSA BSAI-3A SZABIST-ISB


while (current_node->next != nullptr) {

current_node = current_node->next;

current_node->next = product;

void display_inventory() {

Node* current_node = head;

while (current_node != nullptr) {

cout << "Product Name: " << current_node->product_name << endl;

cout << "Price: " << current_node->price << endl;

cout << "Quantity in Stock: " << current_node->quantity_in_stock << endl;

cout << "Supplier: " << current_node->supplier << endl;

cout << endl;

current_node = current_node->next;

};

int main() {

Inventory inventory;

// Add some products to the inventory

DSA BSAI-3A SZABIST-ISB


Node* product1 = new Node("Apple", 1.00, 10, "Walmart");

Node* product2 = new Node("Banana", 0.50, 5, "Target");

Node* product3 = new Node("Orange", 0.75, 3, "Costco");

inventory.add_product(product1);

inventory.add_product(product2);

inventory.add_product(product3);

// Display the inventory

inventory.display_inventory();

return 0;

OUTPUT:

DSA BSAI-3A SZABIST-ISB


DSA BSAI-3A SZABIST-ISB
Q2: create a simple inventory management system for a store. In this system,
you will use a linklist where each row represents a product, and each column
contains information such as the product name, price,quantity in stock, and
supplier. The program should allow you to:
1. Add a new product to the inventory.
2. Display the current inventory.

SOLUTION:

#include <iostream>

using namespace std;

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;
}

Node(string product_name, float price, int quantity_in_stock, string supplier) {


this->product_name = product_name;

DSA BSAI-3A SZABIST-ISB


this->price = price;
this->quantity_in_stock = quantity_in_stock;
this->supplier = supplier;
next = nullptr;
}
};

class Inventory {
public:
Node* head;

Inventory() {
head = nullptr;
}

void add_product(Node* product) {


if (head == nullptr) {
head = product;
} else {
Node* current_node = head;
while (current_node->next != nullptr) {
current_node = current_node->next;
}
current_node->next = product;
}
}

void display_inventory() {
Node* current_node = head;
while (current_node != nullptr) {
cout << "Product Name: " << current_node->product_name << endl;

DSA BSAI-3A SZABIST-ISB


cout << "Price: " << current_node->price << endl;
cout << "Quantity in Stock: " << current_node->quantity_in_stock << endl;
cout << "Supplier: " << current_node->supplier << endl;
cout << endl;
current_node = current_node->next;
}
}
};

int main() {
Inventory inventory;

// Add some products to the inventory


Node* product1 = new Node("Apple", 1.00, 10, "Walmart");
Node* product2 = new Node("Banana", 0.50, 5, "Target");
Node* product3 = new Node("Orange", 0.75, 3, "Costco");

inventory.add_product(product1);
inventory.add_product(product2);
inventory.add_product(product3);

// Display the inventory


inventory.display_inventory();

return 0;
}

OUTPUT:

DSA BSAI-3A SZABIST-ISB


DSA BSAI-3A SZABIST-ISB

You might also like