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

could you explain the source code line by line detaily (the comments it has is r

ID: 3874030 • Letter: C

Question

could you explain the source code line by line detaily (the comments it has is really short and unclear). I am uploading the question and the source code.

USE C++

Write a program which initializes 2 dynamic arrays of floats Arr_a and Arr_b. Arr_C is a dynamic array as well.

The user will input values to place into Arr_a then Arr_b.

The program will then append into Arr_c the elements from Arr_b, then append into Arr_c elements from Arr_a.

The program will finally output the contents of Arr_c.

Attach the Source Code and Output below.

#include 2 using namespace std; 3 int main() 4 5 //declaring dynamic arrays 6 float *Arr-a, *Arr-b, *Arr_c; 7 //array sizes 8 int x, y; 9 //Reading the size of first array 10 coutx; 12 //declaaring dynamic array with size x 13 Arr_a-new float[x]; 4 cout

Explanation / Answer

Explain the Source Code line by line :


/* Program header all the neccessry pre defined library functions can be used are specified in corresponding header files */
#include<iostream.h>
#using namespace std;


//Program execution starts at main() , int is the return type
int main()
{

/* Declaring dynamic arrays
Arrays store elements of similar type. Dynamic is when arrays are initialized when the program is executing. In this case user enters the array value when the program is running.
Array is of type float which means we can store numbers with decimal values. */

float *Arr_a, *Arr_b, *Arr_c;


//Declaring array size variables. These variabls will be used to store the array size
int x,y;

/* Reading the size of the first array. Here user will be promped to enter the size of the array using cout statement. Which will be stored in the variables declared ablove using cin statement. */
cout<<"How many elements you wish to enter into Arr_a";
cin>>x;

/* Declaring dynamic array with size x
Here the will be created using the size specified by the user. */

Arr_a=new float[x];

//User will be promped to enter the elements of the array using cout statement.
cout<<"Enter elements into first arrary: ";

/* Reading elements into first array
This is the logic for reading the values into the array using for loop. The loop will run for x times. x is the size of the array. Inserting the values into the array every single time the loop runs. */

for( int i = 0; i<x;i++)
{
//User will be promped to enter a value into array using cout statement.
cout<<" Enter a value : ";
//Cin statement will be used to insert the value into the array Arr_a[i]
cin>>Arr_a[i];
}

/* Reading the size of the second array. Here user will be promped to enter the size of the array using cout statement. Which will be stored in the variable y declared ablove using cin statement. */
cout<<"How many elements you wish to enter into Arr_b";
cin>>y;

/* Declaring dynamic array with size y
Here the will be created using the size specified by the user. */

Arr_b=new float[y];

//User will be promped to enter the elements of the array using cout statement.
cout<<"Enter elements into second arrary: ";

/* Reading elements into second array
This is the logic for reading the values into the array using for loop. The loop will run for y times. y is the size of the array. Insterting the values into the array every single time the loop runs. */

for( int i = 0; i<y;i++)
{
User will be promped to enter a value into array using cout statement.
cout<<" Enter a value : ";
//Cin statement will be used to insert the value into the array Arr_b[i]
cin>>Arr_b[i];
}


//Displaying contents of first array
cout<<"Contents of Array_a "<<endl;
/* Logic to display content of array using for loop. Loop prints one element each time it runs. It will run x no of times that is the size of the array . */
for(int i=0; i<x ; i++)
{
//It will print array values with cout statement. " " is used to give one tab space after each element.
cout<<Arr_a[i]<<" ;
}


//Displaying contents of second array
cout<<"Contents of Array_a "<<endl;
/* Logic to display content of array using for loop. Loop prints one element each time it runs. It will run y no of times that is the size of the array. */
for(int i=0; i<y ; i++)
{
//It will print array values with cout statement. " " is used to give one tab space after each element.
cout<<Arr_b[i]<<" ;
}


/* Declaring third array dynamically with size x+y
New array will be created using the size of first and second array . x + y , since the new array will store the elements of both first and second array. */

Arr_c= new float(x+);

//Copying elements of second array
cout<< Copying elements of Arr_b to Arr_c ";
//Logic to copy the array elements from one array to another using for loop.
for(int i=0; i<y ; i++)
{
//For every time the loop runs. It copies one element from Arr_b to Arr_c
Arr_c[i]=Arr_b[i];
}


//Copying elements of first array
cout<< Copying elements of Arr_a to Arr_c ";
//New variable is initialized to 0. To start the array index from 0.
int j=0;
/*Logic to copy the array elements from one array to another using for loop.
Note i<(x+y) which means it will copy to the last space. That is after elements of second array. */

for(int i=0; i<(x+y) ; i++)
{
//For every time the loop runs .It copies one element from Arr_c to Arr_c
Arr_c[i]=Arr_a[j++];
}


//Displaying contents of third array after copying from second and first array
cout<<" Array contents of Arr_c after copying from Arr_b and Arr_a : "<<endl;

/* Logic to display content of array using for loop. Loop prints one element each time it runs. It will run x no of times that is the size of the array. */
for(int i=0;i<(x+y);i++)
{
//It will print array values with cout statement. " " is used to go the next line after every iteration.
cout<<Arr_c[i]<<" ";

}

/* Returning 0- Which means it is returning nothing. It should be used because main has a return type of int specified. " int main()". */

return 0;

}