anuj.iiit2007
BAN USER- 0of 0 votes
AnswersWrite a method to create a deep-clone of an instance of the class Drawing.
- anuj.iiit2007 in United States
public class Drawing {
public List < Shape > shapes = new LinkList < Shape >();
}
where shape is an abstract class which can have many concrete implementation
public abstract class Shape implements Serailizable {
---
}| Report Duplicate | Flag | PURGE
Adobe - 0of 0 votes
AnswerWrite a method to create a deep-clone of an instance of the class Drawing.
- anuj.iiit2007 in United States
public class Drawing {
public List<Shape> shapes = new LinkedList<Shape>();
}
where shape is an abstract class that can have many concrete implementations:
public abstract class Shape implements Serializable {
}| Report Duplicate | Flag | PURGE
Adobe - 0of 0 votes
Answersfind least common ancestor in btree.
- anuj.iiit2007 in United States
Note:its btree not bst| Report Duplicate | Flag | PURGE
Zynga Algorithm - 0of 0 votes
Answersfind all broken links in a web page
- anuj.iiit2007 in United States| Report Duplicate | Flag | PURGE
Zynga - 0of 0 votes
Answershow to implement LRU for ecommerce site --> use linklist+map
- anuj.iiit2007 in United States| Report Duplicate | Flag | PURGE
Zynga - 0of 0 votes
AnswersHow will you store friend-to-friend relation of facebook in db
- anuj.iiit2007 in United States| Report Duplicate | Flag | PURGE
Zynga Database - 0of 0 votes
AnswersA stream of numbers of length not more than M will be given. You don't know the exact length of the stream but are sure that it wont exceed M. At the end of the stream, you have to tell the N/2 th element of the stream, considering that N elements came in the stream. what would be best space complexity with which you can solve this problem
- anuj.iiit2007 in United States| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
AnswersWrite a C program to display * for each letter of password you type in command line.
- anuj.iiit2007 in United States
Like:Password
********| Report Duplicate | Flag | PURGE
C - 0of 0 votes
Answers#include <iostream>
- anuj.iiit2007 in United States
class C {
private:
int num;
public:
C(int a) : num(a) {}
int get_val() const;
};
//changes are not allowed in below code
int C::get_val() const {
num++;
return num;
}
int main() {
C obj(29);
std::cout << obj.get_val() << std::endl;
}
The question was to make the above code work you can make changes only inside class C| Report Duplicate | Flag | PURGE
Microsoft C++ - 0of 0 votes
AnswersWrite a function in C/C++ that implements long2ip and ip2long in PHP.
- anuj.iiit2007 in United States| Report Duplicate | Flag | PURGE
- 0of 0 votes
AnswersWrite a function in C/C++ that implements long2ip and ip2long in PHP.
- anuj.iiit2007 in United States| Report Duplicate | Flag | PURGE
- 0of 0 votes
AnswersWrite a function to count the number of numbers between two 64 bit numbers a, b that have the sum of their bits equal to a fibonacci number. E.g Between 15 and 17 there are two numbers that have sum of bits equal to a fibonacci number.
- anuj.iiit2007 in United States| Report Duplicate | Flag | PURGE
- 0of 0 votes
AnswersYou have a library provided by the vendor. All you have is header files and library files.
- anuj.iiit2007 in United States
Library contains the class Shape and there is whole hierarchy tree (i mean classes which derive from this base class).
Now you want to add some function "getArea" (not originally present in the class or any of its derived class) in the class "Shape" , you dont have the source code.
Using this library, you have written a lot of code. Now you have to make some changes so that, any object of Shape class (or its derived class) will be able to call this function.
With your strategy, you should be able to override the definition of this function in the derived class.| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersYou have a list of coins of some denominations(d1<d2...<dk). You have unlimited supply of these coins. Find out the how can u make a sum S using minimum number of coins.
- anuj.iiit2007 in India
DP solution was required as he was not satisfied with greedy approach.| Report Duplicate | Flag | PURGE
Adobe - 0of 0 votes
AnswersQuestion DETERMINE THE OUTPUT R1,R2,R3 ARE THREE REGISTERS
- anuj.iiit2007 in United States
START :POP R1
POP R2
COMPARE R2,0
JUMP_EQ DONE_Z
PUSH R2
PUSH R1
SUBTRATCT R2,1
PUSH R2
CALL START
POP R3
POP R1
POP R2
MULTIPLY R3,R2
JUMP DONE
DONE_Z:MOVE R3,1
DONE:PUSH R3
PUSH R1
RETURN| Report Duplicate | Flag | PURGE
- 0of 0 votes
AnswersYou are given a function printKDistanceNodes which takes in a root node of a binary tree, a start node and an integer K. Complete the function to print the value of all the nodes (one-per-line) which are a K distance from the given start node in sorted order. Distance can be upwards or downwards.
- anuj.iiit2007 in India| Report Duplicate | Flag | PURGE
- 0of 0 votes
Answers//Error with the following code,can anyone correct the //following code for queue using two stack getting //compilation error in constructor
- anuj.iiit2007 in India
#include <cstdlib> // system definitions
#include <iostream> // I/O definitions
#include <fstream>
#include<string>
#include<stack>
#include<vector>
using namespace std; // make std:: accessible
using std::stack;
using std::string;
template<typename T>class Myqueue
{
stack<T> s1,s2;
public:
Myqueue(){
s1=new stack<T>();
s2=new stack<T>();
}
int size()
{
return s1.size()+s2.size();
}
void add(T value)
{
s1.push(value);
}
T peek()
{
if(!s2.empty())
return s2.peek();
while(!s1.empty())
s2.push(s1.pop());
return s2.peek();
}
T remove()
{
if(!s2.empty())
return s2.pop();
while(!s1.empty())
s2.push(s1.pop());
return s2.pop();
}
};
int main()
{
Myqueue<string> str;
/*str.Myqueue();*/
string str1;
str.add("devesh");
str.add("pankaj");
str1=str.peek();
return 0;
}| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test C++
- 2 Answers MICROSOFT WRITTEN
The code in the 'main' function tries to store some values inside a STL vector and also subsequently print them. But something is wrong in the usage of the STL vector. Fix it.
- anuj.iiit2007 October 11, 2012
#include <vector>
#include <iostream>
class A {
private:
int a;
public:
A(int x) : a(x) {}
void setVal(int x) { a = x; }
int getVal() { return a; }
};
int main() {
std::vector<A> arr(10);
for (int i = 9; i >= 0; i--) {
arr[i].setVal(20 + i);
}
for (int i = 0; i < 10; i++) {
std::cout << arr[i].getVal() << std::endl;
}| Flag | PURGE - 3 Answers C++ Microsoft question
The routine 'myfunc' is designed to throw an exception of type 'myExcep'. However it is being called from the 'main' function assuming that an exception of type 'derivedExcep' will be caught. Correct the code so that the exception thrown by the 'myfunc' function is caught and handled by the catch block in the 'main' function. The routine 'my_handler' should be helpful to you.
- anuj.iiit2007 October 02, 2012
#include <iostream>
#include <exception>
class myExcep {
public:
myExcep () {}
};
void myfunc() throw (myExcep) {
throw 0;
}
class derivedExcep : public myExcep {};
//changes allowed in below code only
void my_handler() throw (&derivedExcep) {
std::cout<< "hit the handler" << std::endl;
throw derivedExcep();
}
int main() {
try {
myfunc();
}
catch (derivedExcep & e) {
std::cout<<"caught exception gracefully"<< std::endl;
}
return 0;
}| Flag | PURGE
Can anyone tell what we need to make the changes in my_handler(
- anuj.iiit2007 October 02, 2012#include <iostream>
#include <exception>
class myExcep {
public:
myExcep () {}
};
void myfunc() throw (myExcep) {
throw 0;
}
class derivedExcep : public myExcep {};
void my_handler() throw (derivedExcep) {
std::cout<< "hit the handler" << std::endl;
throw derivedExcep();
}
int main() {
try {
myfunc();
}
catch (derivedExcep & e) {
std::cout<<"caught exception gracefully"<< std::endl;
}
return 0;
}
//some mistake was there in above code
#include <iostream>
#include <exception>
class myExcep {
public:
myExcep () {}
};
void myfunc() throw (myExcep) {
throw 0;
}
class derivedExcep : public myExcep {};
//changes allowed in below code only
void my_handler() throw (&derivedExcep) {
std::cout<< "hit the handler" << std::endl;
throw derivedExcep();
}
int main() {
try {
myfunc();
}
catch (derivedExcep & e) {
std::cout<<"caught exception gracefully"<< std::endl;
}
return 0;
}
Thanks, it works
one more question
The routine 'myfunc' is designed to throw an exception of type 'myExcep'. However it is being called from the 'main' function assuming that an exception of type 'derivedExcep' will be caught. Correct the code so that the exception thrown by the 'myfunc' function is caught and handled by the catch block in the 'main' function. The routine 'my_handler' should be helpful to you.
#include <iostream>
#include <exception>
class myExcep {
public:
myExcep () {}
};
void myfunc() throw (myExcep) {
throw 0;
}
class derivedExcep : public myExcep {};
//changes allowed in below code only
void my_handler() throw (&derivedExcep) {
std::cout<< "hit the handler" << std::endl;
throw derivedExcep();
}
int main() {
try {
myfunc();
}
catch (derivedExcep & e) {
std::cout<<"caught exception gracefully"<< std::endl;
}
return 0;
}
ya
- anuj.iiit2007 August 26, 2012#include <iostream>
#include <cstring>
#include <cstdlib>
#include<map>
#include<vector>
using namespace std;
int countBits(unsigned int nh )
{
unsigned int count = 0;
while(nh)
{
count += nh & 1;
nh >>= 1;
}
return count;
}
int presentInLookUpTable(int noOfBits)
{
map<int,int> fibonacci;
fibonacci[1]=1;
fibonacci[2]=1;
fibonacci[3]=1;
fibonacci[5]=1;
fibonacci[8]=1;
fibonacci[13]=1;
fibonacci[21]=1;
fibonacci[34]=1;
fibonacci[55]=1;
map<int,int>::iterator i = fibonacci.find(noOfBits);
if((*i).first)
return 1;
}
int main()
{
int nh,nl,noOfBits,j;
cin>>nh;
cout<<"\n";
cin>>nl;
while(nh!=nl)
{
int noOfBits = countBits(nh);
if(presentInLookUpTable(noOfBits))
{
cout<<nh;
}
nh--;
}
getchar();
return 0;
}
When both file links during execution extern int *myarray declaration in file2.c will search for *myarray declared and allocated space ,and that is done in file1.c myarray[10].So what exactly you are saying is *myarray will not match to myarray[].
- anuj.iiit2007 May 13, 2012When both file links during execution extern int *myarray declaration in file2.c will search for *myarray declared and allocated space ,and that is done in file1.c myarray[10].So what exactly you are saying is *myarray will not match to myarray[].
- anuj.iiit2007 May 13, 2012
yes,we can use 2 string but how will you replace the character typed in command line with second string characters.
- anuj.iiit2007 October 17, 2012Suppose when you typed 'P' it should be shown as '*'.can you give implementation.