In: Computer Science
int[]array1={67, 78, 92, 45, 67, 86, 24, 96, 39, 82, 86};
String[] array2 ={“Namath”, “Dockery”, “Atkinson”, “Sauer”, “Brady”, “Maynard”, “Boozer”};
C++ code for the required specifications is provided below: FileName- main.cpp
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
void swappingINT(int &a, int &b) { //swap the content of a and b
int temp;
temp = a;
a = b;
b = temp;
}
void displayINT(int *array, int size) {
for(int i = 0; i<size; i++)
cout << array[i] << " ";
cout << endl;
}
void selectionSortINT(int *array, int size) {
int i, j, imin;
for(i = 0; i<size-1; i++) {
imin = i; //get index of minimum data
for(j = i+1; j<size; j++)
if(array[j] > array[imin])
imin = j;
//placing in correct position
swap(array[i], array[imin]);
}
}
void swapping(string &a, string &b) { //swap the content of a and b
string temp;
temp = a;
a = b;
b = temp;
}
void display(string *array, int size) {
for(int i = 0; i<size; i++)
cout << array[i] << " ";
cout << endl;
}
void selectionSort(string *array, int size) {
int i, j, imin;
for(i = 0; i<size-1; i++) {
imin = i; //get index of minimum data
for(j = i+1; j<size; j++)
if(array[j] < array[imin])
imin = j;
//placing in correct position
swap(array[i], array[imin]);
}
}
int cubicNumbersIterative(int n) {
int sum = 0;
for(int i = n; i>0; i--) {
//cout << sum << " ";
sum += pow(i, 3);
}
return sum;
}
int cubicNumbersRecursive(int n) {
if(n == 0)
return 0;
return(pow(n, 3) + cubicNumbersRecursive(n-1));
}
int main() {
int n;
int arr1[] = {67, 78, 92, 45, 67, 86, 24, 96, 39, 82, 86};
n = 11;
string arr2[] = { "Namath", "Dockery", "Atkinson", "Sauer", "Brady", "Maynard", "Boozer"};
int n2 = 7;
cout << "Array1 before Sorting: ";
displayINT(arr1, n);
selectionSortINT(arr1, n);
cout << "Array1 after Sorting: ";
displayINT(arr1, n);
cout << "Array2 before Sorting: ";
display(arr2, n2);
selectionSort(arr2, n2);
cout << "Array2 after Sorting: ";
display(arr2, n2);
int number = 3;
int sumit = cubicNumbersIterative(number);
int sumrec = cubicNumbersRecursive(number);
cout << "\nCubic Sum Iterative: " << sumit << endl;
cout << "\nCubic Sum Recursive: " << sumrec << endl;
return 0;
}