Two questions??

This is a discussion on Two questions?? within the C++ Programming forums, part of the General Programming Boards category; 1) Borland C++ or Visual C++. I've used Borland before but I might need to do some low-level display work ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    124

    Question Two questions??

    1) Borland C++ or Visual C++. I've used Borland before but I might need to do some low-level display work (e.g. plot a graph etc). Is there any performance difference between the two. Which would be easier to handle C++ stuff and also help with a little bit of graphics?

    2) I've decided to use a MULTIMAP for a sequence comparision comparision program. The data structures are:
    Code:
    struct COORD
    {
       int x, y;  //for the coordinates
       char Letter;      //for character name
    };
    
    multimap <COORD, int> Nodes;  //the int is the 'key'
    The problem is that the key is not unique. Here're some values in the multimap:

    x=1,y=2 ; Letter=A ; Key=1
    x=3,y=7 ; Letter=A ; Key=4
    x=4,y=7 ; Letter=B ; Key=3
    x=5,y=8 ; Letter=B ; Key=3
    x=6,y=9 ; Letter=C ; Key=3
    x=6,y=11; Letter=A ; Key=5


    The key is basically (y - x). Now, I want to use an iterator to the MULTIMAP and pick out all keys with the same value (e.g. Key = 3) and then store these values in another multimap. Problem is I don't know the value of the key from before. I just know there will be repititions but I don't know what those values are.

    Also, how do I store the entries that I get from the MULTIMAP, given that I don't know how many of each Key I have?

    Thanks!

    Edit:

    Ok, I realize that I could get around this by storing all the keys in a vector while I'm populating the multimap. The problem is I only want to have unique keys in the vector, no repititions. Is there a way where I could simply push something on a vector (or something else) and if the element already exists then it's simply overwritten. I don't want to do comparisions to do the same cause that would add needless computations to my program.
    Last edited by alvifarooq; 05-30-2005 at 02:48 AM.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    124
    Is it true that while inserting into a map if they keys are the same (as above), previous data will be overwritten? If so, then how do I get to the stage above i.e.
    Code:
    x=1,y=2 ; Letter=A ; Key=1
    x=3,y=7 ; Letter=A ; Key=4
    x=4,y=7 ; Letter=B ; Key=3
    x=5,y=8 ; Letter=B ; Key=3
    x=6,y=9 ; Letter=C ; Key=3
    x=6,y=11; Letter=A ; Key=5

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    A multimap can store multiple values with the same keys. A map cannot.

    I believe that Visual C++ produces slightly faster code than Borland C++, but I'm not sure. The difference will not be big.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    124
    oh ok...So, what's the best way to pick out all keys with the same value (e.g. Key = 3) and then store these MAP entries in another data structure; given that I don't know the key values beforehand.

    Also, in the Visual C++ vs. Borland C++ case, I'm interested in speed, and internal functions for graphics (e.g. the chart function in MATLAB where I just give the program coordinates and MATLAB makes the graph for me)

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Neither compiler has internal functions for graphics. You can use the low-level graphics functions of the GDI, or you get a real graphing library. Neither ought to be compiler-bound.

    What do you mean, you don't know the key?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    124
    Regarding the VC++ thing, I want to know which supports plotting graphs in the most efficient manner possible.

    I have several values for keys, e.g. -3, -1, -1, 2, 3, 3, 3, 4 like that...but let's say i use find() for the multimap, i won't know what value to use to find the corresponding entry. What I want to be able to do is to find all multiple-key entries (e.g. 3 above) and single key entries and then store then store those records somewhere else. Simply, how to use find() in this case.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You don't use find. You use find to find the element(s) corresponding to known keys. In your situation, you iterator through the whole map and dispatch elements to other maps based on their key.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Registered User
    Join Date
    Sep 2004
    Posts
    124
    ya i was hoping there was a simpler way...this way i have to make another map that stores only the single keys and then compare these against the multimap keys when i want to do the transfer...one question though: When I insert numbers (key) in a MAP, if these numbers are not unique (e.g. 1,2,2,3,3,3,3,4,5) in the end the entries in my map will be:

    a) 1,2,2,3,3,3,3,4,5 OR
    b) 1,2,3,4,5

    as in will i get overwrites for the key? (b) is what I'm looking for.

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    A std::map will overwrite the values of the key.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 08:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21