Question
C++ Modify arrtemp.cpp by removing the preassignment of the data for each array and by adding five new function templates. The first new function template
C++
Modify arrtemp.cpp by removing the preassignment of the data for each array and by adding five new function templates.
The first new function template should allow the user to enter the array data from the keyboard.
The second new function template should print the second largest value for an array without sorting.
You may assume that each array contains distinct data, that is no duplicates.
The third new function template should sort the array data in ascending order.
The fourth new function template should save the array data to a text file.
The fifth new function template should retrieve the array data from the text file.
Output should include the second largest value of each array along with all three arrays being printed out in ascending order twice, once before the text file is saved and once after the array is retrieved from the text file. . (Make sure to include the line template
Each array should be saved to a separate text file.
arrtemp.cpp
#include
using namespace std;
//function template to print an array
//works for multiple data types
template
void printarray (T *a, const int n)
{
for (int i = 0; i < n; i++)
cout << a[i] << " ";
cout << endl;
}
int main()
{
const int n1 = 5, n2 = 7, n3 = 6;
int a[n1] = {2, 4, 6, 8, 10};
float b[n2] = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7};
char c[n3] = "HELLO";
cout <<"the integer array" << endl;
printarray(a, n1);
cout <<"the float array" << endl;
printarray(b,n2);
cout <<"the string is" << endl;
printarray(c,n3);
return 0;
}
/*
the integer array
2 4 6 8 10
the float array
1.1 2.2 3.3 4.4 5.5 6.6 7.7
the string is
H E L L O
*/
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started