munther_abdellatif

template exc

Jul 6th, 2021 (edited)
422
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3. template <class A>
  4. A MAX(A a,A b);
  5. int main() {
  6.     int x , y;
  7.     cout << "enter int number X : ";
  8.     cin >> x;
  9.     cout << "enter int number Y : ";
  10.     cin >> y;
  11.     cout << "the maximum number is " << MAX(x, y)<<endl;
  12.     float z, w;
  13.     cout << "enter float number X : ";
  14.     cin >> z;
  15.     cout << "enter float number Y : ";
  16.     cin >> w;
  17.     cout << "the maximum number is " << MAX(z, w)<<endl;
  18.     char a, b;
  19.     cout << "enter char X : ";
  20.     cin >> a;
  21.     cout << "enter char Y : ";
  22.     cin >> b;
  23.     cout << "the maximum char is " << MAX(a, b)<<endl;
  24. }
  25. template <class A>
  26. A MAX(A a,A b){
  27.     return (a > b ? a : b);
  28. }
RAW Paste Data