Upwork C++ PROGRAMMING TEST 2016

Hello Freelancer, Welcome to allupworktestanswers.com Here to get the C++ PROGRAMMING TEST of Latest version 2016. We are ready here to provide your desire upwork test answer. We already tested all exam test information Available include on here. So Dear, Why Late? Read the below full exam test and get more information from our website. 

1. Consider the following class hierarchy:
class Base

{
}
class Derived : public Base
{
}
Which of the following are true?
Answers:
  1. The relationship between the Base and Derived can be described as: Base is a Derived
  2. The relationship between the Base and Derived can be described as: Base has a Derived
  3. Derived can access only public member functions of Base
  4. Derived can access public and protected member functions of Base
  5. 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:
  1. void fun(int, char *) void fun(char *,int)
  2. void x(int,char) int *x(int,char)
  3. int get(int) int get(int,int)
  4. void F(int *) void F(float *)
  5. 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:
  1. 4
  2. 7
  3. 8
  4. 14
  5. 19
4. Which of the following statements about function overloading, is true?
Answers:
  1. C++ and namespaces should be used to replace occurrences of function overloading
  2. Overloaded functions may not be declared as “inline”
  3. Although the return types and parameter types of overloaded functions can be different, the actual number of parameters cannot change
  4. Function overloading is possible in both C and C++
  5. 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:
  1. Object objShape of Shape class will be created
  2. A compile time error will be generated because you cannot declare Shape objects
  3. A compile time error will be generated because you cannot call draw function of class ‘Shape’
  4. A compile time error will be generated because the derived class’s draw() function cannot override the base class draw() function
  5. 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:
  1. To make it impossible for this particular destructor to be overloaded
  2. To ensure that correct destructor is called when p is deleted
  3. To ensure that the destructors are called in proper orde
  4. To improve the speed of class Person’s destruction
  5. 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:
  1. extern “C”
  2. extern C
  3. _stdcall
  4. _cdecl
  5. _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:
  1. Public
  2. Private
  3. Protected
  4. Friend
  5. 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:
  1. Person(string sName);
  2. Person(string sName, int nAge);
  3. Copy(Person *p);
  4. Person(const Person &p);
  5. Copy(const Person &p)?
10. Which of the following member functions can be used to add an element in an std::vector?
Answers:
  1. add
  2. front
  3. push
  4. 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:
  1. monthTable(winter,spring={“March”,”April”,”May”});
  2. monthTable winter, spring;
  3. monthTable, winter, spring;
  4. monthTable, winter,spring={“March”,”April”,”May”};
  5. monthTable winter,spring={“March”,”April”,”May”};
12. Which of the following are NOT valid C++ casts
Answers:
  1. dynamic_cast
  2. einterpret_cast
  3. static_cast
  4. const_cast
  5. 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:
  1. font size=2>foo = new *char[200];</font
  2. font size=2>foo = new char[200];</font
  3. font size=2>foo = new char[200]*;</font
  4. font size=2>foo = new char*[200];</font
  5. 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:
  1. Incorrect syntax. The body of the class declaration is missing
  2. Incorrect syntax. {}; is missing
  3. The syntax is correct
  4. Incorrect syntax. {} is missing
  5. Incorrect syntax. Requires a *
15. Which of the following are true about class member functions and constructors?
Answers:
  1. A constructor can return values but a member function cannot
  2. A member function can declare local variables but a constructor cannot
  3. A member function can return values but a constructor cannot
  4. A constructor can declare local variables but a member function cannot
  5. 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:
  1. 4
  2. 5
  3. 6
  4. 7
  5. 8
  6. 9
  7. 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:
  1. private
  2. protected
  3. default
  4. virtual
  5. 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:
  1. 10
  2. 11
  3. 25
  4. 13
  5. 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:
  1. 11,9
  2. 9,10
  3. 12,10
  4. 11,10
20. If input and output operations have to be performed on a file, an object of the _______ class should be created.
Answers:
  1. fstream
  2. iostream
  3. ostream
  4. istream
  5. 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:
  1. Yes, it is valid
  2. No, we cannot assign values like this
  3. No, the parenthesis cannot be empty
  4. 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:
  1. A non-template member function
  2. A template function definition
  3. A template function declaration
  4. A template class definition
  5. A template class declaration
23. Which of the following statements regarding functions are false?
Answers:
  1. Functions can be overloaded
  2. Functions can return the type void
  3. Inline functions are expanded during compile time to avoid invocation overhead
  4. You can create arrays of functions
  5. You can pass values to functions by reference arguments
  6. You can return values from functions by reference arguments
  7. A function can return a pointe
24. What does ADT stand for?
Answers:
  1. Accessible derived type
  2. Access to derived type
  3. Abstract data type
  4. Abstract derived type
  5. Accessible data type
25. Consider the following code:
#include<iostream>
using namespace std;
class A
{
public :
A()
{
cout << “Constructor of An”;
};
~A()
{
cout << “Destructor of An”;
};
};
class B : public A
{
public :
B()
{
cout << “Constructor of Bn”;
};
~B()
{
cout << “Destructor of Bn”;
};
};
int main()
{
B *pB;
pB = new B();
delete pB;
return 0;
}
What will be the printed output?
Answers:
  1. Constructor of B Constructor of A Destructor of A Destructor of B
  2. Constructor of A Constructor of B Destructor of B Destructor of A
  3. Constructor of B Constructor of A Destructor of B Destructor of A
  4. Constructor of A Constructor of B Destructor of A Destructor of B
  5. 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:
  1. Code will Crash or Throw and Exception
  2. Code will Execute, but there will be a memory leak
  3. Code will execute properly
  4. 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:
  1. All are true
  2. Only 1, 2 and 4 are true
  3. Only 1 and 2 are true
  4. Only 1,3 and 4 are true
  5. 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:
  1. Base Base
  2. Base Derived
  3. Derived Base
  4. 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:
  1. A::I A::f() { return 0; }
  2. A::I g(A::I p = A::x);
  3. A::I g(A::I p) { return 0; }
  4. 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:
  1. The compilation will fail with the error – ‘__LINE__’ : undeclared identifie
  2. The compilation will fail with the error – ‘__LINE__’ unresolved identifie
  3. The code will compile and run without errors
  4. The code will crash at runtime
31. Which of the following STL classes is deprecated (i.e. should no longer be used)?
Answers:
  1. ostrstream
  2. ostringstream
  3. ostream
  4. wostream


Finally no more words require about the C++ PROGRAMMING TEST  information in this session of this content. If you are require knowing more, Please ask to us via our contact us form or comment box. Please make sure that, you don’t send Personal information via the Comment box.  Thank you very mutch for being with us.

0 comments: