Find the error (s) in the following code: template //Line 1 class strange //Line 2 { … }; strange s1 //Line 3 strange s2 //Line 4 Consider the following declaration: template class strange //Line 2 { … private : type a; type b; }; Write a statement that declars sObj to be an object of type strange such that the private member variables a and b are of type int. Write a statement that declares sObj that shows the declaration in the class strange to overload the operator = = as a member function. Assume that two objects of type strange are equal if their corresponding member variables are equal. Write the definition of the function operator == for the class strange, which is overloaded as member function Consider the definition of the following statement template Type surprise (Type x , Type y) { return x+y; } What is the output of following statements? cout< type funcExp (type list[ ] ,int size) { type x = list[0]; type y = list [ size-1]; for(int j = 1; j list [size – 1-j]) y = list [size – 1-j]; } return x+y; } Further suppose that you have the following declaration: double sales[7] = {280.50, 320.00, 56.00, 78.90, 300.00, 100.00, 250.00}; string names[] = {“Mike”, “Lisa”, “Nancy”, “Robinson”, “Miller”, “Sam”}; What is the output of the following statements cout<
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
- Find the error (s) in the following code:
template <class type> //Line 1
class strange //Line 2
{
…
};
strange <int> s1 //Line 3
strange <type> s2 //Line 4
- Consider the following declaration:
template <class type>
class strange //Line 2
{
…
private : type a;
type b;
};
- Write a statement that declars sObj to be an object of type strange such that the private member variables a and b are of type int.
- Write a statement that declares sObj that shows the declaration in the class strange to overload the operator = = as a member function.
- Assume that two objects of type strange are equal if their corresponding member variables are equal. Write the definition of the function operator == for the class strange, which is overloaded as member function
- Consider the definition of the following statement
template <class Type>
Type surprise (Type x , Type y)
{
return x+y;
}
What is the output of following statements?
- cout<<surprise(5, 7) <<endl;
- string str1 = ‘Sunny”;
string str2 = “ Day”;
cout<<surprise(str1, str2) <<endl;
- Consider the following definition of the following function template:
template <class type>
type funcExp (type list[ ] ,int size)
{ type x = list[0];
type y = list [ size-1];
for(int j = 1; j <size – 1; j++)
{ if (x < list [j])
x = list [j];
if (y>list [size – 1-j])
y = list [size – 1-j];
}
return x+y;
}
Further suppose that you have the following declaration:
double sales[7] = {280.50, 320.00, 56.00, 78.90, 300.00, 100.00, 250.00};
string names[] = {“Mike”, “Lisa”, “Nancy”, “Robinson”, “Miller”, “Sam”};
What is the output of the following statements
- cout<<funcExp(sales,7)<<endl;
- cout<<funcExp(names, 6)<<endl;
- Write the definition of the function template that swaps the content of two variables
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images