program 1 code: #include <iostream> #include <fstream> using namespace std; cons
ID: 3762316 • Letter: P
Question
program 1 code:
#include <iostream>
#include <fstream>
using namespace std;
const int n =5;
int A[n];
template <class T>
T maxfunc()
{
int max=0;
for(int i=0; i< 6; i++)
{
if(A[i]>max)
A[i] = max;
}
cout << "The max value is " << max << endl;
return 0;
};
int main()
{
ifstream ins;
ins.open("data.rtf");
cin.getline("data.rtf", 5);
if(ins.is_open()){
cout << "File is open";
}
else{
cout << "File NOT Open";
}
while(ins.good())
{
for(int i=0; i<6; i++)
cout << A[i] << " " << endl;
//ins>>A[i];
}
maxfunc();
//system("pause");
return 0;
}
Explanation / Answer
#include <iostream>
#include <fstream>
using namespace std;
const int n =5;
int A[n];
template <class T>
T maxfunc()
{
int max=0;
for(int i=0; i< 6; i++)
{
if(A[i]>max)
A[i] = max;
}
cout << "The max value is " << max << endl;
return 0;
};
int main()
{
ifstream ins;
ins.open("data.rtf");
cin.getline("data.rtf", 5);
if(ins.is_open()){
cout << "File is open";
}
else{
cout << "File NOT Open";
}
while(ins.good())
{
for(int i=0; i<6; i++)
cout << A[i] << " " << endl;
//ins>>A[i];
}
maxfunc();
//system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.