Question

Need help studying for c++ class. We just learned about STL. And learns about iterators, vectors,...

Need help studying for c++ class. We just learned about STL. And learns about iterators, vectors, templates and doubly link list and maps.

One of the challenge question is asking:
If we were given a map or a multimap, we would have to output the keys in reverse order and keep the values the same (meaning don’t reverse or change the order) using only 1 loop.

Can someone show me an example.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Source code:-
---------------------------
#include <iostream>
#include <map>
#include <iterator>
using namespace std;
int main()
{
    map<string,string>obj;
    obj["101"]="venkanna";
    obj["102"]="koothada";
    obj["103"]="prudhvi";
    obj["104"]="Madhu";
    obj["105"]="Narayana";
    cout<<"\nthe Key values in hashmap values are"<<endl;
    cout<<"\n-------------------------------------"<<endl;
    map<string, string> :: iterator itr;
    for(itr =obj.begin();itr!=obj.end();++itr)
    {
        cout<<itr->first<<"->\t"<<itr->second<<endl;
    }
    cout<<"\nthe reverse order of Key values in hashmap values are"<<endl;
    cout<<"\n-------------------------------------"<<endl;
    map<string, string> :: reverse_iterator itr2;
    for(itr2 =obj.rbegin();itr2!=obj.rend();++itr2)
    {
        cout<<itr2->first<<"->\t"<<itr2->second<<endl;
    }
    return 0;
}
sample output:-
-------------------------


the Key values in hashmap values are 101- enkanna 102-koothada 103 prudhui 104→ Madhu 105-Narayana the reverse order of Key v

Add a comment
Know the answer?
Add Answer to:
Need help studying for c++ class. We just learned about STL. And learns about iterators, vectors,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have a programming assignment for a introductory c++ class and I am really struggling writing...

    I have a programming assignment for a introductory c++ class and I am really struggling writing this program. Below are the assignment requirements, I am unable to use vectors in stl and I keep getting a ton of compiling errors. Thank you chegg experts. You have really helped me out this semester. Your responses and code has cleared up so many issues ive had. Description The purpose of this challenge is to employ the use of basic functions and arrays....

  • Hi there! I need to compare two essay into 1 essay, and make it interesting and...

    Hi there! I need to compare two essay into 1 essay, and make it interesting and choose couple topics which im going to talk about in my essay FIRST ESSAY “Teaching New Worlds/New Words” bell hooks Like desire, language disrupts, refuses to be contained within boundaries. It speaks itself against our will, in words and thoughts that intrude, even violate the most private spaces of mind and body. It was in my first year of college that I read Adrienne...

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

  • I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter T...

    I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter Two, “Keys to Successful IT Governance,” from Roger Kroft and Guy Scalzi’s book entitled, IT Governance in Hospitals and Health Systems, please refer to the following assignment instructions below. This chapter consists of interviews with executives identifying mistakes that are made when governing healthcare information technology (IT). The chapter is broken down into subheadings listing areas of importance to understand...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT