Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me identify what is wrong in the following C++ code. #include <iostr

ID: 3677472 • Letter: P

Question

Please help me identify what is wrong in the following C++ code.

#include <iostream>

#include <String>

#include <Map>

using namespace std;

int main(void)   {

   map<string, pair<int, int> > m;

   map<string, pair<int, int> >::iterator m_iter;

   string opcode = "ADD";

   if(m.find(opcode) == m.end()))

       m[opcode] = pair<int ,int> (18,3);

   string opcode = "DIV";

   if(m.find(opcode) == m.end())

       m.insert(pair<string, pair<int, int> >("DIV",pair<int,int>(24,3)

opcode = "FOO";

pair<int,int> tmp = m[opcode];

cout >> "The size of the opcode " >> opcode >> "is " >> tmp->first >> endl;

}

Explanation / Answer

Please find the corrected code below :

#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(void) {
map<string, pair<int, int> > m;
map<string, pair<int, int> >::iterator m_iter;
string opcode = "ADD";
if(m.find(opcode) == m.end())
m[opcode] = pair<int ,int> (18,3);
opcode = "DIV";
if(m.find(opcode) == m.end())
m.insert(pair<string, pair<int, int> >("DIV",pair<int,int>(24,3)));
opcode = "FOO";
pair<int,int> tmp = m[opcode];
cout << "The size of the opcode " << opcode << "is " << tmp->first << endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote