473,395 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Rows: display a pattern that increments in each row

Hi
I'm a newbie and want to display a pattern that will increment with each
line of display.
I thought i might be able to count the rows and use that info to increment
my display.
I've got my starting point using setw and don't want to use cout for every
line of display. What should i be looking for to use.
Thanks
Jul 19 '05 #1
4 4744


Nicolla MacPherson wrote:

Hi
I'm a newbie and want to display a pattern that will increment with each
line of display.
what pattern?
I thought i might be able to count the rows and use that info to increment
my display.
You might. It depends on the pattern.
I've got my starting point using setw and don't want to use cout for every
line of display. What should i be looking for to use.


Using cout for every single line is the easiest thing you could do, *if*
your pattern is that way. It all depends on what the pattern looks like.
If your pattern is such that you can derive some formula from the line count,
then things are going the easy way.

Example: You have to produce this pattern:

*
***
*****
*******
*********

So what do you recognize? Every line consists of spaces followed
by '*' characters. How many are in each line? Lets make a table:

line # | # of spaces # of asteriks
---------+-----------------------------
0 | 5 1
1 | 4 3
2 | 3 5
3 | 2 7
4 | 1 9

Now can you come up with some formulas that emit the
number of spaces when given the line number? What about
the number of asteriks?

#_of_spaces = 5 - line_#
#_of_asteriks = 2 * line_# + 1

So your output loop basically looks like this

for( line = 0; line < 5; ++line )
{
compute NrOfSpaces as 5 - line
compute NrOfAsteriks as 2 * line + 1

output NrOfSpaces ' '
output NrOfAsteriks '*'

output '\n'
}

And thats it for this specific pattern.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #2
Nicolla

If you could draw some of the pattern or just post the homework question...
:-) .... that would help.

Pete

"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:3F***************@gascad.at...


Nicolla MacPherson wrote:

Hi
I'm a newbie and want to display a pattern that will increment with each
line of display.
what pattern?
I thought i might be able to count the rows and use that info to increment my display.


You might. It depends on the pattern.
I've got my starting point using setw and don't want to use cout for every line of display. What should i be looking for to use.


Using cout for every single line is the easiest thing you could do, *if*
your pattern is that way. It all depends on what the pattern looks like.
If your pattern is such that you can derive some formula from the line

count, then things are going the easy way.

Example: You have to produce this pattern:

*
***
*****
*******
*********

So what do you recognize? Every line consists of spaces followed
by '*' characters. How many are in each line? Lets make a table:

line # | # of spaces # of asteriks
---------+-----------------------------
0 | 5 1
1 | 4 3
2 | 3 5
3 | 2 7
4 | 1 9

Now can you come up with some formulas that emit the
number of spaces when given the line number? What about
the number of asteriks?

#_of_spaces = 5 - line_#
#_of_asteriks = 2 * line_# + 1

So your output loop basically looks like this

for( line = 0; line < 5; ++line )
{
compute NrOfSpaces as 5 - line
compute NrOfAsteriks as 2 * line + 1

output NrOfSpaces ' '
output NrOfAsteriks '*'

output '\n'
}

And thats it for this specific pattern.

--
Karl Heinz Buchegger
kb******@gascad.at

Jul 19 '05 #3
Hi Pete
this is my code so far what i'm having trouble with is that the pyramid code
has to include 2 for loops. But i just can't display the lines individually
with out using cout all the time. If you can just give me some pointers as
to what i'm doing wrong as I can't copy anyones code.
Cheers

Nicolla

#include <iostream> //For cin, cout

#include <iomanip> //For setw()

using namespace std;

const maxLines = 20;
const maxColumns = 1;
void main (void)
{
int line=0;
int numCarats =0;
char carat ='^';

cout <<"\n\n\n"; //Move down the screen 3 lines
cout <<setw(40) <<carat <<endl; //Define where to start with the display

// while (numCarats <= 19) numCarats !=19; numCarats++)
// {
// cout <<'^';
// }


for (line = 4;line < 16; ++line) //number of lines to be displayed
{

//width for column

cout.width (40);
//position left side characters within the column

cout <<setw(39) <<carat <<resetiosflags(ios::left)<< setw(1) <<carat;

//Fill the left side, allows blank space to be entered before the carat
amount entered
//This allows for the carats to be right justified

cout.fill (' ');
cout <<carat <<endl;
cout <<setw(38) <<carat <<resetiosflags(ios::left)<< setw(1) <<carat ;
cout.fill (' ');
cout <<carat <<endl;
}


}

"Pete" <s3*****@student.uq.edu.au> wrote in message
news:bh**********@bunyip.cc.uq.edu.au...
Nicolla

If you could draw some of the pattern or just post the homework question... :-) .... that would help.

Pete

"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:3F***************@gascad.at...


Nicolla MacPherson wrote:

Hi
I'm a newbie and want to display a pattern that will increment with each line of display.


what pattern?
I thought i might be able to count the rows and use that info to increment my display.


You might. It depends on the pattern.
I've got my starting point using setw and don't want to use cout for every line of display. What should i be looking for to use.


Using cout for every single line is the easiest thing you could do, *if*
your pattern is that way. It all depends on what the pattern looks like.
If your pattern is such that you can derive some formula from the line

count,
then things are going the easy way.

Example: You have to produce this pattern:

*
***
*****
*******
*********

So what do you recognize? Every line consists of spaces followed
by '*' characters. How many are in each line? Lets make a table:

line # | # of spaces # of asteriks
---------+-----------------------------
0 | 5 1
1 | 4 3
2 | 3 5
3 | 2 7
4 | 1 9

Now can you come up with some formulas that emit the
number of spaces when given the line number? What about
the number of asteriks?

#_of_spaces = 5 - line_#
#_of_asteriks = 2 * line_# + 1

So your output loop basically looks like this

for( line = 0; line < 5; ++line )
{
compute NrOfSpaces as 5 - line
compute NrOfAsteriks as 2 * line + 1

output NrOfSpaces ' '
output NrOfAsteriks '*'

output '\n'
}

And thats it for this specific pattern.

--
Karl Heinz Buchegger
kb******@gascad.at


Jul 19 '05 #4


Nicolla wrote:

Hi Pete
this is my code so far what i'm having trouble with is that the pyramid code
has to include 2 for loops.
Well. If you need 2 loops, you need 2 loops.
BTW: I don't see 2 loops in the posted code, only 1
But i just can't display the lines individually
with out using cout all the time.
Indeed. You do a lot of things with cout in your loop.
I haven't analyzed it completely, but just by looking
at it it seems to much. Try to simplify it.
If you can just give me some pointers as
to what i'm doing wrong as I can't copy anyones code.


Well. For this to know, we would need to know your goal.
That is: what does the pattern look like you have to produce.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: endus | last post by:
I'm having some trouble getting something to work. I'm not even sure whether or not this is possible, but it *seems* like it should be. I've done a fair amount of experimenting and googling...but...
5
by: Harry Gould | last post by:
To all, I'm a newbie here, so please bear with me. I develop web pages for a company intranet where Internet Explorer 6 is the standard. Now I must develop a public internet website that is...
20
by: WindAndWaves | last post by:
Hi Gurus I was wondering if you can send me in the right direction: I have a table with about 300 rows. I want to make all of them invisible and when a user enters a code in a form then make...
3
by: jason | last post by:
is there a way to set up an array of bits of generic size, cycle through all the possible bit patterns, and detect a sub-pattern within the bit pattern? for cycling through possible patterns: i...
14
by: Jacko | last post by:
Hi guys, Say I made a SELECT statement to my sql DB that would return 50 rows that I will use a sqldatareader to access. Instead of iterating through each and every row of the datareader, I'd...
31
by: One Handed Man \( OHM - Terry Burns \) | last post by:
My Brain is dead !!!!! I modify a single row in a DataTable By setting the FirstName column in a specific row to another name. ( Without Accepting Changes ). However, this statement still...
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
11
by: jimstruckster | last post by:
I have a table with 10 rows, I want all rows except for the first to be hidden when the page first opens up. If the user puts a value in a text box in the first row then I want the second row to...
11
by: sanju | last post by:
Hi all, I am new in the world of javascript. Someone plz help me. I have two tables containing 30 rows each. In first table there is checkbox and in the second table there is radio buttons ahead...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.