Ideas Solution Code
#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
const int rows = 10;
const int cols = 10;
int selectOption(){
int choice = 0;
cout<<"Press 1 to populate a two-dimensional array with integers from 1 to 100\n";
cout<<"Press 2 to display the array elements\n";
cout<<"Press 3 to display the largest element present in the array along with its row and column index\n";
cout<<"Press 4 to find and show the transpose of the array\n";
cout<<"Press 5 To Exit\n";
cout<<"\nPlease select an option, use numbers from 1 to 5: ";
do {
cin>>choice;
if(choice >= 1 && choice <= 5){
break;
}
else {
cout<<"\nChoice should be between 1 and 5\n";
cout<<"Invalid choice, please select again: ";
}
} while(true);
cout<<"___________________________________________________\n";
return choice;
} // end selectOption function
void populateArray(int data[rows][cols]){
srand(time(0));
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
data[i][j] = rand() % 100 + 1;
}
}
cout<<"Array populated sucessfully\n";
} // end of poulateArray function
void showElements(int data[rows][cols]){
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
cout<<data[i][j]<<"\t";
}
cout<<endl;
}
} // end of showElements function
void showLargestElement(int data[rows][cols]){
int largest = 1, row =0, col = 0;
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
if(data[i][j] > largest){
largest = data[i][j];
row = i;
col = j;
}
}
}
cout<<"Largest element is "<<largest<<" which is at row = "<<row+1<<" or index = "<<row<<" and column "<<col+1<<" or index "<<col<<endl;
} // end of showLargestElement function
void transposeArray(int data[rows][cols]){
for(int i = 0; i < cols; i++){
for(int j = 0; j < rows; j++){
cout<<data[j][i]<<'\t';
}
cout<<endl;
}
} // end of transposeArray function
main(){
int choice = 0, data[rows][cols] = {0};
do{
choice = selectOption();
switch(choice){
case 1:
cout<<endl;
populateArray(data);
cout<<endl;
break;
case 2:
if(data[0][0] == 0){
cout<<"\nSorry the array is empty, first populate it by pressing 1 to perform this task"<<endl<<endl<<endl;
continue;
}
cout<<endl;
showElements(data);
cout<<endl;
break;
case 3:
if(data[0][0] == 0){
cout<<"\nSorry the array is empty, first populate it by pressing 1 to perform this task"<<endl<<endl<<endl;
continue;
}
cout<<endl;
showLargestElement(data);
cout<<endl;
break;
case 4:
if(data[0][0] == 0){
cout<<"\nSorry the array is empty, first populate it by pressing 1 to perform this task"<<endl<<endl<<endl;
continue;
}
cout<<endl;
transposeArray(data);
cout<<endl;
break;
}
}while(choice != 5); // end of do-while loop
} // end of main function