0% found this document useful (0 votes)
15 views3 pages

Upkoad Cs 301p

Uploaded by

hejaz589
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)
15 views3 pages

Upkoad Cs 301p

Uploaded by

hejaz589
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/ 3

#include<iostream>

#include<string>
#include<conio.h>
using namespace std;

class Part {
public:
int partID;
string partName;
int quantity;
Part* next;

Part(int partID,string partName,int quantity) :


partID(partID),partName(partName),
quantity(quantity), next(NULL) {}
};

class Inventory {
public:
Part* head;

Inventory() : head(NULL) {}

void addPart (int partID, string partName,int quantity) {


Part* newPart = new Part(partID,partName,quantity);
newPart->next = NULL;
if(head == NULL)
{
head = newPart;
}
else
{
Part* ptr = head;
while(ptr->next != NULL)
{
ptr = ptr->next;
}
ptr->next = newPart;
}
}

void deletePart(int partID) {


Part* current = head;
Part*prev = NULL;

while (current != NULL && current->partID != partID) {


prev = current;
current = current->next;
}

if (current == NULL) {
return;
}
if (prev == NULL) {
head = current->next;
} else {
prev->next = current->next;
}

delete current;
}

void updateQuantity(int partID,int newQuantity) {


Part* current = head;

while (current != NULL) {


if(current->partID == partID) {
current->quantity = newQuantity;
return;
}
current = current->next;
}
}

void findPart(int partID) {


Part* current = head;

while (current != NULL) {


if (current->partID == partID) {
cout << "Found Part:ID " << current->partID;
cout << ",Name " << current->partName;
cout << ",Quantity " <<current->quantity << "\n";
return;
}
current = current->next;
}

cout << "Part with ID " << partID << " not found.\n";
}

void printInventory() {
cout << "Part ID Part Name Quantity\n";
cout << "--------------------------------------\n";
Part* current = head;
while (current != NULL) {
cout << current->partID <<" "<<current-
>partName;
cout << " " << current->quantity << "\n";
current = current->next;
}
cout << "\n";
}
};

int main() {
cout << "---------------------------------------------\n";
cout << "Computer Parts Management system [Bc230218902]\n";
cout << "----------------------------------------------\n";

Inventory storeInventory;

storeInventory.addPart(101, "SSD", 25);


storeInventory.addPart(102, "RAM", 40);
storeInventory.addPart(103, "HDD", 15);

cout <<"\nInventory Added.\n";


storeInventory.printInventory();

cout << "Finding Part ID 101:\n";


storeInventory.findPart(101);
cout << "\n";

cout << "After Deleting SSD and Updating RAM Quantity....\n\n";

storeInventory.deletePart(101);
storeInventory.updateQuantity(102, 50);

storeInventory.printInventory();

getch();
return 0;
}

You might also like