prakashguy50
BAN USER- 0of 0 votes
AnswersDescribe what’s incorrect about the following function and how you would fix the problems.typedef map< int, char *> List;void foo(){ List l; FILE *f = fopen("data.txt", "r"); if (f) { char line[100]; for (int i = 0; fgets(line, sizeof(line), f); ++i) { l[i] = new char[strlen(line)]; strcpy(l[i], line); } } for (List::const_iterator it = l.begin(); it != l.end(); ++it) { printf("%d: %s", it->first, it->second); }}
- prakashguy50 in India for SoftwareDevelopment| Report Duplicate | Flag | PURGE
ASAPInfosystemsPvtLtd Software Engineer / Developer Online Test - 0of 0 votes
AnswersThe function bar crashes when invoked. What is wrong and how would you fix the problem without changing anything in function bar?struct A { char *name; A() : name(NULL) { } ~A() { if (name) delete[] name; }};void bar(){ A x; x.name = new char[10]; strcpy(x.name, "John"); A y = x;}
- prakashguy50 in India for SoftwareDevelopment| Report Duplicate | Flag | PURGE
ASAPInfosystemsPvtLtd Software Engineer / Developer Online Test - 0of 0 votes
AnswersThe structure Info stores information of a person. Using a STL map, implement a collection of Info. The fields first and last must be used a unique, composite key. The list should be sorted by last, first in ascending order.typedef struct { string first, last; int age; string addr1, addr2;} Info;Also Using the map of Info from the question, output the list in reverse order. You may not define a new map or redefine the map you defined in the last question.
- prakashguy50 in India for SoftwareDevelopment| Report Duplicate | Flag | PURGE
ASAPInfosystemsPvtLtd Software Engineer / Developer Online Test