unit un3ch18;
interface
uses crt;
type
 status =(s, o);
 stuff_data =record
              stuff_status :status;
              number :longInt;
              cost :real;
              vender :string[20]
             end;{stuff_data}
 stuff_pointer = ^stuff;
 stuff = record
          stuff_info:stuff_data;
          link :stuff_pointer
         end;{stuff}

 stuff_queue = object
               procedure Init;
               procedure push(newstuff{in}:stuff_data);
               procedure pop (var newstuff{out}:stuff_data);
               function getPrice :real;
               procedure display;
               {procedure ask(x}{in}{:string;var y_answer}{out}{:char);  }
               procedure send_cost(newstuff{in}:stuff_data);
               procedure makestuff(var newstuff{out}:stuff_data);
              private
               first, last :stuff_pointer ;
               procedure dodisplay (data{in}:stuff_data);
              end;{stuff_queue}

implementation
procedure stuff_queue.Init;
{}
begin{Init}
 first := nil;
 last := nil
end;{Init}

{procedure stuff_queue.ask(x}{in}{:string;var y_answer}{out}{:char);}
{var next_ch :char;  {next_char as answer}
{begin}{ask}
 {repeat
  write (x:length(x));
  readLn (next_ch)
 until next_ch in ['y', 'Y', 'n', 'N' ] ;
 y_answer := next_ch
end;}{ask}



procedure stuff_queue.dodisplay(data:stuff_data);
{for displaying content of data.
 pre :none.
 post:content of data is shown.}
begin{dodisplay}
 with data do
  begin{with}
   write (number:25);
   if stuff_status = s  then write (' status= s ':15)
   else if stuff_status = o then write (' status= o ':15)
   else writeln('      An error has been occured. ');
   write ('cost=',cost:10,'$') ;
   writeLn ('vender =',vender :20)
  end{with}
end;{dodisplay}



function stuff_queue.getPrice :real;
{for calculate price of a order.
 pre :stuff_queue is defined.
 post:price is product of this function and is defined.}
var p :stuff_pointer;
begin{getPrice}
 p:=first;
 if first =nil then writeLn ('error, queue is empty ')
 else getPrice := p^.stuff_info.number*p^.stuff_info.cost
end;{getprice}


procedure stuff_queue.send_cost(newstuff{in}:stuff_data);
{for making information and price of an order.
 pre : newstuff was defined.
 post: price and information about the stuff is displayed.}
begin{send_cost}
 with newstuff do
  begin{with}
   write ('status =', 'o',' ','number =',number,' ','cost =',cost);
   writeLn (' ','vender = ',vender);
   writeLn ('total price = ',getPrice)
  end{with}
end;{send_cost}




procedure stuff_queue.push(newstuff{in}:stuff_data);
{for adding a new stuff to a queue of stuffs.
 pre : newstuff was defined.
 post:newstuff is added to queue of stuffs.}
var  p :stuff_pointer;
begin{push}
 p^.link :=nil;
 p^.stuff_info :=newstuff;
 last^.link := p;
 last := p
end;{push}


procedure stuff_queue.pop (var newstuff{out}:stuff_data);
{for omit a stuff from a queue.
 pre : queue was defined.
 post: newstuff is defined and this stuff is omitted from queue.}
var p :stuff_pointer;
begin{pop}
 p:=first;
 newstuff := p^.stuff_info;
 first := first^.link;
 p^.link :=nil;
 if p<> nil then  dispose (p)
end;{pop}

procedure stuff_queue.makestuff(var newstuff{out}:stuff_data);
{for create a stuff}
begin{makestuff}
 with newstuff do
  begin{with}
   stuff_status := s;
   write ('number of stuff>');
   readLn (number);
   write ('cost of each stuff>');
   readLn (cost);
   write ('vender> ');
   readLn (vender)
  end{with}
end;{makestuff}


procedure stuff_queue.display;
{for display contents of a queue.
 pre : queue is defined.
 post:none.}
var p :stuff_pointer;
begin{display}
 p := first;
 while p<>nil do
  begin{while}
   dodisplay(p^.stuff_info);
   p:= p^.link
  end{while}
end;{display}

end.{un3ch18}