An inventory query

kfaraz_at_gmail.com
Date: 02/13/05


Date: 12 Feb 2005 23:51:27 -0800

hi

I've just started using prolog. I,ve started to make a model of a
retail system. I have defined the product nad the shopping cart(shown
below). One of the obvious queries is to find out the cost of each
product in the cart. The following code displays the cost correctly the
cost of each component of the cart, Now I would like to call
cost_of_cart(T,C), where T is the cart and C is the total cost of the
cart. for this how can I add the cost of the invidual products, in
order to obtain the total cost when the predicate cost_of_cart(T,C) is
called.

shopping_cart(cart1,[quant(12906,5),quant(7655,1), quant(4097,3)]).

cost_of_cart(T):-
                   shopping_cart(T,[quant(P,Y)|L]),
                   cost_of([quant(P,Y)|L]).

cost_of([]).
cost_of([quant(P,Y)|L]):-
                         product(P,D,_,_),
                         C is D * Y,
                         tab(4), write(P),put(9), write(C), nl,
                         cost_of(L).

the result of this program is
?- cost_of_cart(cart1).
    12906 299.95
    7655 489.99
    4097 50.97

Yes

I am just startng of in prolog so any help in this regard will be
greatly appreciated.



Relevant Pages

  • Re: Pixma IP4200/5200 - ? liable to clogging
    ... have registered as an empty cart, however, even when you refill them the ... printer reads the chip, sees the cart as empty, and gives you dire messages ... New OEM carts cost about $14 US - almost the ... printhead while under warranty. ...
    (comp.periphs.printers)
  • Re: cost per page
    ... >>It used to be that the cost per page was much less in laser printers than ... But looking at the prices of laser printer toner today I ... > cart could last a couple thousands. ... This reduces the cost per page ...
    (comp.periphs.printers)
  • Re: best cheap Canon printer?
    ... Over its line it seems to print well at reasonable cost, ... I could get a $50 rebate on selected Canon printers. ... This is a five cart printer - a black pigment ink cart and black, yellow, cyan, and magenta photo printing carts. ...
    (comp.periphs.printers)
  • Re: php shopping cart needed.
    ... the cost to include this is double what I am ... > we need an all PHP cart. ... >>> of price for this program, with no other charges involved. ...
    (microsoft.public.frontpage.programming)
  • Re: best cheap Canon printer?
    ... Over its line it seems to print well at reasonable cost, ... 3-color + printhead cart of HP or Lexmark). ... I could get a $50 rebate on selected Canon printers. ... has so little of each color ink in it that it empties very quickly. ...
    (comp.periphs.printers)