Home > Back-end >  In the object-oriented design. Exe had untreated exception: 0 x00422d96 0 xc0000005: while reading p
In the object-oriented design. Exe had untreated exception: 0 x00422d96 0 xc0000005: while reading p

Time:09-25

# include
# 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; String num, name;
Float price;
Unsigned int quantity;
Cout<" Code: "& lt; Cin> num;
Cout<" Name: "& lt; Cin> name;
Cout<" Price: "& lt; Cin> Price;

While (cin) fail ())
{
Cout<" There is an error, please input again: "& lt; Cin> Price;
}
Cout<" Quantity: "& lt; Cin> Quantity;
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!" return p;
}
Void the Display (Link Head)
{
The Link p;
P=the Head - & gt; Next;
Cout<" All the goods information "& lt; Cout<" Price code name======number "& lt; while(p!=NULL)
{
Cout Num<" "& lt; Name<" "& lt; Price<" "& lt; Quantityp=p-> Next;
}
}
Void Display_One (Link Head, string& Num, unsigned quantity)
{
The Link p;
P=Search (Head, num);
Cout<" Code number price name========subtotal (RMB) "& lt; Cout Num<" "& lt; Name<" "& lt; Price<" "& lt; "" & 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; Cin> GoOn.
If (GoOn=='N' | | GoOn=='N')
break;
The else
{
String num.
Unsigned int quantity;
Cout<" Code: "& lt; Cin> num;
Cout<" Quantity: "& lt; Cin> Quantity;
The sum +=CheckOut (p, num, quantity);
Cout<" You buy goods is: "& lt; Display_One (p, num, quantity);
Xg (Head, num, quantity);
}
}
Cout<" The pay "& lt; Cout<" Real pay: ";
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; Cout<" * 1. Input information 2. 3. Query goods display data 4. Buying goods 0. * "exit 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." Loop=0;
break;
Case 1:
The Head=the Create (Head);
break;
Case 2:
Cout<" Input the commodity code: "& lt; P=Search (Head, num);
Cout<" Price code name======number "& lt; Cout Num<" "& lt; Name<" "& lt; Price<" "& lt; Quantitybreak;
Case 3:
The Display (the Head);
break;
Case 4:
Total (the Head);
break;
}
}

Release (the Head);
return 0;
}
  • Related