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 10:00
Jackson is teaching the decimal number system. he wants his students to know how to expand numbers by powers of 10. which is the correct order in which digits are assigned values in the decimal number system?
Answers: 1
question
Computers and Technology, 22.06.2019 18:00
Martha is a healer, a healthcare provider, and an experienced nurse. she wants to share her daily experiences, as well as her 12 years of work knowledge, with people who may be interested in health and healing. which mode of internet communication can martha use?
Answers: 3
question
Computers and Technology, 22.06.2019 19:50
Write a car class having two private member variables called tank and speed. write public methods called pumpgas and gofast. the method pumpgas gets an integer for gas that must be pumped. that value needs to be added to tank (no more than 20 gallons). it must return the amount of gas that is purchased ($4 per gallon). the method gofast should increase the speed by 5 each time it is called.write a constructor for the above class that initialized both variables to zero.write a tostring to display both the tank and speed when the car is printed.modify the car class to implement the interface comparable and an interface called carinter having the public methods in carinter.write the main program to create an array of size 5 of type car. create 5 car objects having each location of the array to refer to one of the cars. test the pumpgas, gofast, equals method on the array items. write an enhanced loop to print all the car values (using a tostring written last time).write a generic method to find the minimum of four items. pass int, double, char, string and car objects to test this method.
Answers: 1
question
Computers and Technology, 23.06.2019 02:00
Arecipients list has been loaded into a document. which commands should be clicked in order to filter the list so that letters will not be printed for recipients who live in a certain state? mailings tab, start mail merge, select recipients, type new list, then insert only contacts from the desired states mailings tab, rules, select recipients, use existing list, then choose a recipients list that includes only contacts in certain states mailings tab, select recipients, use existing list, rules, fill in, then type in certain states mailings tab, rules, skip record select “state” under field name, then type in the state name under “equal to”
Answers: 2
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
Mathematics, 12.01.2021 01:30
question
Mathematics, 12.01.2021 01:30
question
Mathematics, 12.01.2021 01:30
question
English, 12.01.2021 01:30
question
Mathematics, 12.01.2021 01:40
question
Mathematics, 12.01.2021 01:40
Questions on the website: 13722360