Hi, I'm having trouble displaying the numbers in the file on the screen. The numbers are in the .data files but i cant get them to display.
//******************************************************************************
// Exercise: Homework 07 Arrays and pointers
// This program reads two sets of integers from the text files A.data and B.data.
// The program finds the intersection of the two sets (which is the
// set of numbers contained in both sets). The intersecting
// values are displayed and saved in C.data with the same file format
// tha A.data and B.data, is that to say, one interger in each line of the file
// being the first line the number of elements in the set.
//******************************************************************************
#include <iostream>
#include <fstream>
using namespace std;
const int SIZE = 20; // Maximum number of values in each array
// Function Prototypes
void getArrays(int [], int &, int [], int &, int);
int findIntersection(int [], int, int [], int, int [], int);
void displayIntArray(int [], int);
void saveArray(int [], int);
int main(){
//Sets A ,B, C and the atual corresponding size
int setA[SIZE], setB[SIZE], setC[SIZE], sizeA=0, sizeB=0, sizeC=0;
// Get values for the sets A and B from A.data and B.data.
getArrays(setA, sizeA, setB, sizeB, SIZE);
// Find the intersection of the two sets A and B
sizeC = findIntersection(setA, sizeA, setB, sizeB, setC, SIZE);
// Display setC (intersecting values of setA and setB) and save it in C.data
saveArray(setC, sizeC);
displayIntArray(setC, sizeC);
system("pause");
return 0;
}
//******************************************************************************
// Definition of function getArrays
// This function accepts two int arrays as arguments.
// It prompts the user to enter 10 values for each array
//******************************************************************************
void getArrays(int A[], int &sizeA, int B[], int &sizeB , int maxSize){
ifstream fileA;
fileA.open ("A.data");
cout<<"Reading data from a.data";
for(int index = 0; index < sizeA; index++)
fileA>>A[index];
fileA.close();
displayIntArray(A, sizeA);
ifstream fileB;
fileB.open ("B.data");
// file sizeA;
//if (sizeA> = max size)(cout<<"eretor";exit(0);
cout<<"Reading data from b.data";
for(int index = 0; index < sizeB; index++)
fileB>>B[index];
fileB.close();
displayIntArray(B, sizeB);
//TODO
}
//******************************************************************************
// Definition of function findIntersection
// This functon accepts three arrays as arguments.
// The first two arrays (first and second) are scanned, and all values appearing
// in both are stored in the third array (intersect).
// The number of values that appear in both arrays is returned.
//******************************************************************************
int findIntersection(int A[], int sizeA, int B[], int sizeB, int C[], int size){
int index3 = 0;
for(int index1 = 0; index1 < sizeA; index1++)
{
for(int index2 = 0; index2 < sizeA; index2++)
{
if(A[index1] == B[index2])
{
C[index3] = A[index1];
index3++;
}
}}
//TODO
}
//******************************************************************************
// Definition of function displayIntArray
// This function acepts two arguments: an array of ints
// and an int. The second argument is the number of
// valid elements contained in the array.
// These values are displayed, if there are any.
//******************************************************************************
void displayIntArray(int a[], int num){
for (int index = 0; index < num; index++)
cout << a[index] <<" A";
cout << endl;
//TODO
}
//******************************************************************************
// Definition of function saveArray
// This function save an array "a" of size "size" in the textFile C.data
//******************************************************************************
void saveArray(int a[], int size){
ofstream fileC;
fileC.open("C.data");
cout<<"Saving Intersection(a,B) in c.data";
fileC<<size;
for(int index = 0; index < size; index++)
fileC<<a[index];
fileC.close();
}