I'm trying to write a C++ program that:
- Creates an - array_1of- size nand fills it following the formula- x(i) = x(0) + h*iwhere- n,- x(0)and- hare input parameters;
- Creates an - array_2of- size l=n+1and fills it following the formula- x(i) = ((b-a)/n)*i+a, where- a,- bare input parameters;
- Creates an - array_sinof- size l=n+1and fills it with the sine of the elements of- array_2.
I decided to do these three steps in three separate void functions. Here is my code:
#include <iostream>
#include <cmath>
using namespace std;
void fillarr1 (double ar_x[], int n, double x_0, double h);
void fillarr2 (double ar_y[], double a, double b, int n, int l);
void Sin (double ar_y[], double sine_[], int l);
int main () 
{
    int n, i;   
    double  a, b, h, x_0;
    cout << "Number of points \n";
    cin >> n;
    int l=n+1;
    double *x = new double(n); //array_1
    double *y = new double(l);  //array_2
    double *sine = new double(l);   //array_3
    cout << "Separation between points \n";
    cin >> h;   
    cout << "x(0) = ";
    cin >> x_0;
    fillarr1 (x, n, x_0, h);
    cout << "\na = ";
    cin >> a;
    cout << "\nb = ";
    cin >> b;
    fillarr2 (y, a, b, n, l);
    cout << "\nsin \n";
    Sin(y, sine, l);
    cout << "\n\n\n";
    for (i=0; i<n; i++)
    {   
        cout << x[i] << "\t";
    }
    cout << "\n\n\n";
    for (i=0; i<l; i++)
    {   
    
        cout << y[i] << "\t";
    }
    cout << "\n\n\n";
    for (i=0; i<l; i++)
    {   
    
        cout << sine[i] << "\t";
    }
    delete [] x;
    delete [] y;
    delete [] sine;
    return 0;
}
void fillarr1 (double ar_x[], int n, double x_0, double h)
{
    int i;
    for (i=0; i<n; i++)
    {   
        ar_x[i]=x_0+h*i;
        cout << ar_x[i] << "\t";
    }
}
void fillarr2 (double ar_y[], double a, double b, int n, int l)
{   
    int i;
    double h_;
    h_=(b-a)/(n);
    for (i=0; i<l; i++)
    {   
        ar_y[i]=a+h_*i;
        cout << ar_y[i] << "\t";
    }
}
void Sin(double ar_y[], double sine_[], int l)
{
    int i;
    for(i=0;i<l;i++)
    {
        sine_[i]=sin(ar_y[i]);
        cout << sine_[i] << "\t";
    }
      
}
I'm also trying to print the elements of the arrays both in the void functions and in the main. It appears that, after the function calls, the original dynamic arrays passed to the void functions are filled with random values. Furthermore, the process exits with return value 3221226356. Here is an output example: output
I really don't know how to fix it, any help would be very appreciated.
 
     
    