# include
using namespace std;
Struct Sale
{
String num.
String name;
Float price;
Unsigned int quantity;
Struct Sale * next;
};
Typedef struct Sale Node;
Typedef Node * Link;
//create a list
Link the Create (Link Head)
{
The Head=new Node (Link);
The Head - & gt; Num="";
The Head - & gt; Name="";
The Head - & gt; Price=0.0;
The Head - & gt; Quantity=0;
The Head - & gt; next=NULL;
The Link p;//define a used to calculate the pointer p
P=the Head;
The Link DNode;
Char GoOn.
Do
{
Cout<" Commodity warehousing information "& lt;
Float price;
Unsigned int quantity;
Cout<" Code: "& lt;
Cout<" Name: "& lt;
Cout<" Price: "& lt;
While (cin) fail ())
{
Cout<" There is an error, please input again: "& lt;
}
Cout<" Quantity: "& lt;
While (cin) fail ())
{
Cout<" There is an error, please input again: "& lt;
Cin> Quantity;
}
DNode=new Node (Link);
DNode - & gt; Num=num;
DNode - & gt; Name=name;
DNode - & gt; Price=price;
DNode - & gt; Quantity=quantity;
DNode - & gt; next=NULL;
p-> Next=DNode;
P=DNode;
Cout<" Information recorded success, whether to continue? (Y/N) ";
Cin> GoOn.
}
While (GoOn=='Y' | | GoOn=='Y');
Return the Head;
}
//release list
Void Release (Link Head)
{
The Link p;
While (the Head!=NULL)
{
P=the Head;
The Head=Head - & gt; Next;
delete p;
}
}
//query
The Link Search (Link Head, string& Num)
{
The Link p;
P=the Head;
while(p!=NULL)
{
If (p - & gt; Num==num)
return p;
The else
p=p-> Next;
}
Cout<" No such goods!"
}
Void the Display (Link Head)
{
The Link p;
P=the Head - & gt; Next;
Cout<" All the goods information "& lt;
{
Cout
}
}
Void Display_One (Link Head, string& Num, unsigned quantity)
{
The Link p;
P=Search (Head, num);
Cout<" Code number price name========subtotal (RMB) "& lt;
}
//a single commodity summary
Float CheckOut (Link Head, string& Num, unsigned quantity)
{
The Link p;
Float the sum (0);
P=Search (Head, num);
Sum=(p - & gt; Price * quantity);
Return the sum.
}
Void xg (Link Head, string& Num, unsigned quantity)
{
The Link p;
P=Search (Head, num);
p-> Quantity=p - & gt; Quantity - quantity;
}
//total checkout
Void Total (Link Head)
{
The Link p;
P=the Head;
Float the sum (0);
Float fukuan;
Char GoOn.
While (1)
{
Cout<" End please press \ 'N \ continue to press any other key "& lt;
If (GoOn=='N' | | GoOn=='N')
break;
The else
{
String num.
Unsigned int quantity;
Cout<" Code: "& lt;
Cout<" Quantity: "& lt;
The sum +=CheckOut (p, num, quantity);
Cout<" You buy goods is: "& lt;
Xg (Head, num, quantity);
}
}
Cout<" The pay "& lt;
Cin> Fukuan;
Cout<" Change "& lt;
Int main ()
{
//* * * * * * * * * * * * menu options
The Link Head=NULL;
The Link p;
String num.
Int loop=1;
While (loop)
{
Cout<" * * * * * * * welcome to, please choose to enter the system * * * * * * * * * "& lt;
Int the menu;
Cin> The menu;
If (cin) fail ())
{
Cout<" There is an error, please input again!"
Cin> The menu;
}
The switch (menu)
{
Case 0:
Cout<" Have withdrawn from the system."
break;
Case 1:
The Head=the Create (Head);
break;
Case 2:
Cout<" Input the commodity code: "& lt;
Cout<" Price code name======number "& lt;
Case 3:
The Display (the Head);
break;
Case 4:
Total (the Head);
break;
}
}
Release (the Head);
return 0;
}