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

  • Context: C/C++ 
  • Thread starter Thread starter CFDFEAGURU
  • Start date Start date
  • Tags Tags
    C++ Map
Click For Summary

Discussion Overview

The discussion revolves around the use of a map in C++ to manage pipe sizes and their corresponding schedules. Participants explore different data structures suitable for associating multiple schedules with a single pipe size, addressing both theoretical and practical aspects of implementation.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant questions how to use a map to associate multiple schedules with a single pipe size, suggesting that a map typically associates one key with one value.
  • Another participant proposes using a multimap to allow multiple values (schedules) for a single key (pipe size), indicating that this approach might be suitable for the problem.
  • There are suggestions to use structures or classes to hold the data, which could facilitate displaying options in user interfaces.
  • Concerns are raised about using raw arrays due to their limitations in STL containers, with alternatives like std::vector being suggested.
  • A participant confirms successful implementation using a multimap, indicating that it worked as intended for their application.

Areas of Agreement / Disagreement

Participants express differing views on the appropriate data structure to use, with some advocating for multimaps while others suggest alternative methods. The discussion does not reach a consensus on a single best approach.

Contextual Notes

Participants mention the need for familiarity with iterators when using multimaps, and there are references to the necessity of building a library or database for managing options, which may introduce additional complexity.

Who May Find This Useful

This discussion may be useful for C++ programmers looking to manage collections of related data, particularly in applications involving user input and selection from multiple options.

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

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 11 ·
Replies
11
Views
15K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
2
Views
5K
Replies
2
Views
3K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 7 ·
Replies
7
Views
8K