follows all instructions Write a method that takes an array and two values a and
ID: 671647 • Letter: F
Question
follows all instructions
Write a method that takes an array and two values a and b as its arguments then fill the array with random values between a and b The method header should be: Write a method that take 4 arrays say a,b,c,d and an integer value k and merges arrays a,b from the point k and get two offsprings c,d The method header should be write a method that takes an array and two values a and b as its arguments then change the contents of the array by multiply each value by a value between a and b The method header should be: Test The previous methodsExplanation / Answer
#include <iostream>
#include <stdlib.h>
using namespace std;
void fillArray(double arr[], double min, double max) {
int range = (max - min + 1);
double r = min;
int arrSize = sizeof(arr) / sizeof(arr[0]);
cout <<arrSize;
for(int i =0; i < arrSize; i++) {
r = min+ rand() % range;
arr[i] = r;
}
}
void scrosover(double A[], double B[], double C[], double D[], int k) {
int arrSize = sizeof(A) / sizeof(A[0]);
for(int i =0; i < arrSize; i++) {
if(i < k) {
C[i] = A[i];
D[i] = B[i];
} else {
C[i] = B[i];
D[i] = A[i];
}
}
}
void mutation (double arr[], double min, double max) {
int arrSize = sizeof(arr) / sizeof(arr[0]);
int range = (max - min + 1);
double r = min+ rand() % range;
for(int i =0; i < arrSize; i++) {
arr[i] = arr[i] * r;
}
}
void printArr(double arr[]) {
int arrSize = sizeof(arr) / sizeof(arr[0]);
for(int i =0; i < arrSize; i++) {
cout << arr[i] << " ";
}
cout <<" ";
}
int main()
{
double arr[] = {1,2,4,5,6,7} ;
fillArray(arr,10, 20);
printArr(arr);
double A[] = {1,2,3,4,5};
double B[] = {6,7,8,9,10};
double C[5], D[5];
scrosover(A,B,C,D,3);
printArr(C);
printArr(D);
double arr2[] = {5,6,7,8,9};
mutation(arr2, 5, 10);
printArr(arr);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.