1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
//Purpose: To find the maximum
//Course: Comp 130
//Professor: Mia Chia
//Driver file.
#include<iostream>
#include <string>
#include <cmath>
#include "maximum.h"
using namespace std;
int main() {
int arrA[3] = { 1 , 2000, 3 };
double arrB[3] = { 45.7, 23.6, 999.6 };
string arrC[3] = { "ghi", "abc","def" };
maximum <int> intList;
cout << "Maximum from integer array = " << maxiNum(arrA) << endl; // I HAVE AN UNDEFINED Identifier here
return 0;
}
//maximum.h
#include <iostream>
using namespace std;
#include <string>
template<class T>
class maximum {
public:
//maximum;
T maxiNum();
void displayList();
int arrA[3] = { 1 , 2000, 3 };
double arrB[3] = { 45.7, 23.6, 999.6 };
string arrC[3] = { "ghi", "abc","def" };
private:
int capacity = 5;
int first = 0;
int last = 0;
};
template<class T>
T maximum<T>::maxiNum() { //This function should find the maximum of a given array
T num1;
T num2;
T num3;
T max;
int arrA[3] = { 1 , 2000, 3 };
double arrB[3] = { 45.7, 23.6, 999.6 };
string arrC[3] = { "ghi", "abc","def" };
num1 = arrA[0], arrB[0], arrC[0];
num2 = arrA[1], arrB[1], arrC[1];
num3 = arrA[2], arrB[2], arrC[2];
num1 = max;
if (num2 > num1) {
num2 = max;
}
if (num3 > num2) {
num3 = max;
}
return max;
}
template<class T>
void maximum<T>::displayList()
{
for (int i = 0; i < 5; i++)
{
cout << arrA[i] << " ";
cout << arrB[i] << " ";
cout << arrC[i] << " ";
}
}
|