c++ program input file (data.dat) consists of the following ______________ 4 1 1
ID: 3762558 • Letter: C
Question
c++ program input file (data.dat) consists of the following ______________ 4 1 13 3 2 1.1 4.1 8.1 5.2 2.3 the student is in class _______________ max function should output 13,8.1,"the" as the max values. Thanks! Program 1: Let A be an array of n elements. Write a template function, maxfunc(...), which takes an unsorted f type as an input p maximum value. Assume the operators are defined question, you may hardcode n-5. You must write all functions you call, and also need to write a main0 to test the following data arrays stored in a data file (data.dat): f type as an input parameter and returns the element with the Assume the operators and > are defined for the class T. In this array o 4 1 13 32 1.1 4.1 8.1 5.2 2.3 the student is in class Il >is judged on the basis of alphabetical order In addition, the results should be printed out in main() routine to the screen and to an output file (out.txt). template typename T> void functionMethod(T inData) coutExplanation / Answer
#include<iostream>
#include<string.h>
#include<fstream>
using namespace std;
template <typename T>
T maxfunc(T arr[]) {
T max=arr[0];
for (int i=1; i<5; i++) {
if (arr[i] > max)
max = arr[i];
}
return max;
}
template <typename T>
void functionMethod(T inData) {
cout<<inData<<" ";
}
int main() {
ifstream file;
file.open("data.dat");
if (!file) {
cout<<"Sorry!! file cannot be opened!!"<<" ";
return 0;
}
int arr1[5];
double arr2[5];
for (int i=0; i<5; i++) {
file>>arr1[i];
}
functionMethod(maxfunc(arr1));
for (int i=0; i<5; i++) {
file>>arr2[i];
}
functionMethod(maxfunc(arr2));
cout<<" ";
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.