Arrays and functions HELP!!!!


Write a program with several functions that perform the following tasks:

Read the following 10 integer numbers from the file data.txt into array A.
10 15 27 89 90 95 27 13 99 33

Call function ReadArray that reads numbers from the file data.txt into an array.

Copy array A into array B in reverse order.
Call function ReverseArray that copies an array into another array in reverse order

Print the elements of Array A and B.
Call function PrintArray that prints the elements of an array of any size


THIS IS OUR ASSIGNMENT AND THIS IS WHAT I HAVE SO FAR I CANT DISPLAY ARRAY A AND B AT THE SAME TIME HELP ME WITH THAT PLEASE.
File Edit Options Buffers Tools C++ Help
#include <iostream>
#include <fstream>

using namespace std;

const int ARRAY_SIZE=10;
void ReadArray(int Array_A[], int ARRAY_SIZE);
void ReverseArray(int Array_A[], int Array_B[], int ARRAY_SIZE);
void PrintArray(int Array_A[], int Array_B[], int ARRAY_SIZE);

int main()
{

int Array_B[ARRAY_SIZE];
int Array_A[ARRAY_SIZE];
ReadArray(Array_A, ARRAY_SIZE);
// PrintArray(Array_A, ARRAY_SIZE);
ReverseArray(Array_A, Array_B, ARRAY_SIZE);
PrintArray(Array_A, Array_B, ARRAY_SIZE);

return 0;
}

void ReadArray(int Array_A[], int ARRAY_SIZE)
{
ifstream inputFile;
inputFile.open("data2.txt");
int i=0;

if(!inputFile)
{

cout << "File does not exist";
}

else
{
while (inputFile)
{
inputFile >> Array_A[i];
i++;

}
}
inputFile.close();
}

void ReverseArray( int Array_A[], int Array_B[],int ARRAY_SIZE)
{
for ( int i=0; i< ARRAY_SIZE; i++)
{
Array_B[ARRAY_SIZE-1-i]=Array_A[i];
}


}

void PrintArray (int Array_A[], int Array_B[],int ARRAY_SIZE)
{

for( int i=0; i< ARRAY_SIZE; i++)
{
cout << Array_A[i] << ",";
// cout << Array_B[];

ArrayB= ReverseArray(Array_B[], Array_B[], Array_SIZE);
cout << ArrayB;

}


}

Last edited on
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <fstream>

const int ARRAY_SIZE = 10; // BECAUSE GLOBAL DON'T NEED TO PASS

void ReadArray(int []);
void ReverseArray(int [], int []);
void PrintArray(int []);

int main()
{
    int Array_A[ARRAY_SIZE];
    int Array_B[ARRAY_SIZE];
    
    ReadArray(Array_A);
    PrintArray(Array_A);
    
    ReverseArray(Array_A, Array_B);
    PrintArray(Array_B);
    
    return 0;
}

void ReadArray(int Array_A[])
{
    std::ifstream inputFile;
    inputFile.open("data2.txt");
    int i=0;
    
    if(!inputFile)
    {
        std::cout << "File does not exist";
    }
    
    else
    {
        while (inputFile)
        {
            inputFile >> Array_A[i];
            i++;
        }
    }
    inputFile.close();
}

void ReverseArray( int array01[], int array02[])
{
    for ( int i = 0; i < ARRAY_SIZE; i++)
        array02[ARRAY_SIZE - i - 1] = array01[i];
}

void PrintArray (int anArray[])
{
    for( int i = 0; i < ARRAY_SIZE; i++)
        std::cout << anArray[i] << (i < ARRAY_SIZE - 1? ',':'\n');
}
10,15,27,89,90,95,27,13,99,33
33,99,13,27,95,90,89,27,15,10
Program ended with exit code: 0
Last edited on
Topic archived. No new replies allowed.