Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using c + + ; In the 2 0 2 0 grid far below, four numbers along a diagonal line have been marked in red.

Using c++;
In the 2020 grid far below, four numbers along a diagonal line have been marked in
red. The product of these numbers is 26637814=1788696. Write a program to
answer the question: what is the greatest product of "z" adjacent numbers in the same
direction (up, down, left, right or diagonally) in the grid?
grid20.txt
2020
0802229738150040007504050778521250779108
4949994017811857608717409843694804566200
8149317355791429937140675388300349133665
5270952304601142692468560132567137023691
2231167151676389419236542240402866331380
2447326099034502447533537836842035171250
3298812864236710263840675954706618386470
6726206802621220956394396308409166499421
2455580566739926971778789683148834896372
2136230975007644204535140061339734313395
7817532822753167159403800462161409535692
1639054296353147555888240017542436298557
8656004835718907054444374460215851541758
1980816805944769287392138652177704895540
0452088397359916079757321626267933279866
8836688757622072034633674655123263935369
0442167338253911249472180846293240627636
2069364172302388346299698267598574043616
2073352978319001743149714886811623570554
0170547183515469169233486143520189196748
Your program must accept the parameter "z" from command line along with the name of
the grid file. It must output the positions of the numbers in the greatest product, the
actual numbers and the product. For example, to indicate the above four red numbers,
your program must print the following:
Example 1 output (input in bold):
Enter filename: 2 grid20.txt
Enter the adjacent number: 4
Maximum 4-product in file "grid.txt"
Row 7 col 9: 26
Row 8col10:63
Row 9 col 11:78
Row 10col12:14
Max Product: 1788696
Note that the grid may be smaller or larger than 2020 but must always be a square
grid. If your program detects something other than a square grid, it should output an
error message. Also note that the user may request a "z" larger than the grid, in which
case your program should also output an error message.
grid3.txt
33
080222
494999
814931
Example 2 output (input in bold):
Enter filename: grid3.txt
Enter the adjacent number: 2
Maximum 2-product in file "grid.txt"
Row 1 col 1: 49
Row 1col2:99
Max Product: 4851
Please use "grid20.txt" and "grid3.txt" to test your program.
Submission detail:
Implement the program use either recursive or non-recursive method (70pt as
starting points)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions