This is a problem presented in the book on page 182. The Exercise is 5.7. (pleas
ID: 3676504 • 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
HAS to BE in visual basic windows form application, in visual studio 2012.
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
#include <iostream>
#include <conio.h>
#include <iomanip>
using namespace std;
int main()
{
//First Triangle
for (int i = 0; i <= 10; i++) //this prints stars as rows
{
for (int j = 0; j < 1; j++) //this prints stars as columns
{
if (j == i)
{
cout << "*";
}
else
{
cout << " ";
}
}
}
//Second triangle
for (int i = 0; i <= 10; i++) //this prints stars as rows
{
for (int j = 0; j < 1; j++) //this prints stars as columns
{
if (j == i)
{
cout << " ";
}
else
{
cout << "*";
}
}
}
//Third Triangle
for (int i = 0; i <= 10; i++) //this prints stars as rows
{
for (int j = 0; j < 1; j++) //this prints stars as columns
{
if (j == i)
{
cout << " ";
}
else
{
cout << "*";
}
}
}
//Fourth Triangle
for (int i = 0; i <= 10; i++) //this prints stars as rows
{
for (int j = 0; j < 1; j++) //this prints stars as columns
{
if (j == i)
{
cout << "*";
}
else
{
cout << " ";
}
}
}
_getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.