Write a class named Location for locating a maximal value and its location in a two-dimensional array. The class contains public data fields row, column, and maxValue that store the maximal value and its indices in a two dimensional array with row and column as int type and maxValue as double type. The class also contains a constructor Location(row, column, maxValue) for creating an instance with the specified row, column, and maxValue.
Write the following function that returns the location of the largest element in a two-dimensional array. Assume that the column size is fixed.
```
const int ROW_SIZE = 3;
const int COLUMN_SIZE = 4;
Location locateLargest(const double a[][COLUMN_SIZE]);
```
The return value is an instance of Location.
Write a test program that prompts the user to enter a 3 by 4 two-dimensional array and displays the location of the largest element in the array. Here is a sample run:
```
```
#include
using namespace std;
class Location
{
public:
Location(int r, int c, double m)
{
row = r;
column = c;
maxValue = m;
}
int row;
int column;
double maxValue;
};
const int ROW_SIZE = 3;
const int COLUMN_SIZE = 4;
Location locateLargest(const double a[][COLUMN_SIZE])
{
int row = 0;
int column = 0;
double maxValue = a[0][0];
for (int i = 0; i < ROW_SIZE; i++)
for (int j = 0; j < COLUMN_SIZE; j++)
if (maxValue < a[i][j])
{
row = i;
column = j;
maxValue = a[i][j];
}
return Location(row, column, maxValue);
}
int main()
{
double p[ROW_SIZE][COLUMN_SIZE];
cout << "Enter a 3 by 4 two-dimensional array:";
for (int i = 0; i < ROW_SIZE; i++)
for (int j = 0; j < COLUMN_SIZE; j++)
cin >> p[i][j];
Location loc = locateLargest(p);
cout << "The location of the largest element is " <<
loc.maxValue << " at (" << loc.row << ", " << loc.column << ")" << endl;
return 0;
}
(b)
#include
#include
using namespace std;
bool isConsecutiveFour(vector
{
for (int i = 0; i < values.size() - 3; i++)
{
bool isConsecutive = true;
for (int j = i; j < i + 3; j++)
{
if (values[j] != values[j + 1])
{
isConsecutive = false;
break; // No consecutive sequence starting at i
}
}
if (isConsecutive) return true;
}
return false;
}
int main()
{
cout << "Enter the number of values: ";
int size;
cin >> size;
vector
cout << "Enter the values: ";
for (int i = 0; i < values.size(); i++)
cin >> values[i];
cout << (isConsecutiveFour(values) ? "true" : "false") << endl;
return 0;
}
bool isConsecutiveFour(vector
{
int count = 0;
for (int i = 1; i < values.size(); i++)
{
if (values[i - 1] == values[i])
count++;
else
count = 0;
if (count == 4) return true;
}
return false;
}
```
You might also like to view...
________ is the main suite of protocols used on the Internet
A) MIME B) TCP/IP C) DNS D) POP
If the boat has efficiency e, the amount of fuel used when traveling at a speed s for time t is . The distance traveled in that time is .
Consider a class MotorBoat that represents motorboats. A motorboat has attributes for • The capacity of the fuel tank • The amount of fuel in the tank • The maximum speed of the boat • The current speed of the boat • The efficiency of the boat’s motor • The distance traveled The class has methods to • Change the speed of the boat • Operate the boat for an amount of time at the current speed • Refuel the boat with some amount of fuel • Return the amount of fuel in the tank • Return the distance traveled so far a. Write a method heading for each method. b. Write preconditions and postconditions for each method. c. Write some Java statements that test the class. d. Implement the class.
Talks, lectures, or speeches given to an audience are called ________
Fill in the blank(s) with correct word
Case 10-1 Janice, a content writer, uses Microsoft Word 2016 to create articles. She enters the text, edits it, and changes the appearance of the document using the same application. Janice wishes to add a registered trademark symbol at the end of the pages in the document. She should type _____ so that AutoCorrect converts it into a registered trademark symbol.
A. |r|? B. ?(r) C. ?(rt) D. ?|rt|