Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Mapping Tem...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 7 Topic 9540 of 9775
Post > Topic >>

Re: Mapping Templates function betweeen 2 class

by "Alf P. Steinbach" <alfps@[EMAIL PROTECTED] > Apr 24, 2008 at 03:43 PM

* yogesh:
> 
> I need to know how to solve this problem of the code ,

I'm not sure how this one slipped past moderation, but the moderators
(praise be 
upon them![1] :-)) are only human.

This is clearly homework and as such, the article should have been
rejected.

Note that if you don't do your homework yourself, but just ask others to
do
it, 
you will only be postponing the point where you're unable to proceed with
the 
course (or some other course).  And on the way you will then have wasted
other's 
time and money, namely those helping you, and your own or your family's
money, 
because instead of paying tuition and not earning wages and then failing
the

course or some later course, you could have been working /earning/ money.
Also, 
please don't post the same article independently to many newsgroups,
because

that is an additional waste of time for those wi****ng to help you, and for
readers.


> kindly help me if any one know this
>   given 2 classes A and B defined as follows
>       struct A { int a; }
>       struct B { int b; char c; }
>     the requirement is to efficiently write 2 map classes
>       1. class AMap
>      It should have member functions similar to below
>        add (const std::string name, A*)
>        A* get (const std::string name)
>        remove(const std::string name)
>       2. class BMap
>      It should have member functions similar to below
>        add (const std::string name, B*)
>        B* get (const std::string name)
>        remove(const std::string name)
>     Note that in the above add/get/remove functions, I have
> deliberately not provided the correct signatures as that is what you
> need to create.

The above paragraph is a message from your teacher to you.  He or she is
hinting 
that the signatures are not perfect.  Consider references instead of
pointers.


>     Add a main routine that exercises all the above functions
>     no extra libs like glib should be used; STL may be used

If you can use "STL", presumably meaning the C++ standard library, then
one
way 
to cheat would be to use std::map.  However, I'm sure your teacher meant
that 
you could use the standard C++ library in your test program, and that you
should 
not use std::map in the implementation of the two classes AMap and BMap.

Essentially your teacher is asking you to create two classes AMap and BMap
akin 
to std::map, except not as a template class that can handle any kinds of
keys 
and values, but just handling strings as keys, and A and B as values.  The

requirement of "efficiently" probably means that a linear search for a key
is 
not sufficient except as an optimization for small number of keys.  The
general 
search must use e.g. a binary search or a hash table lookup.

Presumably the intent is to then let you realize that the two classes AMap
and 
BMap are (or could be) identical except for the value type that a key
retrieves, 
and then to introduce you to templates, where instead of two distinct
classes 
AMap and BMap you can just write one general template class, like
std::map.


Cheers, & hth.,

- Alf


Notes:
[1] We do receive praise for our work, thank you all.  Also many many
thanks
to 
those who re****t problems.  Without knowing about problems we can't fix
them.

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 7 Posts in Topic:
Mapping Templates function betweeen 2 class
yogesh <yogeshkumark@[  2008-04-24 01:04:38 
Re: Mapping Templates function betweeen 2 class
Nicola Musatti <nicola  2008-04-24 15:18:45 
Re: Mapping Templates function betweeen 2 class
"Alf P. Steinbach&qu  2008-04-24 15:43:21 
Re: Mapping Templates function betweeen 2 class
red floyd <no.spam@[EM  2008-04-24 15:43:19 
Re: Mapping Templates function betweeen 2 class
Stuart Golodetz <sgolo  2008-04-24 15:43:20 
Re: Mapping Templates function betweeen 2 class
Alex Shulgin <alex.shu  2008-04-25 03:41:56 
Re: Mapping Templates function betweeen 2 class
nickf3 <nickf3@[EMAIL   2008-04-25 03:41:25 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Jul 8 23:26:53 CDT 2008.