Thread: knapsack problem

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    7

    Unhappy knapsack problem

    i have algorithm for the knap sack i want to convert it to c++ langugh
    can you advice me ?

    can i use a file to put the data ?
    for example i have knap sack for year 2000, year 2001 and year2002
    and each of them have a size and value
    thue i have to create a 3 files

    but how can i delete the data from the files`for the next user

    or do you have another solution or better than the file???


    thank you

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You can delete a file with with the ANSI C (and thus C++) standard function remove() in <cstdio>. (Make sure that you don't have any open streams referring to the file first.)

    But it's probably a bad design to write the data into a file (or three). Why not just create three separate variables? Or better yet, one function which handles any knapsack, which you then call three times?

    Also, if you want to learn more about the knapsack problem itself, try this Wikipedia entry. http://en.wikipedia.org/wiki/Knapsack_problem
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. Knapsack Problem
    By Fork in forum C Programming
    Replies: 4
    Last Post: 11-13-2006, 12:42 PM
  5. Multiple Knapsack Problem
    By polymeta in forum C Programming
    Replies: 3
    Last Post: 11-15-2001, 08:03 PM