Adobe Interview Question


Country: India




Comment hidden because of low score. Click to expand.
0
of 0 vote

//Json object using composite pattern
class IJsonObject {
public:
virtual void print() = 0;
};

class IJsonObjects : public IJsonObject {
public:
vector<IJsonObject*> objects;
string str_key;

IJsonObjects() : str_key("") {

}

IJsonObjects(string str) : str_key(str) {

}

void print() {
if (str_key.length() > 0) {
cout << "\"" << str_key << "\" : {";
}
for (auto elem : objects) {
elem->print();
}
if (str_key.length() > 0) {
cout << "}";
}
}
};

class IJsonInt : public IJsonObject {
public:
int val;
string str_key;
IJsonInt(string str, int v) : str_key(str), val(v) {
}

void print() {
cout << "\"" << str_key << "\" : " << val << endl;
}

};

class IJsonStr : public IJsonObject {
public:
string str_val;
string str_key;
IJsonStr(string str, string v) : str_key(str), str_val(v) {
}

void print() {
cout << "\"" << str_key << "\" : \"" << str_val << "\"" << endl;
}

};

void process_json_str() {
cout << "\n\n Json block: " << endl;
IJsonObjects* json_root = new IJsonObjects;
IJsonObject * json_obj1 = new IJsonInt { "version", 10 };
json_root->objects.push_back(json_obj1);
IJsonObject* json_obj2 = new IJsonStr{ "OS", "Windows 10" };
IJsonObject* json_obj3 = new IJsonInt{ "Build number", 6093 };
json_root->objects.push_back(json_obj2);
json_root->objects.push_back(json_obj3);

IJsonObjects* json_subroot = new IJsonObjects{"Customer Details"};
IJsonObject* json_obj4 = new IJsonInt{ "Age", 30 };
IJsonObject* json_obj5 = new IJsonStr{ "name", "Kunal" };
json_subroot->objects.push_back(json_obj4);
json_subroot->objects.push_back(json_obj5);
json_root->objects.push_back(json_subroot);

IJsonObjects* json_subroot2 = new IJsonObjects{ "Contract Details" };
IJsonObject* json_obj6 = new IJsonInt{ "Cost per licence", 15 };
IJsonObject* json_obj7 = new IJsonStr{ "Licence", "3 Years" };
json_subroot2->objects.push_back(json_obj6);
json_subroot2->objects.push_back(json_obj7);
json_subroot->objects.push_back(json_subroot2);

json_root->print();
return;
}

- Kunal Bansal September 30, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//Json object using composite pattern
class IJsonObject {
public:
virtual void print() = 0;
};

class IJsonObjects : public IJsonObject {
public:
vector<IJsonObject*> objects;
string str_key;

IJsonObjects() : str_key("") {

}

IJsonObjects(string str) : str_key(str) {

}

void print() {
if (str_key.length() > 0) {
cout << "\"" << str_key << "\" : {";
}
for (auto elem : objects) {
elem->print();
}
if (str_key.length() > 0) {
cout << "}";
}
}
};

class IJsonInt : public IJsonObject {
public:
int val;
string str_key;
IJsonInt(string str, int v) : str_key(str), val(v) {
}

void print() {
cout << "\"" << str_key << "\" : " << val << endl;
}

};

class IJsonStr : public IJsonObject {
public:
string str_val;
string str_key;
IJsonStr(string str, string v) : str_key(str), str_val(v) {
}

void print() {
cout << "\"" << str_key << "\" : \"" << str_val << "\"" << endl;
}

};

void process_json_str() {
cout << "\n\n Json block: " << endl;
IJsonObjects* json_root = new IJsonObjects;
IJsonObject * json_obj1 = new IJsonInt { "version", 10 };
json_root->objects.push_back(json_obj1);
IJsonObject* json_obj2 = new IJsonStr{ "OS", "Windows 10" };
IJsonObject* json_obj3 = new IJsonInt{ "Build number", 6093 };
json_root->objects.push_back(json_obj2);
json_root->objects.push_back(json_obj3);

IJsonObjects* json_subroot = new IJsonObjects{"Customer Details"};
IJsonObject* json_obj4 = new IJsonInt{ "Age", 30 };
IJsonObject* json_obj5 = new IJsonStr{ "name", "Kunal" };
json_subroot->objects.push_back(json_obj4);
json_subroot->objects.push_back(json_obj5);
json_root->objects.push_back(json_subroot);

IJsonObjects* json_subroot2 = new IJsonObjects{ "Contract Details" };
IJsonObject* json_obj6 = new IJsonInt{ "Cost per licence", 15 };
IJsonObject* json_obj7 = new IJsonStr{ "Licence", "3 Years" };
json_subroot2->objects.push_back(json_obj6);
json_subroot2->objects.push_back(json_obj7);
json_subroot->objects.push_back(json_subroot2);

json_root->print();
return;
}

- Kunal Bansal September 30, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//Json object using composite pattern
class IJsonObject {
public:
virtual void print() = 0;
};

class IJsonObjects : public IJsonObject {

string str_key;
string str_indent;
public:
vector<IJsonObject*> objects;

IJsonObjects() : str_key("") , str_indent("") {
}

IJsonObjects(string str) : str_key(str), str_indent(" ") {
}

void print() {
if (str_key.length() > 0) {
cout << str_indent << "\"" << str_key << "\" : {";
}
for (auto elem : objects) {
cout << str_indent;
elem->print();
}
if (str_key.length() > 0) {
cout << str_indent << "}" << endl;
}
}
};

class IJsonInt : public IJsonObject {
public:
int val;
string str_key;
IJsonInt(string str, int v) : str_key(str), val(v) {
}

void print() {
cout << "\"" << str_key << "\" : " << val << endl;
}

};

class IJsonStr : public IJsonObject {
public:
string str_val;
string str_key;
IJsonStr(string str, string v) : str_key(str), str_val(v) {
}

void print() {
cout << "\"" << str_key << "\" : \"" << str_val << "\"" << endl;
}

};

void process_json_str() {
cout << "\n\n Json block: " << endl;
IJsonObjects* json_root = new IJsonObjects;
IJsonObject * json_obj1 = new IJsonInt { "version", 10 };
json_root->objects.push_back(json_obj1);
IJsonObject* json_obj2 = new IJsonStr{ "OS", "Windows 10" };
IJsonObject* json_obj3 = new IJsonInt{ "Build number", 6093 };
json_root->objects.push_back(json_obj2);
json_root->objects.push_back(json_obj3);

IJsonObjects* json_subroot = new IJsonObjects{"Customer Details"};
IJsonObject* json_obj4 = new IJsonInt{ "Age", 30 };
IJsonObject* json_obj5 = new IJsonStr{ "name", "Kunal" };
json_subroot->objects.push_back(json_obj4);
json_subroot->objects.push_back(json_obj5);
json_root->objects.push_back(json_subroot);

IJsonObjects* json_subroot2 = new IJsonObjects{ "Contract Details" };
IJsonObject* json_obj6 = new IJsonInt{ "Cost per licence", 15 };
IJsonObject* json_obj7 = new IJsonStr{ "Licence", "3 Years" };
json_subroot2->objects.push_back(json_obj6);
json_subroot2->objects.push_back(json_obj7);
json_subroot->objects.push_back(json_subroot2);

json_root->print();
return;
}

- kbkunalb October 01, 2020 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More