#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
class Ware
{
public:
int id;
char name[30];
int count;
Ware *next;
};
class ListWare
{
public:
Ware *first;
void init();
void add();//from keyboard
void add2(Ware *w);
bool deletee(int myId);
void print();
void save();
void load();
bool edit (int myId, int addCount, int delCount);
Ware *findById(int myId);
Ware *findByName(char *str);
};
void ListWare::init()
{
first=NULL;
}
bool ListWare::edit (int myId, int addCount, int delCount)
{
Ware *temp;
temp=first;
bool result=0;
while (temp!=NULL)
{
if (temp->id==myId)
{
result=1;
temp->count+=addCount;
temp->count-=addCount;
break;
}
temp=temp->next;
}
return result;
}
void ListWare::add()
{
Ware *w=new Ware;
cout<<"id: ";
cin>>(*w).id;
cout<<"name: ";
cin>>(*w).name;
cout<<"count: ";
cin>>(*w).count;
(*w).next=NULL;
if (first==NULL)
first=w;
else
{
(*w).next=first;
first=w;
}
}
void ListWare::add2(Ware *w)
{
(*w).next=NULL;
if (first==NULL)
first=w;
else
{
(*w).next=first;
first=w;
}
}
bool ListWare:

eletee(int myId)
{
}
void ListWare:

rint()
{
Ware *temp=first;
while(temp!=NULL)
{
cout<<(*temp).id<<'\t'<<'\t'<<'\t'<<'\t'<<(*temp).name<<'\t';
cout<<(*temp).count<<endl;
temp=(*temp).next;
}
}
void ListWare::save()
{
fstream f;
f.open("ware",ios:

ut);
Ware *temp=first;
while (temp != NULL)
{
f.write((char *)temp,sizeof(Ware));
temp=(*temp).next;
}
f.close();
}
void ListWare::load()
{
first=NULL;
fstream a;
a.open("ware",ios::in);
while(!a.eof())
{
Ware *c=new Ware;
a.read( (char *)c ,sizeof(Ware));
if (a.eof())
break;
add2(c);
}
a.close();
}
class Send
{
public:
void init();
int id;
char date[9];
ListWare *list;
int listCount;
//Receipt *next;
};
void Send::init()
{
list=new ListWare;
(*list).init();
// next=NULL;
listCount=0;
}
class Receipt
{
public:
void init();
int id;
char date[9];
ListWare *list;
int listCount;
Receipt *next;
};
void Receipt::init()
{
list=new ListWare;
(*list).init();
next=NULL;
listCount=0;
}
class ListReceipt
{
public:
Receipt *first;
void add();
bool deletee(int myId);
void print();
void save();
void load();
void init();
};
void ListReceipt::init()
{
first=NULL;
}
void ListReceipt::add()
{
Receipt *r=new Receipt;
(*r).init();
cout<<"Receipt id: ";
cin>>(*r).id;
cout<<"Receipt date: ";
cin>>(*r).date;
int k=-1;
while(k!=0)
{
cout<<"1: Add ware"<<endl;
cout<<"2: Delete ware"<<endl;
cout<<"0: Finish"<<endl;
cin>>k;
if (k==1)
{
//(*r).add();
}
}
}
void showFirstMessage()
{
cout<<"1: Add Ware"<<endl;
cout<<"2: Delete Ware"<<endl;
cout<<"3: Save Ware"<<endl;
cout<<"4: Load Ware"<<endl;
cout<<"5: List Ware"<<endl;
cout<<"6: Add Receipt"<<endl;
cout<<"7: List Recipt"<<endl;
cout<<"8: Add Send"<<endl;
cout<<"9: List Send"<<endl;
cout<<"10: edit"<<endl;
cout<<"0: Exit"<<endl;
}
main()
{
ListWare *list= new ListWare;
(*list).init();
int k=-1;
while (k!=0)
{
showFirstMessage();
cin>>k;
if (k==1)
{
(*list).add();
}
if (k==2)
{
cout<<"Please give ware id: ";
int id;
cin>>id;
if ((*list).deletee(id))
cout<<"deleted done";
else
cout<<"Ware is not found";