This is a problem presented in the book on page 182. The Exercise is 5.7. (pleas
ID: 3676492 • Letter: T
Question
This is a problem presented in the book on page 182. The Exercise is 5.7. (please see the pdf linked to this dropbox for information on the exact layout of the triangles and examples of program output, HTML does not reproduce the layout precisely). this is in visual basic programming 2012 EDITION: 6TH 14 PUBLISHER: PEARSON ISBN: 9780133406955
visual basic 2012 windows form application in visual studio.
5.7 (Triangles of Asterisks) Write a program that displays the following patters separately, one below the other in a TextBox. Use For..Next loops to generate the patterns. All asterisks (*) should be displayed one at a time by the statement outputTextBox.AppendText(“*”) (this causes the asterisks to display side by side). The statement outputTextBox.AppendText(vbCrLf) can be used to position to the next line, and a statement of the form outputTextBox.AppendText(“ “) can be used to display spaces for the last two patterns. There should be no other output statements in the program. [Hint: The last two patterns require that each line begin with an appropriate number of blanks.] Maximize your use of repetition (with nested For…Next statements) and minimize the number of output statements. Set the TextBox’s Font property to Lucida Console, its MultiLine property to True and its ScrollBars property to Vertical so that you can scroll through the results.
(a)
(b)
(c)
(d)
*
**
***
****
*****
******
*******
********
*********
**********
**********
*********
********
*******
******
*****
****
***
**
*
**********
*********
********
*******
******
*****
****
***
**
*
*
**
***
****
*****
******
*******
********
*********
**********
(a)
(b)
(c)
(d)
*
**
***
****
*****
******
*******
********
*********
**********
**********
*********
********
*******
******
*****
****
***
**
*
**********
*********
********
*******
******
*****
****
***
**
*
*
**
***
****
*****
******
*******
********
*********
**********
Explanation / Answer
Imports System
' Program prints four triangles, one below the other
Public Class Triangles
' draw four triangles
Public Overridable Sub drawTriangles()
Dim row As Integer ' the row position
Dim column As Integer ' the column position
Dim space As Integer ' number of spaces to print
' first triangle
For row = 1 To 10
For column = 1 To row
Console.Write("*")
Next column
Console.WriteLine()
Next row ' end for loop
Console.WriteLine()
' second triangle
For row = 10 To 1 Step -1
For column = 1 To row
Console.Write("*")
Next column
Console.WriteLine()
Next row ' end for loop
Console.WriteLine()
' third triangle
For row = 10 To 1 Step -1
For space = 10 To row + 1 Step -1
Console.Write(" ")
Next space
For column = 1 To row
Console.Write("*")
Next column
Console.WriteLine()
Next row ' end for loop
Console.WriteLine()
' fourth triangle
For row = 10 To 1 Step -1
For space = 1 To row - 1
Console.Write(" ")
Next space
For column = 10 To row Step -1
Console.Write("*")
Next column
Console.WriteLine()
Next row ' end for loop
End Sub ' end method drawTriangles
End Class ' end class Triangles
' Test application for class Triangles
Public Class TrianglesTest
Public Shared Sub Main(ByVal args() As String)
Dim application As New Triangles()
application.drawTriangles()
End Sub ' end main
End Class ' end class TrianglesTest
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.