Ive created my program however I got an error message saying
I\'ve created my program, however I got an error message saying void printFileValues cannot convert 1 from intArray[20] to int. Is my program correct and my code correct, down below is the question asked and my code created.
#include \"stdafx.h\"
#include <iostream>
#include <string>
#include <fstream>
#include <assert.h>
using namespace std;
void readIntFile(ifstream &, int[], int, int &);
void printFileValues(int, int &);
int main()
{
string fileName1, fileName2, fileName3, fileName4;
ifstream x;
int const size = 20;
int intArray[size];
int length = 0;
// The user will be asked to enter the first file name
cout << \"Enter the input file name: \";
cin >> fileName1;
cout << endl;
// The first file will be opened
x.open(fileName1.c_str());
readIntFile(x, intArray, size, length); // The function is called, so the user can read the data in the file
printFileValues(intArray, length);
if (x.is_open())
{
cout << \"The file does exists and the data has been shown, you may proceed.\" << endl;
}
else
{
cout << \"ERROR! The file does not exists, please check the file again. \" << endl;
}
// The user will be asked to enter the second file name
cout << \"Enter the input file name: \";
cin >> fileName2;
cout << endl;
// The second file will be opened
x.open(fileName2.c_str());
readIntFile(x, intArray, size, length); // The function is called, so the user can read the data in the file
printFileValues(intArray, length);
if (x.is_open())
{
cout << \"The file does exists and the data has been shown, you may proceed.\" << endl;
}
else
{
cout << \"ERROR! The file does not exists, please check the file again. \" << endl;
}
//The user will be asked to enter the third file name
cout << \"Enter the input file name: \";
cin >> fileName3;
// The third file will be opened
x.open(fileName3.c_str());
readIntFile(x, intArray, size, length); // The function is called, so the user can read the data in the file
printFileValues(intArray, length);
if (x.is_open())
{
cout << \"The file does exists and the data has been shown, you may proceed.\" << endl;
}
else
{
cout << \"ERROR! The file does not exists, please check the file again. \" << endl;
}
// The user will be asked to enter the fourth file name
cout << \"Enter the input file name: \";
cin >> fileName4;
// The fourth file will be opened
x.open(fileName4.c_str());
readIntFile(x, intArray, size, length); // The function is called, so the user can read the data in the file
printFileValues(intArray, length);
if (x.is_open())
{
cout << \"The file does exists and the data has been shown, you may proceed.\" << endl;
}
else
{
cout << \"ERROR! The file does not exists, please check the file again. \" << endl;
}
system(\"pause\");
return 0;
}
// Description: This function will read the data in the files.
//Pre-Condition: For this function to work, you must input a while statement
//Post-Condition: The end result would be the function has been able to read the data from the file and the user will then proceed to the next step
void readIntFile(ifstream &x, int intArray[], int size, int &length)
{
int i = 0;
while (!x.eof())
{
x >> intArray[i];
}
i++;
size = i;
}
// Description: This function wil print the files data values once called in the main function
//Pre-Condition: In order for this function to work, you must be able to print what has been stored in the array
//Post-Condition: The end result would be the correct values stored in the file array shown
void printFileValues(int intArray[], int &length)
{
for (int i = 0; i < length; i++)
{
cout << \"The values in the files are: \" << intArray[i] << \" \" << endl;
}
}
Pregram 2 i program will request the user to enter a file name, then attempt to open the file with that name (1) If the file does not exist, display an error message. (2) If the file does exist but contains NO data (3) If the file does exist and contains NO data, display an error message contains data then your program calls a function that has the following interface -out ifnu void reallnfild intream &x;, int intArray 1 1, int size, int &length;, ) n ra void printFile Values(int intArray [ 1. int&length;) in Inside method readIntFile, the code should read all the integers in the file and store them into array intArray and return the total number of integers stored in that file in variable length. You must design a while loop with a test for end-of-file (eof) condition: x.eofO where eof ) represents the end of a file and is a member function of fstream class. The variable size is the declared size of the array. The size of the array for this program is 20. Remember that you are required to perform a check to ensure you do not overflow the array The method printFile Valucs will print the values that are stored in the array. Use proper labelling. Use an assetion to stop the program if there are no values in the array to print. Since this should never happen but is a \"safeguard\" in case it does how will you test this? You must run tests to verify the correctness of your program The file \"in.dat\" should be downloaded from Canvas must be a part of the testing of the program NOTE: These checks will be REQUIRED on all future programs that use input files Use the project template for EACH program-uploaded as individual documentsSolution
you need to change the function declaration of printFileValues in the beginning before main function to take first argument as array not int as below
void printFileValues(int [], int &);
if you make abov change ,,it compiles ..