subject
Computers and Technology, 01.12.2020 16:40 zay179

In C++, Write a class Field. h and Field. cpp that stores a 2-D array of integers. The following methods should be implemented:
Field( const vector> & )
Field( vector> && )
int Weight( int x1, int y1, int x2, int y2 )
This method returns the sum of all elements in the rectangle defined by the points (x1,y1) and (x2,y2).
Pay attention, the relative position of (x1,y1) and (x2,y2) can be any. If coordinates go beyond the array boundaries, throw the out_of_range exception.
The Weight function should be O(1) run time. To achieve this, you will need to do the precomputing in the constructors. Precomputing should be done in O(N) time and O(N) space. Here, N is the total number of the elements in the 2-D array.
For example, for the array below function Weight(1,2,4,0) returns 42. The selected rectangle is highlighted.
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
int PathCost()
This method computes the cost of the cheapest path from top-left corner of the field to the bottom-right corner. The only possible moves are right and down.
The function PathCost should be O(N) time.
For example, for the same 2-D array, PathCost() returns 25. The cheapest path is highlighted on the picture below.
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
Requirement: no explicit usage of pointers anywhere in your code please. Please comment code thoroughly as well.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 08:00
Someone with this coz i don’t really know what i can choose, just pick whatever u want. homework - you need to choose a website that you like or use frequently. you must visit the website and discuss 6 different features/parts/aspects of the website that you think makes it good. (100 words)
Answers: 2
question
Computers and Technology, 22.06.2019 22:00
Competent nonverbal communication involves interacting with others in a manner that is appropriate for which of the following? select all that apply. situation task individuals
Answers: 3
question
Computers and Technology, 23.06.2019 05:20
Which operating system is a version of linux?
Answers: 1
question
Computers and Technology, 23.06.2019 06:00
Respond to the following in three to five sentences. select the workplace skill, habit, or attitude described in this chapter that you believe is most important for being a successful employee.
Answers: 1
You know the right answer?
In C++, Write a class Field. h and Field. cpp that stores a 2-D array of integers. The following me...
Questions
question
History, 24.11.2020 21:00
question
Mathematics, 24.11.2020 21:00
question
English, 24.11.2020 21:00
question
Mathematics, 24.11.2020 21:00
question
Mathematics, 24.11.2020 21:00
Questions on the website: 13722367