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

Product Inventory Management System

The document defines a C++ class for managing product inventory. The class contains methods for adding, updating, deleting and viewing products. It also contains methods for updating product quantities during sale and updating the data file. The main function displays a menu and calls the appropriate class methods based on the user's selection to manage the product inventory stored in a data file.

Uploaded by

Piyush Sidana
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 views13 pages

Product Inventory Management System

The document defines a C++ class for managing product inventory. The class contains methods for adding, updating, deleting and viewing products. It also contains methods for updating product quantities during sale and updating the data file. The main function displays a menu and calls the appropriate class methods based on the user's selection to manage the product inventory stored in a data file.

Uploaded by

Piyush Sidana
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

#include<iostream>

#include<stdio.h>

#include<fstream>

#include<string.h>

using namespace std;

/* Class declaration */

class product

intprice,quantity;

char name[20],perishable[3];

public:

char* get_name();

intget_quantity();

voidadd_product();

voidupdate_product();

voidupdate_quantity(int);

voiddelete_product();

voidsale_product();

voidview_inventory();

}g;

/* To return product name of product */

char* product::get_name()

return name;

}
/* To return quantity of product */

int product::get_quantity()

return quantity;

/* To update quantity of product */

void product::update_quantity(int n)

quantity=quantity-n;

/* To add a new product */

void product::add_product()

system("cls");

char x[20];

cout<<"\n\t\t=======================================================================
========";

cout<<"\n\t\t|| || ADD PRODUCT || ||";

cout<<"\n\t\t=======================================================================
========";

cout<<"\n\n\t\tEnter Product Name :- ";

fflush(stdin);

gets(x);

int flag=0;
ifstream file("[Link]");

while([Link]((char*)&g,sizeof(g)))

if(strcmpi(get_name(),x)==0)

flag=1;

break;

[Link]();

if(flag==0)

strcpy(name,x);

cout<<"\n\t\tEnter Product Price :- ";

cin>>price;

cout<<"\n\t\tEnter Product Quantity :- ";

cin>>quantity;

cout<<"\n\t\tIs it Perishable (Yes / No) :- ";

fflush(stdin);

gets(perishable);

cout<<"\n\n\t\t\t\t !!!!! Product added in inventory successfully !!!!!";

ofstream file("[Link]",ios::app);

[Link]((char*)&g,sizeof(g));

[Link]();

else
{

cout<<"\n\n\t\t\t\t !!!!! Product is already present in inventory !!!!!";

/* To update a product */

void product::update_product()

system("cls");

char x[20];

int flag=0,pos,choice;

cout<<"\n\t\t=======================================================================
========";

cout<<"\n\t\t|| || UPDATE PRODUCT || ||";

cout<<"\n\t\t=======================================================================
========";

cout<<"\n\n\t\tEnter the product name to update :- ";

fflush(stdin);

gets(x);

fstream file("[Link]");

while(![Link]())

pos=[Link]();

[Link]((char*)&g,sizeof(g));

if(strcmpi(get_name(),x)==0)
{

flag=1;

break;

if(flag==0)

cout<<"\n\n\t\t\t\t !!!!! Product is not present in inventory !!!!!";

else

system("cls");

cout<<"\n\t\t=======================================================================
========";

cout<<"\n\t\t|| || UPDATE PRODUCT || ||";

cout<<"\n\t\t=======================================================================
========";

cout<<"\n\t\t|| ||";

cout<<"\n\t\t|| !!!!!!!!!! 1. TO UPDATE PRICE !!!!!!!!!! ||";

cout<<"\n\t\t|| ||";

cout<<"\n\t\t|| !!!!!!!!!! 2. TO UPDATE QUANTITY !!!!!!!!!! ||";

cout<<"\n\t\t|| ||";

cout<<"\n\t\t=======================================================================
========";

cout<<"\n\n\t\tEnter your choice :- ";

cin>>choice;

if(choice==1)

{
cout<<"\n\t\tEnter new price of the product :- ";

cin>>price;

else if(choice==2)

cout<<"\n\t\tEnter new quantity of the product :- ";

cin>>quantity;

cout<<"\n\n\t\t\t\t !!!!! Product updated in inventory successfully !!!!!";

[Link](pos);

[Link]((char*)&g,sizeof(g));

[Link]();

/* To delete a product */

void product::delete_product()

system("cls");

int flag=0;

char x[20];

cout<<"\n\t\t=======================================================================
========";

cout<<"\n\t\t|| || DELETE PRODUCT || ||";

cout<<"\n\t\t=======================================================================
========";
cout<<"\n\n\t\tEnter the product name to delete :- ";

fflush(stdin);

gets(x);

ifstream file1("[Link]");

ofstream file2("[Link]",ios::app);

while([Link]((char*)&g,sizeof(g)))

if(strcmpi(get_name(),x)==0)

flag=1;

else

[Link]((char*)&g,sizeof(g));

[Link]();

[Link]();

remove("[Link]");

rename("[Link]","[Link]");

if(flag==0)

cout<<"\n\n\t\t\t\t !!!!! Product is not present in inventory !!!!!";

else

cout<<"\n\n\t\t\t\t !!!!! Product deleted from inventory successfully !!!!!";

/* To sale a product */

void product::sale_product()

{
system("cls");

char x[20];

int flag=0,pos,choice,n;

cout<<"\n\t\t=======================================================================
========";

cout<<"\n\t\t|| || SALE PRODUCT || ||";

cout<<"\n\t\t=======================================================================
========";

cout<<"\n\n\t\tEnter the product name to sale :- ";

fflush(stdin);

gets(x);

fstream file("[Link]");

while(![Link]())

pos=[Link]();

[Link]((char*)&g,sizeof(g));

if(strcmpi(get_name(),x)==0)

flag=1;

break;

if(flag==0)

cout<<"\n\n\t\t\t\t !!!!! Product is not present in inventory !!!!!";


}

else

cout<<"\n\t\tEnter the quantity of the product :- ";

cin>>n;

if(n>get_quantity())

cout<<"\n\n\t\t\t\t !!!!! Sorry, sufficient quantity is not present in inventory !!!!!";

else

cout<<"\n\n\t\t\t\t !!!!! Product sold from inventory successfully !!!!!";

update_quantity(n);

[Link](pos);

[Link]((char*)&g,sizeof(g));

[Link]();

/* To view inventory */

void product::view_inventory()

system("cls");

cout<<"\n\t\t=======================================================================
========";

cout<<"\n\t\t|| || INVENTORY || ||";


cout<<"\n\t\t=======================================================================
========";

cout<<"\n\n\t\t\t\t\t Product Name :- "<<name;

cout<<"\n\n\t\t\t\t\t Product Price :- "<<price;

cout<<"\n\n\t\t\t\t\t Product Quantity :- "<<quantity;

cout<<"\n\n\t\t\t\t\t Perishable :- "<<perishable;

cout<<"\n\n\t\t=====================================================================
==========";

/* To display main menu */

voidmain_menu()

system("cls");

cout<<"\n\t\t=======================================================================
=========";

cout<<"\n\t\t|| ########## --------------------------- ########## ||";

cout<<"\n\t\t|| ########## SHOPPING MANAGEMENT SYSTEM ########## ||";

cout<<"\n\t\t|| ########## --------------------------- ########## ||";

cout<<"\n\t\t=======================================================================
=========";

cout<<"\n\t\t|| ||";

cout<<"\n\t\t|| !!!!!!!!!! 1. TO ADD A NEW PRODUCT !!!!!!!!!! ||";

cout<<"\n\t\t|| ||";

cout<<"\n\t\t|| !!!!!!!!!! 2. TO UPDATE A PRODUCT !!!!!!!!!! ||";

cout<<"\n\t\t|| ||";

cout<<"\n\t\t|| !!!!!!!!!! 3. TO DELETE A PRODUCT !!!!!!!!!! ||";

cout<<"\n\t\t|| ||";

cout<<"\n\t\t|| !!!!!!!

!!! 4. TO SALE A PRODUCT !!!!!!!!!! ||";


cout<<"\n\t\t|| ||";

cout<<"\n\t\t|| !!!!!!!!!! 5. TO VIEW INVENTORY !!!!!!!!!! ||";

cout<<"\n\t\t|| ||";

cout<<"\n\t\t|| !!!!!!!!!! 6. TO EXIT !!!!!!!!!! ||";

cout<<"\n\t\t|| ||";

cout<<"\n\t\t=======================================================================
=========";

/* Main function */

int main()

charch;

int choice;

do

main_menu();

cout<<"\n\n\t\t\t\t\tEnter your choice :- ";

cin>>choice;

if(choice==1)

p.add_product();

else if(choice==2)

p.update_product();

else if(choice==3)

p.delete_product();
else if(choice==4)

p.sale_product();

else if(choice==5)

int flag=0;

ifstream file("[Link]");

while([Link]((char*)&g,sizeof(g)))

flag=1;

p.view_inventory();

cout<<endl<<endl;

system("pause");

[Link]();

if(flag==0)

system("cls");

cout<<"\n\n\t\t\t\t !!!!! No inventory Found !!!!!";

else if(choice==6)

exit(0);

cout<<"\n\nWant to go to main menu (y/n) :- ";

cin>>ch;
}while(ch=='y');

return 0;

Common questions

Powered by AI

The main purpose of the 'product' class is to manage products in an inventory system through various operations such as adding, updating, deleting, selling, and viewing products. The class maintains product details like name, price, quantity, and whether it is perishable. The 'add_product' method allows for new products to be added to the inventory, checking for duplicates before adding. The 'update_product' method enables updates to the price and quantity of existing products. 'delete_product' removes a product from inventory, 'sale_product' handles selling by updating quantities, and 'view_inventory' displays the current inventory status .

The program supports modular programming by defining distinct methods for each inventory operation, such as 'add_product', 'update_product', 'delete_product', etc., within the 'product' class. This encapsulation of functionality into individual, reusable methods simplifies maintenance, testability, and debugging. It enables code reuse and separation of concerns, where each method independently manages a specific aspect of the inventory, improving overall code readability and scalability .

The inventory viewing function reads and outputs all product data stored in 'product.dat', reflecting the current inventory state by displaying each product's name, price, quantity, and perishability status. This thorough visualization allows users to review stock levels, product details, and decide on the need for restocking or promotions. The organized display supports informed decision-making by providing a real-time snapshot of inventory health, aiding strategic planning and inventory management .

The 'system("cls")' function is used to clear the console screen before displaying a new menu or prompt, providing a clean interface by removing previous outputs. This improves readability and user focus on the current operation. However, a potential drawback is its platform dependency, as 'cls' is specific to Windows and may not work on other operating systems like Linux or MacOS, leading to compatibility issues. This command can also pose security risks if user input is not adequately sanitized .

To improve the program for handling multiple product entries simultaneously, batch processing could be introduced, allowing multiple products to be added, updated, or deleted in a single operation through lists or files of product details. Enhancing the file handling with indexing methods or an actual database could improve performance for large inventories. Integrating multi-threading could also optimize operations, enabling concurrent processing without slowing user interaction .

The program identifies duplicate product entries during the addition of a new product by reading through existing entries in 'product.dat' and comparing the names using `strcmpi(get_name(), x) == 0`. If a match is found, the 'flag' variable is set to 1, and a message informs the user that the product already exists, preventing the addition of duplicates. This check before writing new data ensures data consistency and avoids redundancy .

The main menu design follows user interface design principles by offering a clear, labeled layout structured with line delimiters and numbered options, improving usability by helping users easily identify and choose tasks. The use of numbered options for actions like adding or deleting a product facilitates quick navigation in text-based interfaces. It provides feedback by acknowledging user selections through confirmation messages, reinforcing actions taken. While functional for a command-line program, enhancements like clearer prompts and error handling can further improve the user experience .

The program uses file operations to persistently store and manage product information, simulating a product database. It uses an 'ifstream' to read product data, allowing for checks such as duplicates during addition. 'Ofstream' is used to write new data into the file, which helps in saving updates or new entries. Additionally, 'fstream' enables both reading and writing operations for updates and sales. It temporarily stores operations in 'temp.dat' before these changes are committed back to 'product.dat', ensuring data integrity during deletions and updates .

To enhance the 'sale_product' method's functionality, several improvements could be implemented: 1) Introduce an error message if an invalid product name is entered. 2) Automate update notifications when low stock levels are reached. 3) Enable partial sales if full requested quantity isn't available, offering the maximum available quantity. 4) Track sales history for reporting and analytics. 5) Implement user authentication to restrict access and maintain sales log integrity .

The program checks if the requested sale quantity exceeds the available product quantity using `if(n > get_quantity())`. If the requested sale quantity is greater than the available quantity, the program outputs a message stating that sufficient quantity is not present in the inventory, thus preventing the quantity from becoming negative. This conditional check ensures that a product's quantity cannot drop below zero due to excessive sales .

You might also like