Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using C#: Create a program named DemoSquares that instantiates an array of 10 Sq

ID: 3668343 • Letter: U

Question

Using C#: Create a program named DemoSquares that instantiates an array of 10 Square objects with sides that have values of 1 through 10 and that displays the values for each Square. The Square class contains fields for area and the length of a side, and a constructor that requires a parameter for the length of one side of a Square. The constructor assigns its parameter to the length of the Square's side field and calls a private method that computes the area field. Also include read-only properties to get a Square's side and area.

Explanation / Answer

This is DemoSquare.ds using System; namespace DemoSquares { public class DemoSquares { public static void Main(string[] args) { Console.Title = "Demo Squares"; Console.WriteLine("Area and Side Length of Squares: "); Console.WriteLine("{0} {1} {2}", "#", "Side Length", "Area"); Square[] squares = new Square[11]; for (int i = 1; i < 10; i++) { squares[i] = new Square(i); Square currentSquare = squares[i]; Console.WriteLine("{0} {1,11} {2,4}", i, currentSquare.SideLength, currentSquare.Area); } Console.Read(); } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote