Menu

[solved]-Need Help Finishing Program Simple Magic Square Links External Site Numeric Square Numbers Q39063816

(Need help finishing program)

A simple magic square (Links to an external site.) is numeric asquare, such that the numbers in all rows and all columns sum tothe same constant. Each entry z in our magic square is calculatedusing the following formula “Z = ((x – (2 * (-y))) Mod Size)” wherex and y values are based on the size of the square. Magic squarescreated should be odd numbered and greater than zero. Often whenwriting commercial code, the customer brings in an application witha complaint or concern that they wish you to address. Many times,it is up to us to examine the application and come up with aproposal to satisfy the customer. They may not be computerscientists, so the hire us to find solutions to sometimes FUZZYcomplaints. Lets look at the following. The following code is anattempt to create a user friendly program that examines the userinput “Size” and attempts to prevent processing erroneous userinput while not crashing the application in the process. Whenrunning the program, the customer finds the results confusing whenthey mistakenly enter characters instead of numbers. Also, the userwants to be allowed to create as many squares as he or she wants.See what you can do to improve this example using what we havelearned throughout the course. We might consider a user friendlyway to inform the user of invalid entries. The program outputshould be neat and well blocked. Comment your code changes. Useyour imagination to create your custom solution. HINT: It wasnotices that when the word “Cat” for example is entered, the numberconverts to a zero. The president of the company noticed when thevalue “3blind mice” was entered, a square of size three wascreated.

Module Module1

Sub Main()

Dim x As Integer

Dim y As Integer

Dim Z As Integer

Dim strSize As String

Dim Size As Integer

Console.BackgroundColor = ConsoleColor.White

Console.ForegroundColor = ConsoleColor.DarkBlue

Console.Clear() Console.SetCursorPosition(25, 2)

Console.WriteLine(“CS_6 Magic Square Spactacular!”)

Console.SetCursorPosition(21, 4)

Console.Write(“Number of Chars Wide (Use Odd Nums): “)

‘Read as a string to prevent program crash when enteringletters

strSize = Console.ReadLine()

Size = Val(strSize)

‘Convert string to numberic value

Size = Math.Abs(Size) ‘Prevent negative values

If (Size Mod 2) = 0 Then ‘Force Size to be odd Size = Size + 1’Add 1 to even numbers

End If

‘Calculate the square and write to screen

For x = 0 To Size – 1

Console.SetCursorPosition(35, x + 6)

For y = 0 To Size – 1

Z = ((x – (2 * (-y))) Mod Size)

Console.Write(Z & ” “)

Next y

Console.WriteLine()

Next x

Console.ReadKey()

End Sub

End Module

Expert Answer


Answer to (Need help finishing program) A simple magic square (Links to an external site.) is numeric a square, such that the numb… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *