Shishu

generic point class

Aug 11th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <class Data>
  6. int Max(Data *x, int n){
  7.     int i, p;
  8.     Data max;
  9.     max = x[0];
  10.     p = 0;
  11.     for(i = 0; i < n; i++){
  12.         if(x[i] > max){
  13.             max = x[i];
  14.             p = i;
  15.         }
  16.     }
  17.     return p;
  18. }
  19.  
  20. int main(){
  21.     int age[5] = {5, 9 , 4, 7, 3};
  22.     double cgpa[5] = {3.5, 1.9, 2.9, 3.9, 2.5};
  23.     int ans;
  24.     ans = Max(cgpa, 5);
  25.     cout << ans << endl;
  26.     return 0;
  27. }
Add Comment
Please, Sign In to add comment