Answer to Question #187315 in C++ for prathna

Question #187315

Often some situation arises in programming where data or input is dynamic in nature, i.e. the number of data item keeps changing during program execution. A live scenario where the program is developed to process lists of employees of an organization. The list grows as the names are added and shrink as the names get deleted. With the increase in name the memory allocate space to the list to accommodate additional data items. Such situations in programming require which technique. Explain the concept with the help of suitable examples


1
Expert's answer
2021-04-30T04:07:39-0400
#include <iostream>
#include <map>


using namespace std;


int main()
{
    map<string, int> names;
    bool menu = true;
    while(menu)
    {
        cout << "Choose the operation(1, 2): " << endl;
        cout << "1. Add name to vector" << endl;
        cout << "2. Remove name from vector" << endl;
        cout << "3. Exit" << endl;
        int choice;
        int counter = 0;
        cin >> choice;
        switch(choice);
        {
            case 1:
                counter++;
                string name;
                cout << "Enter name you want to add: ";
                cin >> name;
                names[name] = counter;
                break;


            case 2:
                cout << "Enter name you want to remove: ";
                cin >> name;
                names.erase(name);
                break;
        }
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS