Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help getting this ouput the language c++ please use begginer code easy to u

ID: 3723588 • Letter: N

Question

Need help getting this ouput the language c++ please use begginer code easy to understand and this is a makefile

the text in red is inside a file i named lab.cpp

and the code for the text in black is in a file named Array.cpp

Enter array length to populate (between 1-10) Enter value for index myarray[O] Enter value for index myarray[1] Enter value for index myarray[2] Enter value for index myarray[3] Enter value for index myarray[4] 6 Function CountArray was called and 5 array values were updated Array values are: 4121 0. Their sum is: 26

Explanation / Answer

"lab.cpp" will contain the main() function, where execution will start. "array.cpp" will be included as a header in the "lab.cpp" file. The functions to initialize and print the array will be defined in the "array.cpp" file. This file also included globally declared variable "len" and array "myarray[]" so that they can be used anywhere in the two programs. Sum of this array will be calculated in the main() function by using these two global variables. Please ensure that both these files are included in the same project, so that the two files can be used together.

C++ Code for "lab.cpp"

// This is the file "lab.cpp" which has the main() function
#include <iostream>
#include "array.cpp"
// Include file "array.cpp" here so that its functions and variables can be used here
using namespace std;

int main()
{
// Call the function count_array() from "array.cpp" to enter the array
count_array();
cout << "Function CountArray was called and " << len << " array values were updated ";
// "len" can be used here because the file "array.cpp" has been included
// Call the function print_array() to print array contents
print_array();
int sum = 0;
// Calculate the sum by using myarray[] and len from "array.cpp"
for(int i = 0; i < len; i++)
sum += myarray[i];
cout << "Their sum is: " << sum << " ";
return 0;
}

C++ Code for "array.cpp"

//This is file "array.cpp" which is included as header in the other file "lab.cpp"
#include <iostream>
using namespace std;

//Global variables that can be accessed anywhere in "array.cpp" and "lab.cpp"
int myarray[11]; // Length is between 1 and 10
int len; // Length of the array

void count_array() {
// Function to input the array
cout << "Enter array length to populate (between 1-10): ";
cin >> len;
for(int i = 0; i < len; i++) {
cout << "Enter value for index myarray[" << i << "] ";
cin >> myarray[i];
}
}

void print_array() {
// Function to print the array
cout << "Array values are: ";
for(int i = 0; i < len; i++) {
// "len" and "myarray[]" are globally declared, so can be accessed here
cout << myarray[i] << " ";
} cout << " ";
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote