LAB 9 - Array madness
Given the following incomplete C++ program. Complete each function such that:
· function readin, reads values from a data file into the array
· function printarray, prints the array
· function addto adds the prompted value to each element of the array
· function reverse, copies the elements of the array into a second array in reverse order.
Feel free to declare more variables if needed.
The program:
#include <iostream>
#include <fstream>
using namespace std;
ifstream infile;
ofstream outfile;
const int size = 10;
void readin ( int [ ], int);
void addto (int [ ] , int, int);
void reverse (int [ ], int [ ], int );
void printarray ( int [ ], int);
int
main()
{
int array1[size], array2[size];
int num;
infile.open("data.txt");
if(infile.fail())
{
cerr << "Input file failed to open.";
abort();
}
outfile.open("output2.txt");
if (outfile.fail())
{
cerr << "Output file failed to open.";
abort();
}
readin(array1, size);
printarray(array1, size);
cout << "What would you like to add to the array? ";
cin >> num;
addto(array1, size, num);
printarray(array1, size);
reverse(array1, array2, size);
printarray(array2, size);
return 0;
}
void readin ( int a [ ], int num_elem)
{
int i;
//finish function
}
void addto (int a[ ] , int num_ele, int n)
{
int i;
//finish function
}
void reverse (int a[ ], int a2[ ], int num_ele )
{
int i, count;
//finish function
}
void printarray (int a[ ], int num_ele)
{
int i;
//finish function
}