public struct octagon { public float width; public float height; public float basewidth; public float baseheight; } // End of octagon structure |
private void btn10_Click(object sender, EventArgs e) { octagon Ok; // Make an octagon. :) Ok.width = 6f; // Sets wide width to 6f. btn10.Text = Ok.width.ToString(); // Display in button. } |
/// <summary> /// Structure which holds information to construct an octagon. /// </summary> public struct octagon { private float width; private float height; private float basewidth; private float baseheight; public void setvalues(float widthmax, float widthmin, float heightmax, float heightmin) { this.width = widthmax; this.height = heightmax; this.basewidth = widthmin; this.baseheight = heightmin; return; // Return is not necessary for subroutines. } // End of setvalues subroutine public float area() { return width * height - (width - basewidth) * (height - baseheight) * 0.5f; } // Area function calculates area of an octagon. } // End of octagon structure |
private void btn10_Click(object sender, EventArgs e) { octagon Ok = new octagon(); // Make a new octagon. :) Ok.setvalues(4f, 2f, 4f, 2f); // Set the values of the octagon. btn10.Text = Ok.area().ToString(); // Display the area of the octagon in the button. } |
/// <summary> /// Structure which holds information to construct an octagon. /// </summary> public struct octagon { private float width; private float height; private float basewidth; private float baseheight; public octagon(float widthmax, float widthmin, float heightmax, float heightmin) { this.width = widthmax; this.height = heightmax; this.basewidth = widthmin; this.baseheight = heightmin; } // End of setvalues subroutine public float area() { return width * height - (width - basewidth) * (height - baseheight) * 0.5f; } // Area function calculates area of an octagon. } // End of octagon structure |
private void btn10_Click(object sender, EventArgs e) { octagon Ok = new octagon(4f, 2f, 4f, 2f); // Make a new octagon. :) btn10.Text = Ok.area().ToString(); // Display the area of the octagon in the button. } |
public void Inflate() { // Stretches width and height of the octagon. this.width *= 2f; this.height *= 2f; this.basewidth *= 2f; this.baseheight *= 2f; return; } public void Inflate(float widthfactor, float heightfactor) { // Stretches width and height to the specified factor. this.width *= widthfactor; this.basewidth *= widthfactor; this.height *= heightfactor; this.baseheight *= heightfactor; return; } public void Inflate(float areafactor) { // Stretches octagon to increase area by specified factor. this.width *= ( float )Math.Sqrt(areafactor); this.basewidth *= ( float )Math.Sqrt(areafactor); this.height *= ( float )Math.Sqrt(areafactor); this.baseheight *= ( float )Math.Sqrt(areafactor); return; } |
public struct octagon : IComparable, IFormattable { private float width; private float height; private float basewidth; private float baseheight; public int CompareTo(object obj) { octagon test; if (obj is octagon) { test = ( octagon )obj; return this.area().CompareTo(test.area()); } else { return 0; } // End of if block to ensure obj is an octagon. }// End of IComparable's .CompareTo public string ToString(string format, IFormatProvider formatProvider) { return String.Format("Octagon: {0} by {1} with internal {2} by {3}.", width, height, basewidth, baseheight); } // End of octagon.ToString() |
private void btn10_Click(object sender, EventArgs e) { octagon Ok = new octagon(4f, 2f, 4f, 2f); // Make a new octagon. :) octagon[] Octies = new octagon[3]; // Three octagons in an array. Octies[0] = new octagon(6f, 3f, 4f, 2f); // This should be the biggest Octies[1] = Ok; // Followed by this one. Octies[2] = Octies[0]; // This one will be a copy of the first. Octies[2].Inflate(0.25f); // We will shrink it to 25% size. Array.Sort(Octies); // Then sort the array: this requires octagons to implement the IComparable interface. btn10.Text = String.Format("Winner {0}", Octies[2]); // Display the area of the octagon in the button. // Calling string.Format requires octagons to implement the IFormattable Interface. } // End of btn 10's click procedure. |