Skip to main content

C++ Programming Test Upwork Answers 2019

1. Consider the following class hierarchy:


class Base

{

}


class Derived : public Base

{

}


Which of the following are true?
Answers: 
• The relationship between the Base and Derived can be described as: Base is a Derived
• The relationship between the Base and Derived can be described as: Base has a Derived
• Derived can access only public member functions of Base
• Derived can access public and protected member functions of Base
• The following line of code is valid: Base *object = new Derived();
2. Which of the following sets of functions do not qualify as overloaded functions?
Answers: 
• void fun(int, char *) void fun(char *,int)
• void x(int,char) int *x(int,char)
• int get(int) int get(int,int)
• void F(int *) void F(float *)
• All of the above are overloaded functions
3. Consider the sample code given below and answer the question that follows.


1  class Car

2  {

3  private:

4  int Wheels;

5  

6  public:

7  Car(int wheels = 0)

8  : Wheels(wheels)

9  {

10 }

11

12 int GetWheels()

13 {

14 return Wheels;

15 }

16 };

17 main()

18 {

19 Car c(4);

20 cout << "No of wheels:" << c.GetWheels();

21 }


Which of the following lines from the sample code above are examples of data member definition?
Answers: 
• 4
• 7
• 8
• 14
• 19
4. Which of the following statements about function overloading, is true?
Answers: 
• C++ and namespaces should be used to replace occurrences of function overloading
• Overloaded functions may not be declared as "inline"
• Although the return types and parameter types of overloaded functions can be different, the actual number of parameters cannot change
• Function overloading is possible in both C and C++
• The parameter lists and const keyword are used to distinguish functions of the same name declared in the same scope
5. Consider the sample code given below and answer the question that follows.
class Shape
{
public:
virtual void draw() = 0;
};

class Rectangle: public Shape
{
public:
void draw()
{
// Code to draw rectangle
}
//Some more member functions.....
};

class Circle : public Shape
{
public:
void draw()
{
// Code to draw circle
}
//Some more member functions.....
};

int main()
{
Shape objShape;
objShape.draw();
}
What happens if the above program is compiled and executed?
Answers: 
• Object objShape of Shape class will be created
• A compile time error will be generated because you cannot declare Shape objects
• A compile time error will be generated because you cannot call draw function of class 'Shape'
• A compile time error will be generated because the derived class's draw() function cannot override the base class draw() function
• None of the above
6. Consider the sample code given below and answer the question that follows.


class Person 

{

public:

   Person();

      virtual ~Person();

};

class Student : public Person

{

public:

   Student();

   ~Student();

};


main()

{

   Person *p = new Student();

   delete p;

}


Why is the keyword "virtual" added before the Person destructor?
Answers: 
• To make it impossible for this particular destructor to be overloaded
• To ensure that correct destructor is called when p is deleted
• To ensure that the destructors are called in proper orde
• To improve the speed of class Person's destruction
• To prevent the Person class from being instantiated directly making it an abstract base class
7. What linkage specifier do you use in order to cause your C++ functions to have C linkage
Answers: 
• extern "C"
• extern C
• _stdcall
• _cdecl
• _fastcall?
8. You want the data member of a class to be accessed only by itself and by the class derived from it. Which access specifier will you give to the data member?
Answers: 
• Public
• Private
• Protected
• Friend
• Either Public or Friend
9. Consider the sample code given below and answer the question that follows.


class Person 

{

    string name;

    int age;

    Person *spouse;

public:

    Person(string sName);

    Person(string sName, int nAge);

    Person(const Person& p);


    Copy(Person *p);

    Copy(const Person &p);

    SetSpouse(Person *s);

};


Which one of the following are declarations for a copy constructor?
Answers: 
• Person(string sName);
• Person(string sName, int nAge);
• Copy(Person *p);
• Person(const Person &p);
• Copy(const Person &p)?
10. Which of the following member functions can be used to add an element in an std::vector?
Answers: 
• add
• front
• push
• push_back
11. Sample Code


typedef char *monthTable[3];


Referring to the code above, which of the following choices creates two monthTable arrays and initializes one of the two?
Answers: 
• monthTable(winter,spring={"March","April","May"});
• monthTable winter, spring;
• monthTable, winter, spring;
• monthTable, winter,spring={"March","April","May"};
• monthTable winter,spring={"March","April","May"};
12. Which of the following are NOT valid C++ casts
Answers: 
• dynamic_cast
• einterpret_cast
• static_cast
• const_cast
• void_cast
13. Consider the sample code given below and answer the question that follows:


<font size=2>
     char **foo; 
    /* Missing code goes here */ 
    for(int i = 0; i < 200; i++) 
    { 
        foo[i] = new char[100]; 
    }  

Referring to the sample code above, what is the missing line of code?  
</font
Answers: 
• font size=2>foo = new *char[200];</font
• font size=2>foo = new char[200];</font
• font size=2>foo = new char[200]*;</font
• font size=2>foo = new char*[200];</font
• font size=2>foo = new char[][200];</font
14. Consider the line of code given below and answer the question that follows.

class screen;  

Which of the following statements are true about the class declaration above?
Answers: 
• Incorrect syntax. The body of the class declaration is missing
• Incorrect syntax. {}; is missing
• The syntax is correct
• Incorrect syntax. {} is missing
• Incorrect syntax. Requires a *
15. Which of the following are true about class member functions and constructors?
Answers: 
• A constructor can return values but a member function cannot
• A member function can declare local variables but a constructor cannot
• A member function can return values but a constructor cannot
• A constructor can declare local variables but a member function cannot
• A member function can throw exceptions but a constructor cannot
16. Consider the following code:


#include<stdio.h>


int main(int argc, char* argv[])
{
        enum Colors 
        {
                red,
                blue,
                white = 5,
                yellow,
                green,
                pink
        };

        Colors color = green;
        printf("%d", color);
        return 0;
}

What will be the output when the above code is compiled and executed?
Answers: 
• 4
• 5
• 6
• 7
• 8
• 9
• The code will have compile time errors
17. What access specifier allows only the class or a derived class to access a data membe
Answers: 
• private
• protected
• default
• virtual
• public
18. Consider the following code:

#define SQ(a) (a*a)

int  answer = SQ(2 + 3);

What will be the value of answer after the above code executes?
Answers: 
• 10
• 11
• 25
• 13
• None of the above
19. What is the output of the following code segment?

int n = 9;

int *p;

p=&n;

n++;

cout << *p+2 << "," << n;
Answers: 
• 11,9
• 9,10
• 12,10
• 11,10
20. If input and output operations have to be performed on a file, an object of the _______ class should be created.
Answers: 
• fstream
• iostream
• ostream
• istream
• None
21. In the given sample Code, is the constructor definition valid?


class someclass

{

   int var1, var2;

   public:

      someclass(int num1, int num2) : var1(num1), var2(num2)

      {

      }

};
Answers: 
• Yes, it is valid
• No, we cannot assign values like this
• No, the parenthesis cannot be empty
• No, var1 and var2 are not functions but are variables
22. Consider the sample code given below and answer the question that follows.


template <class T> Run(T process);


Which one of the following is an example of the sample code given above?
Answers: 
• A non-template member function
• A template function definition
• A template function declaration
• A template class definition
• A template class declaration
23. Which of the following statements regarding functions are false?
Answers: 
• Functions can be overloaded
• Functions can return the type void
• Inline functions are expanded during compile time to avoid invocation overhead
• You can create arrays of functions
• You can pass values to functions by reference arguments
• You can return values from functions by reference arguments
• A function can return a pointe
24. What does ADT stand for?
Answers: 
• Accessible derived type
• Access to derived type
• Abstract data type
• Abstract derived type
• Accessible data type
25. Consider the following code:


#include<iostream>

using namespace std;


class A
{
public :

        A()

        {

                cout << "Constructor of A\n";

        };

        ~A()

        {

                cout << "Destructor of A\n";

        };

};


class B : public A

{
public :

        B()

        {

                cout << "Constructor of B\n";

        };

        ~B()

        {

                cout << "Destructor of B\n";

        };

};


int main()
{

        B        *pB;

        pB = new B();

        delete pB;

        return 0;

}


What will be the printed output?
Answers: 
• Constructor of B Constructor of A Destructor of A Destructor of B
• Constructor of A Constructor of B Destructor of B Destructor of A
• Constructor of B Constructor of A Destructor of B Destructor of A
• Constructor of A Constructor of B Destructor of A Destructor of B
• The sequence of construction and destruction of A and B will be compiler specific
26. Consider the following code:
<font size=2>
template<class T> void Kill(T *& objPtr)
{
   delete objPtr;
   objPtr = NULL;
}

class MyClass
{
};

void Test()
{
   MyClass *ptr = new MyClass();
   Kill(ptr);
   Kill(ptr);
} 
</font>
Invoking Test() will cause which of the following?
Answers: 
• Code will Crash or Throw and Exception
• Code will Execute, but there will be a memory leak
• Code will execute properly
• Code will exhibit undefined behavio
27. Consider the following statements relating to static member functions and choose the appropriate options:

1. They have external linkage
2. They do not have 'this' pointers
3. They can be declared as virtual
4. They can have the same name as a non-static function that has the same argument types
Answers: 
• All are true
• Only 1, 2 and 4 are true
• Only 1 and 2 are true
• Only 1,3 and 4 are true
• All are false
28. What will be the output of the following code?

class b

{
    int i;

    public:

    virtual void vfoo()

  {

    cout <<"Base ";

  }

};

class d1 : public b

{

    int j;

    public:

    void vfoo()

  {

    j++;

    cout <<"Derived";

  }

};

class d2 : public d1

{

    int k;

};

void main()

{

    b *p, ob;

    d2 ob2;

    p = &ob;

    p->vfoo();

    p = &ob2;

    p->vfoo();

}
Answers: 
• Base Base
• Base Derived
• Derived Base
• Derived Derived
29. Consider the following code:
    class A {
          typedef int I;      // private member
          I f();
          friend I g(I);
          static I x;
      };
Which of the following are valid:
Answers: 
• A::I A::f() { return 0; }
• A::I g(A::I p = A::x);
• A::I g(A::I p) { return 0; }
• A::I A::x = 0;
30. Consider the following code:


#include<iostream>

using namespace std;


int main()
{

cout << "The value of __LINE__  is " <<__LINE__;


return 0;

}


What will be the result when the above code is compiled and executed?
Answers: 
• The compilation will fail with the error - '__LINE__' : undeclared identifie
• The compilation will fail with the error - '__LINE__' unresolved identifie
• The code will compile and run without errors
• The code will crash at runtime
31. Which of the following STL classes is deprecated (i.e. should no longer be used)?
Answers: 
• ostrstream
• ostringstream
• ostream
• wostream

Comments

  1. Great work! Thanks to Admin for Sharing the list of Upwork bootstrap answer Sites.
    This list will Surely help many of us. I Bookmarked and Shared your Link.
    and Bootstrap
    And also good site for Article Writers

    ReplyDelete
  2. Answer to question 6 seems to be incorrect. Proper one is "To ensure that correct destructor is called when p is deleted"

    ReplyDelete

Post a Comment

Popular posts from this blog

English Spelling Test (U.S. Version) Upwork Answers Test 2019

1 . Complete the following sentence by choosing the correct spelling of the missing word. Their relationship was plagued by _______ problems. Perpetual   —- it means: continuing for ever in the same way, often repeated Perpechual Purpetual Perptual 2.  Complete the following sentence by choosing the correct spelling of the missing word. The crowd _________ me on my acceptance into Mensa Congradulated Congrachulated Congratulated  —- it mean: to praise someone Congratilated English Spelling Test (U.S. Version) Answer;Upwork English test answer; Upwork English test answer 2017; lastest Upwork English test answer; upwork test answer;  3. Choose the correct spelling of the word from the options below. Goverment Governmant Government  — the group of people who officially control a country Govermant 4. Choose the correct spelling of the word from the options below. Temperamental ...

Office Skills Test Upwork Test Answers 2019

Question:* Your computer is not printing and a technician is not available, so you perform the following activities to investigate the problem. In which order should you take these up? 1 See if the printer cartridge is finished 2 See if the printer is switched on 3 Try to print a test page using the printer self-test 4 Try to print a test page from Windows 5 See if the printer is properly attached to the computer Answer: • 2,3,1,5,4 Question:* What is 'flexi-time'? Answer: • The flexible use of personal office hours, such as working an hour earlier one day, in order to leave an hour earlier another day. Question:* Which of the following are proven methods of improving your office skills? Answer: • All of the above Question:* When replying to an e-mail, who do you place in the cc: line and who in the bcc: line? Answer: • A person you wish to openly inform goes in the cc: line, and the person you wish to read the e-mail without the knowledge of the rec...

Python Test Answers Upwork 2019

1. Which of the following will disable output buffering in Python? Answers: a. Using the -u command line switch a. class Unbuffered: def __init__(self, stream): self.stream = stream def write(self, data): self.stream.write(data) self.stream.flush() def __getattr__(self, attr): return getattr(self.stream, attr) import sys sys.stdout=Unbuffered(sys.stdout)  a. Setting the PYTHONUNBUFFERED environment variable a. sys.stdout = os.fdopen(sys.stdout.fileno(), ‘w’, 0) 2. Which of the following members of the object class compare two parameters? Answers: a. object.__eq__(self, other)  a. object.__ne__(self, other)  a. object.__compare__(self, other) a. object.__equals__(self, other) a. object.__co__(self, other) a. None of these 3. Object is the base class of new-style datatypes. Which of the following functions is not a member of the object class? Answers: a. object.__eq__(self, other) a. object.__ne__(self, other) a. object.__nz__(self)  a. object.__repr__(self) a. None ...