473,765 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4761


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******@gasca d.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*****@studen t.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******@gasca d.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
13881
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 maybe I'm still missing something obvious... I'm trying to have a <div> appear and disappear based on what a switchbox is set to. Having <div style="display: none;"> and then setting the display property to inline onChange works fine, but I...
5
8225
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 browser-agnostic (i.e., works with Netscape, version 4x, 7x, etc). My question is this: I have about 10 table rows, each tagged with a class attribute (<tr class="billing" style="display:none">) that I wish to make visible or invisible in response...
20
2597
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 selected ones visible. At the moment, I am doing it as follows: www.corstorphinehouse.com/d/avail.html
3
2125
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 was thinking of just using an unsigned int that increments for the cycling of bit patterns, but those only come in prescribed sizes. i was hoping for something more generic, that would allow for a 10bit pattern, for example. for the sub-pattern...
14
4340
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 like to just iterate through, say, rows 20 through 30. How can one do this?
31
1793
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 returns the rows with the 'New Value in it' shouldnt it be the values before I made the change or have I missed something. r = Ds1.Tables(0).Select(Nothing, Nothing, DataViewRowState.OriginalRows)
68
6826
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
8081
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 display. If they put a value in the text box in the second row then display the third row etc. etc. etc. to 10 rows. I'm pretty new to javascript, so I'm not to sure where to start. Any help would be great, thanks a lot.
11
1947
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 each row. If i select 5th & 6th row from first table then it should show only the 5th & 6th row from the second table. The rows are same in both table. Likewise the rows i select from first table should only display from the second table.. plz...
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10163
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9835
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.