The required code is slightly modified as per the requirements of the question in case of any doubts you can ask me in comments
Main.cpp
#include <iostream>
using namespace std;
template<class T>
class calc
{
T a;
T b;
public:
calc(T x,T y)
{
a = x;
b = y;
}
T add();
T subtraction();
T multiply();
T division();
void printResult(T val);
};
template<class T>
T calc<T>::add()
{
return (a+b);
}
template<class T>
T calc<T>::subtraction()
{
return (a-b);
}
template<class T>
T calc<T>::multiply()
{
return (a*b);
}
template<class T>
T calc<T>::division()
{
return (a/b);
}
template<class T>
void calc<T>::printResult(T val)
{
cout <<val<<endl;
}
int main()
{
calc<int>a(10,5);
calc<double>b(3.4,5.5);
// a
cout<<"Addition : ";a.printResult(a.add());
cout<<"Subtraction : ";a.printResult(a.subtraction());
cout<<"Multiplication : ";a.printResult(a.multiply());
cout<<"Division : ";a.printResult(a.division());
cout<<endl;
// b
cout<<"Addition : ";b.printResult(b.add());
cout<<"Subtraction : ";b.printResult(b.subtraction());
cout<<"Multiplication : ";b.printResult(b.multiply());
cout<<"Division : ";b.printResult(b.division());
return 0;
}
OUTPUT

Create a template function printResult which prints a value of type T void printResult(T val); C++...
c++
Q.2. a) Create a C++ class template called MathCalc, to perform arithmetic operations between two numbers. These arithmetic operations are addition, subtraction, multiplication and division. The MathCalc class template accepts two type parameters, which can be defined as: template <class T, class U>. This allows MathCalc to carry out arithmetic operations between two different data types. MathCalc has the following public methods, described here in pseudocode: i. Ret Sum(augend, addend); Ret is the return value of the method. ii....
Submissions) Part A Type and run the Array class template discussed in lecture (Templates notes). Modify the class by adding sort member function (refer to Algorithm Analysis notes for sorting algorithms) Sample usage: a. sort(); Add the needed code in main to test your function. template <class T> 1/you can use keyword typename instead of class class Array { private: T *ptr; int size; public: Array(T arr[], int s); void print(); template <class T> Array<T>:: Array (T arr[], int s)...
c++ language
1) Create a function that prints a greeting when called with a name such as greeting ("Elona") 2) Create a function that squares a double number and returns the result as a double. 3) Create a function that takes 5 int numbers and returns the average as a float 4) Create a single function that gives a greeting, calculates the average of 5 grades but does not return a value. Hint: Use return type void and a string...
Header file for the Rational class:
#ifndef RATIONAL_H
#define RATIONAL_H
class Rational
{
public:
Rational( int = 0, int = 1 ); // default constructor
Rational addition( const Rational & ) const; // function
addition
Rational subtraction( const Rational & ) const; // function
subtraction
Rational multiplication( const Rational & ) const; // function
multi.
Rational division( const Rational & ) const; // function
division
void printRational () const; // print rational format
void printRationalAsDouble() const; // print rational as...
in c++ please explain with answer 6. Given the following template function definition, which of the following is not a valid invocation of the function? template <class T> a. swap(s1,s2); void swap(T& left, T& right) b. swap(int1, int2); { c. swap(ch1, ch2); //implementation d. swap(int1, ch2); } int int1, int2; float flt1, flt2; char ch1, ch2; string s1, s2; 7. Why can you not use the swap template function to swap two complete arrays? template <class T> void swap(T& left,...
//C++ program #include<iostream> using namespace std; template<typename T> class list{ private: T*arr; int size; int capacity; void resize(){ capacity*=2; T * newArr = new T[capacity]; for(int i=0;i<size;i++){ newArr[i] = arr[i]; } delete(arr); arr = newArr; } public: ...
PLEASE HELP ME WITH THIS HOMEWORK. Create a template function that, given an array of elements of any template type, deletes an element on a given position. Submit in the standard format in Dropbox Hw 4 before the deadline. Example for insertion (needs a fix!!! - 1st e-mail gets extra-credit) #include <iostream> using namespace std; // A template function to implement element insertion on given position in array. template <class T> void insert(T a[], int &n,T el, int place )...
In C++, for the provided template linked list class create a derived class of it which adds the functionality to it to find the high and low value of any given data stored in the list. The derived class must be a template. LinkedList.h #pragma once #include <iostream> using namespace std; template <class T> class ListNode { public: T data; ListNode<T>* next; ListNode(T data) { this->data = data;...
vector.h: #ifndef VECTOR_H #define VECTOR_H #include <algorithm> #include <iostream> #include <cassert> template <typename T> class Vector { public: Vector( int initsize = 0 ) : theSize( initsize ), theCapacity( initsize + SPARE_CAPACITY ) { objects = new T[ theCapacity ]; } Vector( const Vector & rhs ) : theSize( rhs.theSize), theCapacity( rhs.theCapacity ), objects( 0 ) { objects = new T[ theCapacity ]; for( int k = 0; k < theSize; ++k) objects[ k ] = rhs.objects[ k...
Q.1. Create a C++ class template called ArrayCalc, to perform a series of mathematical operations on an array. These mathematical operations are calculating the minimum, maximum, sum and average values of the array. The ArrayCalc class template accepts one type parameter, which can be defined as: template <class T>. This allows ArrayCalc to carry out operations for different array data types. ArrayCalc has the following public methods, described here in pseudo code: i. void FindMin(inArrayData[], inArraySize, SoutMinVal); (This function accepts...