How to code the following question in C++ ? Design a class named Location for lo
ID: 3727447 • Letter: H
Question
How to code the following question in C++ ?
Design a class named Location for locating a maximal value and its location in a two dimensional array. The class contains public dat fields row, column and maxValue that store the maximal value and its indices in a two dimensional array.
row and column as int type and maxValue is double type.
Write a method that returns the location of the largest element in a 2 dimensional array
Location locateLargest(double ** a) ;
return value is an instance of Location.
Write a test program that prompts the user to enter a two dimensional array and displays the location of the largest element in the array
Explanation / Answer
#include<stdio.h>
int main ( ) {
/* 2D array declaration */
int disp[2] [3] ;
/*Counter Variables for the loop*/
int i, j ;
for (i=0; i<2; i++) {
for(j=0; j<3; j++) {
printf ("Enter value for disp[%d] [%d] : ", i, j) ;
scanf(" %d", & disp[ i ] [ j ] ) ;
}
}
/ /Displying array elements
printf("Two Dimesional array elements: ") ;
for (i=0; i<2; i++) {
for(j=0; j<3; j++) {
printf ("%d ", disp[ i ] [ j ] ) ;
if (j==2) {
printf(" ") ;
}
}
}
return 0;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.