Question I wrote the following in Java. I need help converting it to C++ using a header and cpp file /> public class Homework { /* * method to put 0s in the odd index positions of the * array and 1s in the even index positions */ public static void initializeArray(int [] initializeArray) { for (int i = 0; i < initializeArray.length; i++) { if(i % 2 == 0) { initializeArray[i] = 1; } else { initializeArray[i] = 0; } } } // method to print all elements of an array public static void printArray(int [] printArray) { for (int i = 0; i < printArray.length; i++) { if(i < printArray.length – 1) { System.out.print(printArray[i] + ", "); } else { System.out.println(printArray[i]); } } } // method to sort all array elements into descending order public static void selectionSort(int [] sort) { int maxNum; for (int i = 0; i < sort.length-1; i++) { maxNum = i; for (int j = i + 1; j sort[maxNum]) { maxNum = j; } } //swap the two elements, sort[maxNum] and sort[i] int temp = sort[maxNum]; sort[maxNum] = sort[i]; sort[i] = temp; } } // recursive method to calculate/return the factorial of a number public static int factorial(int n) { if(n == 1){ return 1; } return (n * (factorial(n-1))); }
Question
I wrote the following in Java. I need help converting it to C++ using a header and cpp file />public class Homework { /* * method to put 0s in the odd index positions of the * array and 1s in the even index positions */ public static void initializeArray(int [] initializeArray) { for (int i = 0; i < initializeArray.length; i++) { if(i % 2 == 0) { initializeArray[i] = 1; } else { initializeArray[i] = 0; } } } // method to print all elements of an array public static void printArray(int [] printArray) { for (int i = 0; i < printArray.length; i++) { if(i < printArray.length – 1) { System.out.print(printArray[i] + “, “); } else { System.out.println(printArray[i]); } } } // method to sort all array elements into descending order public static void selectionSort(int [] sort) { int maxNum; for (int i = 0; i < sort.length-1; i++) { maxNum = i; for (int j = i + 1; j < sort.length; j++){ if (sort[j] > sort[maxNum]) { maxNum = j; } } //swap the two elements, sort[maxNum] and sort[i] int temp = sort[maxNum]; sort[maxNum] = sort[i]; sort[i] = temp; } } // recursive method to calculate/return the factorial of a number public static int factorial(int n) { if(n == 1){ return 1; } return (n * (factorial(n-1))); }
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"
