C++ please.... Need this... For this assignment you will be creating three one-d
ID: 640802 • Letter: C
Question
C++ please....
Need this...
For this assignment you will be creating three one-dimensional dynamic arrays.
First you will prompt the user for the length of the dynamic array.
Next you will create 2 dynamic arrays of the length provided.
For each of these arrays populate them with random numbers in the range from 0 through 9 inclusive (0-9).
Next print out the contents of each array.
Next create another dynamic array twice the length provided.
Now concatonate the two previous arrays into the third.
Finally print out the third array.
Note: You are required to use pointer arithmatic and not subscript notation for the arrays.
For example, use *(a + i) instead of a[i].
This is what i have so far and please work with what i have...
Explanation / Answer
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
srand(time(NULL));
int size = 0;
cout << "Get the size of your Array > ";
cin >> size;
int *a1, *a2, *a3;
a1 = new int[size];
a2 = new int[size];
int random_number = 0;
for(int i = 0; i < size; i++){
random_number = rand()%10;
*(a1 + i) = random_number;
}
cout << "a1 > ";
for(int j = 0; j < size; j++){
cout << *(a1 + j) << " ";
}
cout << endl;
for(int i = 0; i < size; i++){
random_number = rand()%10;
*(a2 + i) = random_number;
}
cout << "a2 > ";
for(int j = 0; j < size; j++){
cout << *(a2 + j) << " ";
}
cout << endl;
a3 = new int[(size * 2)];
for(int j= 0; j< size; j++)
{
*(a3+j)=*(a1+j);
*(a3+j+size)=*(a2+j);
}
return (0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.