1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
MAVERICK [17]
3 years ago
6

C++ You are asked to implement two function templates and a class template.

Computers and Technology
1 answer:
Alex777 [14]3 years ago
6 0

Answer:

Check the explanation

Explanation:

//templateFunctions.h file

#ifndef TEMPLATEFUNCTIONS_H

#define TEMPLATEFUNCTIONS_H

#include <iostream>

using namespace std;

#include "templateClass.h"

//FIX ME: Complete the header of the function template findMax()

// This function takes the array of any type as input and return its maximum value

template <typename T>

T findMax(const T arr[], int nelems)

{

  T max = arr[0];

  for (int i = 1; i < nelems; i++)

  {

      if (arr[i] > max)

          max = arr[i];

  }

  return max;

}

//

// FIX ME: Implement the swapPairObjs() function that swaps the two objects of MyPair

template<typename T1, typename T2>

void swapPairObjs(MyPair<T1,T2>& object1, MyPair<T1,T2>& object2)

{

   T1 temp1_left=object1.getLeft(),temp2_left=object2.getLeft();

   T2 temp1_right=object1.getRight(),temp2_right=object2.getRight();

   object1.setLeft(temp2_left);

   object2.setLeft(temp1_left);

   object1.setRight(temp2_right);

   object2.setRight(temp1_right);

}

#endif

//templateClass.h file

#ifndef MYPAIR_H

#define MYPAIR_H

// FIX ME: please provide the proper template prefix for the MyPair class template

template <typename T1, typename T2>

class MyPair {

public:

  MyPair(T1 _left, T2 _right);

  T1 getLeft();

  T2 getRight();

  void setLeft(T1 _left);

  void setRight(T2 _right);

private:

  T1 left;

  T2 right;

};

//FIX ME: Complete the definition of the constructor MyPair(T1 _left, T2 _right)

// that will assign value _left to the left variable and _right to right.

template<typename T1, typename T2>

MyPair<T1,T2>::MyPair(T1 _left, T2 _right)

{

   left=_left;

   right=_right;

}

//FIX ME: Complete the definition of the getLeft() function

template<typename T1, typename T2>

T1 MyPair<T1,T2>::getLeft()

{

   return left;

}

//FIX ME: Complete the definition of the setLeft() function

template<typename T1, typename T2>

void MyPair<T1,T2>::setLeft(T1 _left)

{

   left=_left;

}

//FIX ME: Complete the definition of the getRight() function

template<typename T1, typename T2>

T2 MyPair<T1,T2>::getRight()

{

   return right;

}

//FIX ME: Complete the definition of the setRight() function

template<typename T1, typename T2>

void MyPair<T1,T2>::setRight(T2 _right)

{

   right=_right;

}

#endif // !MYPAIR_H

Working of codes:

findMax()

You might be interested in
Is a free verse a poetry that has no images
hram777 [196]
No it just means that it does not have any specific rhymes or formats
3 0
3 years ago
Read 2 more answers
What is Accenture's role in Multi-party Systems?
Maslowich

Answer:

helping a single company develop a data ingress platform

Explanation:

Accenture's role in Multi-party Systems is "helping a single company develop a data ingress platform."

This is evident in the fact that Accenture formed a strategic alliance with Marco Polo Network in recent times. The purpose of the alliance is to create a single data ingress platform for many connections. That is those on the network can easily install, either on-prem or through the cloud such as the Marco Polo platform, and then later incorporates the data into the enterprise resource planning system.

7 0
3 years ago
You are assigned by your teacher to perform the assembly of all the parts of the computer in preparation for the hands on activi
Alexus [3.1K]

Answer:

answer it yourself or ask your teacker

Explanation:

7 0
3 years ago
2. Sherry bought the following articles
sineoko [7]

Answer:

Total amount paid → $3525

Explanation:

       Articles                  unit rate               Quantity              Total amount

1). Banarasi sarees         $1500                      2                          $3000

2). Shirting                      $30                          8                          $240

3). Bed sheets                $40.50                    2                           $81

4). Cloth                          $20.25                    8                           $162

5). Handkerchiefs          $3.50                       12                         $42

                                                                                      Total → $3525      

Therefore, total amount paid to purchase the articles given is $3525.        

8 0
3 years ago
Windows stores files on a hard drive in 512-byte blocks called
Tanzania [10]
Hey 

l think what u are thinking of is a disk
5 0
4 years ago
Other questions:
  • The process of converting information, such as text, numbers, photos, or music, into digital data that can be manipulated by ele
    7·1 answer
  • What are two characteristics of a scalable network? (choose two.)?
    5·1 answer
  • Help me please............
    6·2 answers
  • Alicia created this list: set goals, establish a reward system, maintain a positive outlook, avoid burnout. What is the best exp
    8·2 answers
  • Write a program that prompts the user for an integer and then prints all prime numbers up to that integer.
    7·1 answer
  • Should the federal government have bug bounty programs? Why or why not?
    9·2 answers
  • Which of the following is most likely to require use of a server, desktop, and industry-specific handheld computer, and is most
    8·1 answer
  • A ______ uses a web address to locate a website or a web page.
    9·1 answer
  • Write a line of code that declares a variable called shipName and set it equal to the string SpaceX3000.
    9·1 answer
  • It displays the contents of the active cell. It allows you to enter and edit data, such as formulas.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!