C/C++ How to Use a Map in C++ for Pipe Sizes and Schedules?

  • Thread starter Thread starter CFDFEAGURU
  • Start date Start date
  • Tags Tags
    C++ Map
AI Thread Summary
Using a map in C++ to manage pipe sizes and schedules requires understanding that a standard map associates one key with one value, which doesn't fit the need for multiple schedules per pipe size. A multimap is suggested as a suitable alternative, allowing multiple values (schedules) for a single key (pipe size). Implementing this may involve using structures or classes to organize data and display options in user interfaces. Users can also opt to build a library of choices or rely on manual inputs for selection. Overall, utilizing a multimap effectively addresses the problem of associating multiple schedules with a single pipe size.
CFDFEAGURU
Messages
781
Reaction score
10
Hello all,

I am using 2008 C++ Express edition on a Windows XP machine and I have the following question regarding use of a map.

How would you use a map to do the following:

The user enters a pipe size, say 1/8" NPS, now there are three possible schedules for that pipe size. They are 10S, 40S Std, 80S Ex Hvy.

So once the pipe size of 1/8" NPS is entered by the user the three schedules are then printed for the user to select from.

Note: This is just a simplified example, in the real program there are many sizes of pipe to choose from and many schedules.

Any help would be greatly appreciated.

Thanks
Matt
 
Technology news on Phys.org
You wouldn't.

You would use a map to store a collection of key-value pairs, in a way that makes it easy to, if you have a key, to find the corresponding value.

This ability may be of use in a program for solving your problem -- but a map cannot solve your problem all by itself.
 
To make this more explicit: in a map, each key has exactly one value associated with it. Your example has three values (schedules) associated with one key (1/8" NPS).
 
You can always try to map keys to arrays (or lists, or whatever). No idea about implementation details, but I am sure it is doable.
 
Thanks for your help so far.

jtbell,

Could you use a multimap for this application?

Thanks
Matt
 
You could use struct(ures) or classes or structures of classes to hold the data and display in pop-up windows or drop-down menus. That would require you to establish a library that contains every possible choice that could be made. You would have to build the library file (database) and then call from it for your menus or windows. The data selected could then be placed into a structure or class for use in whatever you are going to do with it.
If you don't want to have a database then you could do the same thing without the library file and let the user select size and schedule from experience or manuals.
 
CFDFEAGURU said:
Could you use a multimap for this application?

I've never used a multimap myself, but after looking at what Stroustrup's book says about it, I'd say it looks perfect for your application. You need to be acquainted with using iterators, because you have to use an iterator to pull out all the values (schedules) that correspond to a given key.
 
Last edited:
Borek said:
You can always try to map keys to arrays (or lists, or whatever). No idea about implementation details, but I am sure it is doable.

You can't use raw arrays since they aren't copyable as required by STL containers. You'd have to use std::tr1::array, boost::array or a std::vector.
 
I have it all working correctly. I used the multimap function and it works perfect.

Thanks for all of you help.

Matt
 

Similar threads

Back
Top