Store Management System project with 3 classes
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <conio.h>//Use getch();
using namespace std;
class Goods
{
public:
Goods()
{
}
int kind;
char name[20];
char Id[20];
float price;
int amount;
Goods * Next;
friend ostream& operator<<(ostream& out,Goods& obj)
{
out<<obj.Id<<obj.name<<obj.amount<<obj.kind;
}
friend istream& operator>>(istream& in,Goods& obj)
{
in>>obj.Id>>obj.name>>obj.amount>>obj.kind;
}
void InputAll()
{
InputName();
InputKind();
InputID();
InputOther();
}
void InputKind()
{
Cout<<"\t\tPlease select the category: ";cin>>kind;
}
void InputName()
{
Cout<<"\t\tPlease enter the name of the product: "; cin>>name;
}
void InputID()
{
Cout<<"\t\tPlease enter the product number: "; cin>>Id;
}
void InputBuyprice()
{
Cout<<"\t\tPlease enter the unit price of the product:"; cin>>price;
}
void InputAmount()
{
Cout<<"\t\tPlease enter the product inventory:"; cin>>amount;
}
void InputOther()
{
Cout<<"\t\tPlease enter the price of the product:"; cin>>price;
Cout<<"\t\tPlease enter the quantity in stock:"; cin>>amount;
}
void ReadFile(istream & in)
{
in>>name>>kind>>Id>>price>>amount;
}
void Show()
{
Cout<<" Trade name: "<<name<<endl<<" Category: "<<kind<<endl<<"Number: "<<Id<<endl<<" Price"<<price<<endl< <"Commodity Stock: "<<amount<<endl<<endl<<endl;
}
};
class Goodsmanager : public Goods
{
public:
Goodsmanager();
~Goodsmanager();
void showMenu(int n);
void Find();
void Save();
void ModifyItem();
void RemoveItem();
void Swap(Goods *,Goods *);
void Sort();
void delgoods();
//void Chack();
int ListCount();
void Display()
{
system("cls");
i=0;
for(Goods * p=Head->Next;p!=End;p=p->Next)
{
p->Show();
i++;
}
Cout<<" has a total of "<<i<<" products "<<"\n"<<endl;
Cout<<"Enter any character! Continue...";
getch();
}
Void AddItem()//Enter product information from the keyboard
{
system("cls");
End->InputName();
showMenu(1);
End->InputKind();
do
{
End->InputID();
}while(FindID(End->Id));
End->InputOther();
End->Next = new Goods;
End=End->Next;
Cout<<" added successfully!"<<endl;
Save();
Cout<<"Enter any character! Continue...";
getch();
}
private:
Goods * Head,* End;
int i;
ifstream in;
ofstream out;
Goods *FindItem(char * name)
{
For(Goods * p=Head;p->Next!=End;p=p->Next)//If the match succeeds, the previous pointer is returned. If it is unsuccessful, it returns empty.
if(!strcmp(p->Next->name,name))return p;
return NULL;
}
Goods *FindID(char * Id)
{
For(Goods * p=Head;p->Next!=End;p=p->Next)//If the match succeeds, the previous pointer is returned. If it is unsuccessful, it returns empty.
if(!strcmp(p->Next->Id,Id))return p;
return NULL;
}
};
Void Goodsmanager::Swap(Goods *p1, Goods *p2) //Exchange data for two items
{
Goods *temp=new Goods;
strcpy(temp->name,p1->name);
temp->kind=p1->kind;
strcpy(temp->Id,p1->Id);
temp->price=p1->price;
temp->amount=p1->amount;
strcpy(p1->name,p2->name);
p1->kind=p2->kind;
strcpy(p1->Id,p2->Id);
p1->price=p2->price;
p1->amount=p2->amount;
strcpy(p2->name,temp->name);
p2->kind=temp->kind;
strcpy(p2->Id,temp->Id);
p2->price=temp->price;
p2->amount=temp->amount;
}
Man ̅ Goods ̅ ̅ ̅ ̅ Goods Goods ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅
{
Head=new Goods;
Head->Next=new Goods;
End=Head->Next;
in.open("cangku.txt");
if(!in)
Cout<<" has no inventory"<<endl;
else
{
while(!in.eof())
{
End->ReadFile(in);
if(End->name[0]=='\0')break;
End->Next=new Goods;
End=End->Next;
}
in.close();
Cout<<"\t\t\t\tRead the product information successfully!"<<"\n"<<endl;
}
}
Void Goodsmanager::showMenu(int n)// Menu ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅
{
switch(n)
{
case 1:
{
cout<<"********************************************************************************\n"
<<" 1. Home Appliances 2. Cosmetics 3. Daily Necessities 4. Beverages \n"
<<"********************************************************************************\n"<<endl;
break;}
case 2:
{
system("cls");
Cout<<"*********************** Store Warehouse Management System******************* ****"<<endl;
Cout<<"*********************** 1. Adding items ********************* ****"<<endl;
Cout<<"*********************** 2. Display items ********************* ****"<<endl;
Cout<<"*********************** 3. Sorting items******************* ****"<<endl;
Cout<<"*********************** 4. Find the item******************* ****"<<endl;
Cout<<"*********************** 5. Delete the item******************* ****"<<endl;
Cout<<"*********************** 6. Modify the item******************* ****"<<endl;
Cout<<"*********************** 7. Save product information ****************** *****"<<endl;
Cout<<"*********************** 0. Exit the system******************* ****"<<endl;
Cout<<"\t\t\n\t\t\t\t Please select: 0-8"<<endl;
break;}
case 3:
{
system("cls");
cout<<"********************************************************************************\n"
<<"\t 1. Modify the product name 4. Modify the price \t\t\n"
<<"\t 2. Modify the category 5. Modify the amount of remaining goods\t\t\n"
<<"\t 3. Change number \t\t\n"
<<"\t\t\t\t10.Modify all \n"
<<"********************************************************************************"<<endl;
Cout<<"\t\t\n\t\t\t\t Please select: 0-10"<<endl;
break;
}
case 4:
{
system("cls");
cout<<"********************************************************************************\n"
<<"\t 1. Sort by item price 2. Sort by stock quantity \n"
<<"********************************************************************************"<<endl;
Cout<<"\t\t\n\t\t\t\t Please select: 0-3"<<endl;
break;
}
case 5:
{
system("cls");
cout<<"\n\t\t *********************************\n";
Cout<<"\t\t ***** 1. Find by product name *****\n\t\t ***** 2. Find by product number *****";
Cout<<"\n\t\t *********************************\nPlease select: 0- 2";
break;
}
}
}
Goodsmanager::~Goodsmanager()
{
//Save();
for(Goods * temp;Head->Next!=End;)
{
temp=Head->Next;
Head->Next=Head->Next->Next;
delete temp;
}
delete Head,End;
}
void Goodsmanager::Find()
{
system("cls");
char name[20] ,Id[10];
int x;
Goods * p=NULL;
showMenu(5);
cin>>x;
switch(x)
{
Case 1:{cout<<"\t\tPlease enter the name of the item you are looking for:";cin>>name;
if(p=FindItem(name))
{
p->Next->Show();
Cout<<"Enter any character! Continue...";
getch();
}
else
{
Cout<<"\t\tThe item with this name was not found!"<<'\n'<<endl;
Cout<<"Enter any character! Continue...";
getch();
}
}break;
case 2:
{
Cout<<"\t\tPlease enter the number of the item you are looking for: ";cin>>Id;
if(p=FindID(Id))
{
p->Next->Show();
Cout<<"Enter any character! Continue...";
getch();
}
else
{
Cout<<"\t\tThe item with this number was not found!"<<'\n'<<endl;
Cout<<"Enter any character! Continue...";
getch();
}
}break;
}
}
Void Goodsmanager::ModifyItem() //Modify product information
{
showMenu(3);
int x;
cin>>x;
switch(x)
{
case 1:
{
char Id[20];
Goods * p=NULL;
Cout<<"\t\tPlease enter the number of the item to be modified: ";cin>>Id;
if(p=FindID(Id))
{
Cout<<"\t\tThe information of the product has been found, please enter the new information!"<<endl;
p->Next->InputName();
Cout<<" modified successfully!"<<endl;
Cout<<"Enter any character! Continue...";
getch();
}
else
{
Cout<<"\t\t Didn't find what you need!"<<endl;
Cout<<"Enter any character! Continue...";
getch();
}
break;
}
case 2:
{
char Id[20];
Goods * p=NULL;
Cout<<"\t\tPlease enter the number of the item to be modified: ";cin>>Id;
if(p=FindID(Id))
{
Cout<<"\t\tThe information of the product has been found, please enter the new information!"<<endl;
p->Next->InputKind();
Cout<<" modified successfully!"<<endl;
Cout<<"Enter any character! Continue...";
getch();
}
else
{
Cout<<"\t\t Didn't find what you need!"<<endl;
Cout<<"Enter any character! Continue...";
getch();
}
break;
}
case 3:
{
char Id[20];
Goods * p=NULL;
Cout<<"\t\tPlease enter the number of the item to be modified: ";cin>>Id;
if(p=FindID(Id))
{
Cout<<"\t\tThe information of the product has been found, please enter the new information!"<<endl;
p->Next->InputID();
Cout<<" modified successfully!"<<endl;
Cout<<"Enter any character! Continue...";
getch();
}
else
{
Cout<<"\t\t Didn't find what you need!"<<endl;
Cout<<"Enter any character! Continue...";
getch();
}
break;
}
case 4:
{
char Id[20];
Goods * p=NULL;
Cout<<"\t\tPlease enter the number of the item to be modified: ";cin>>Id;
if(p=FindID(Id))
{
Cout<<"\t\tThe information of the product has been found, please enter the new information!"<<endl;
p->Next->InputBuyprice();
Cout<<" modified successfully!"<<endl;
Cout<<"Enter any character! Continue...";
getch();
}
else
{
Cout<<"\t\t Didn't find what you need!"<<endl;
Cout<<"Enter any character! Continue...";
getch();
}
break;
}
case 5:
{
char Id[20];
Goods * p=NULL;
Cout<<"\t\tPlease enter the number of the item to be modified: ";cin>>Id;
if(p=FindID(Id))
{
Cout<<"\t\tThe information of the product has been found, please enter the new information!"<<endl;
p->Next->InputAmount();
Cout<<" modified successfully!"<<endl;
Cout<<"Enter any character! Continue...";
getch();
}
else
{
Cout<<"\t\t Didn't find what you need!"<<endl;
Cout<<"Enter any character! Continue...";
getch();
}
break;
}
}
}
void Goodsmanager::RemoveItem()
{
system("cls");
char Id[20];
Goods * p=NULL,*temp=NULL;
Cout<<"\t\tPlease enter the number of the item to be deleted: "<<endl;cin>>Id;
if(p=FindID(Id))
{
temp=p->Next;
p->Next=p->Next->Next;
delete temp;
Cout<<"\t\t deleted successfully!"<<endl;
Cout<<"Enter any character! Continue...";
getch();
}
else
{
Cout<<"\t\t Didn't find what you need!"<<endl;
Cout<<"Enter any character! Continue...";
getch();
}
}
Int Goodsmanager::ListCount() //Count the total number of records in the current linked list, return an integer
{
if(! Head)
return 0;
int n=0;
for(Goods * p=Head->Next;p!=End;p=p->Next)
{
n++;
}
return n;
}
void Goodsmanager::Sort()
{
showMenu(4);
int x;
cin>>x;
switch(x)
{
case 1:
{
system("cls");
Cout <<"\t\t sorting..."<<endl;
cout<<"\n";
Goods *p=NULL,*p1=NULL,*k=NULL;
int n=Goodsmanager::ListCount();
if(n<2)
return;
for(p=Head->Next;p!=End;p=p->Next)
for(k=p->Next;k!=End;k=k->Next)
{
if(p->price>k->price)
{
Goodsmanager::Swap(p,k);
}
}
Display();
Out.open("price.txt");
for(Goods *q=Head->Next;q!=End;q=q->Next)
out<<q->name<<"\t"<<q->kind<<"\t"<<q->Id<<"\t"<<q->price<<"\t"<<q->amount<<'\n';
out.close();
Cout<<"Save information successfully"<<endl;
Cout <<"sort completed!"<<endl;
getch();
return;
}
case 2:
{
system("cls");
Cout <<"\t\t sorting..."<<endl;
cout<<"\n";
Goods *p=NULL,*p1=NULL,*k=NULL;
int n=Goodsmanager::ListCount();
if(n<2)
return;
for(p=Head->Next;p!=End;p=p->Next)
for(k=p->Next;k!=End;k=k->Next)
{
if(p->amount>k->amount)
{
Goodsmanager::Swap(p,k);
}
}
Display();
Out.open("inventory.txt");
for(Goods *q=Head->Next;q!=End;q=q->Next)
out<<q->name<<"\t"<<q->kind<<"\t"<<q->Id<<"\t"<<q->price<<"\t"<<q->amount<<'\n';
out.close();
Cout<<"Save information successfully"<<endl;
Cout <<"sort completed!"<<endl;
getch();
return;
}
}
}
void Goodsmanager::Save()
{
out.open("cangku.txt");
for(Goods *p=Head->Next;p!=End;p=p->Next)
out<<p->name<<"\t"<<p->kind<<"\t"<<p->Id<<"\t"<<p->price<<"\t"<<p->amount<<'\n';
out.close();
Cout<<"Save information successfully"<<endl;
}
In ( ( ̅ ̅ ̅ ̅ ( ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅ ̅
{
cout << "\t\t*****************************************" << endl;
for(int i = 0; i < 3; i ++)
cout<<"\t\t******************\t\t\t\t\t\t ******************" << endl;
Cout<<"\t\t****************** Welcome to the warehouse merchandise management system****************** " << endl;
for(int i = 0; i < 3; i++)
cout<<"\t\t******************\t\t\t\t\t\t ******************"<<endl;
cout<<"\t\t*****************************************\n"<<endl;;
Goodsmanager Grade;
Cout<<"\t\t\t\tPress any key to start...";
getch();
int x;
bool quit =false;
while(!quit)
{
Grade.showMenu(2);
cin>>x;
switch(x)
{
case 0:{quit=true;break;}
case 1:{Grade.AddItem();break;}
case 2:{Grade.Display();break;}
case 3:{Grade.Sort();break;}
case 4:{Grade.Find();break;}
case 5:{Grade.RemoveItem();break;}
case 6:{Grade.ModifyItem();break;}
case 7:{Grade.Save();break;}
}
}
return 0;
}
Comments
Leave a comment