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<

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
  1. 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

 

  1. Consider the following declaration:

      template     <class  type>                               

class strange                                       //Line 2

{

                  …

                  private :           type     a;

                                          type     b;

};

           

  1. 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.
  2. Write a statement that declares sObj that shows the declaration in the class strange to overload the operator = = as a member function.
  3. 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          

 

  1. 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?

  1. cout<<surprise(5, 7) <<endl;     
  2. string str1 = ‘Sunny”;

string  str2 = “ Day”;

cout<<surprise(str1, str2) <<endl;                 

 

  1. 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

  1. cout<<funcExp(sales,7)<<endl;
  2. cout<<funcExp(names, 6)<<endl;                                   

 

  1. Write the definition of the function template that swaps the content of two variables

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education