By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,849 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,849 IT Pros & Developers. It's quick & easy.

String Streams

P: 28
Hello everyone...

I have the following problem and i have no idea how to do it.
Can anyone help?

Write a procedure that takes a string as its parameter and which prints out a pattern made out of the string. For example, given the string "XMAS", it would output the following:

X
MM
AAA
SSSS
Jun 8 '07 #1
Share this Question
Share on Google+
29 Replies


DeMan
100+
P: 1,806
You might like to look under the Articles section for c/c++. I believ AdrianH has posted some tutorials how to make patterns from asterisks. I would imagine that would help you to get started, and give you an idea of how to create the pattern!
Jun 8 '07 #2

P: 28
Hello everyone...

I have the following problem and i have no idea how to do it.
Can anyone help?

Write a procedure that takes a string as its parameter and which prints out a pattern made out of the string. For example, given the string "XMAS", it would output the following:

X
MM
AAA
SSSS
I am using C++ and compiler DevC++.



thanks
Jun 8 '07 #3

P: 28
I am trying to find the tutorial that you are talking but i can't can you give me some info or the link please?


thnx
Jun 8 '07 #4

gpraghuram
Expert 100+
P: 1,275
Hi,
You can write a function which takes the character to print and the position of the character and you can print the character that many number of times.

<code removed as per posting guidelines>

Since this is small part i have posted the code....if it against posting guidelines the sorry about that and please remove it.

Raghuram
Jun 8 '07 #5

DeMan
100+
P: 1,806
try here (cleverly titled something about asterix so you would automatically assume Goscinny and Udzero ;))
Jun 8 '07 #6

P: 28
Hello everyone!

thank you for your replies..i tried by myself and i wrote the following piece of code. But i can't compile it. Can anyone tell me what is wrong with my code?
thnx

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int main()
  5. {
  6.  
  7. int counter,i,y;
  8. char text[30];
  9. cout << "Please enter a string : ";
  10. int couter =0;
  11. while ((text[counter]!= '\n') && (counter<30)){
  12. cin>> text[counter++];
  13. }
  14. for (i=0;i<counter; i++)
  15. {    
  16.     for(y=0;y<=i;y++)
  17.      {
  18.     cout << text[i];
  19.     }
  20.     cout << '\n' ;
  21. }
  22. }
Jun 8 '07 #7

Savage
Expert 100+
P: 1,764
try here (cleverly titled something about asterix so you would automatically assume Goscinny and Udzero ;))
Ehm,is there a problem with the title.

PS:I forgot to ask:

Can u,or someone else, please change it to asterisks?

Savage
Jun 8 '07 #8

weaknessforcats
Expert Mod 5K+
P: 9,197
To print this:

X
MM
AAA
SSSS

using an array just recognize that the number of times to display the character is the array element number + 1.

Just write an outer loop that counts from 0 to the end of the array

Then write an inner loops that runs from 0 to the count+1 of the outer loop. You display the character in this inner loop.
Jun 8 '07 #9

P: 28
I am sorry but i don't understand you. I think that i have done what you suggest in my code. and still i don't understand why my code doesn't work.it seems ok to me.

Can you be more specific please...

thx
Jun 8 '07 #10

weaknessforcats
Expert Mod 5K+
P: 9,197
This code:
Expand|Select|Wrap|Line Numbers
  1. cout << text[i];
  2.  
maybve should be
Expand|Select|Wrap|Line Numbers
  1. cout << text[y];
  2.  
Here's what I did:
Expand|Select|Wrap|Line Numbers
  1. char msg[] = "XMAS";
  2.  for(int i =0; i < 4; ++i)
  3.  {
  4.      for(int j = 0; j <  i + 1;++j)
  5.      {
  6.           cout << msg[i];
  7.      }
  8.            cout <<endl;
  9.  }
  10.  
which is what I think you meant to do.
Jun 8 '07 #11

DeMan
100+
P: 1,806
Ehm,is there a problem with the title.

PS:I forgot to ask:

Can u,or someone else, please change it to asterisks?

Savage
NO problem with your title......Sorry, I thought you had concealed a joke in there (and I can't change it - i don't have my magic powers in here)

BTW: I'm terribly sorry, I gave AdrianH credit for that one......you can kill me next time.....
Jun 8 '07 #12

Savage
Expert 100+
P: 1,764
NO problem with your title......Sorry, I thought you had concealed a joke in there (and I can't change it - i don't have my magic powers in here)

BTW: I'm terribly sorry, I gave AdrianH credit for that one......you can kill me next time.....
NO problem!!

I did concealed a joke,but maybe someone finds it stupid..

Savage
Jun 9 '07 #13

AdrianH
Expert 100+
P: 1,251
You might like to look under the Articles section for c/c++. I believ AdrianH has posted some tutorials how to make patterns from asterisks. I would imagine that would help you to get started, and give you an idea of how to create the pattern!
No, that was Savage.


Adrian
Jun 9 '07 #14

AdrianH
Expert 100+
P: 1,251
NO problem!!

I did concealed a joke,but maybe someone finds it stupid..

Savage
Are you referring to the Asterix comix? I loved those. :)


Adrian
Jun 9 '07 #15

Savage
Expert 100+
P: 1,764
Are you referring to the Asterix comix? I loved those. :)


Adrian
U love asterix comics?

Are u on crack again?

Savage
Jun 9 '07 #16

AdrianH
Expert 100+
P: 1,251
U love asterix comics?

Are u on crack again?

Savage
No, why? :p They were great. Asterix, Obolix beating up all those Romans. And the names:
  • getafix (the druid)
  • vitalstatistix and his wife impedimenta
  • cacophonix (the bard)
  • fullioautomatix (ironmonger)
  • nhygenix (the fish monger)
  • geriatrix (the old guy)
Take a look at them and tell me there not funny. lol :D


Adrian
Jun 9 '07 #17

Savage
Expert 100+
P: 1,764
No, why? :p They were great. Asterix, Obolix beating up all those Romans. And the names:
  • getafix (the druid)
  • vitalstatistix and his wife impedimenta
  • cacophonix (the bard)
  • fullioautomatix (ironmonger)
  • nhygenix (the fish monger)
  • geriatrix (the old guy)
Take a look at them and tell me there not funny. lol :D


Adrian
Everything is funny when u are on crack.Just don't think that u can fly.

Savage
Jun 9 '07 #18

AdrianH
Expert 100+
P: 1,251
Everything is funny when u are on crack.Just don't think that u can fly.

Savage
I think that the crack joke is getting old Savage. Just drink your potion and beat up some Romans. ;)


Adrian
Jun 9 '07 #19

Savage
Expert 100+
P: 1,764
I think that the crack joke is getting old Savage. Just drink your potion and beat up some Romans. ;)


Adrian
Oo moving up to higher level..

Savage
Jun 9 '07 #20

AdrianH
Expert 100+
P: 1,251
Oo moving up to higher level..

Savage
That's what happens when your 100 points behind. :D ;)


Adrian
Jun 9 '07 #21

Savage
Expert 100+
P: 1,764
That's what happens when your 100 points behind. :D ;)


Adrian
We have yet to see about this..

Also u have joined 24 days before me :p

Savage
Jun 9 '07 #22

DeMan
100+
P: 1,806
No, why? :p They were great. Asterix, Obolix beating up all those Romans. And the names:
  • getafix (the druid)
  • vitalstatistix and his wife impedimenta
  • cacophonix (the bard)
  • fullioautomatix (ironmonger)
  • nhygenix (the fish monger)
  • geriatrix (the old guy)
Take a look at them and tell me there not funny. lol :D


Adrian
And impedimenta - (vitalstatistix's wife, ->took me a while for the penny to drop on that one, though)

Not forgetting some of the people they encounter on their journeys.....to me that was (is?) one of the charms of the Asterix comics, trying to decipher what the names of the characters actually meant.....
Jun 9 '07 #23

Savage
Expert 100+
P: 1,764
And impedimenta - (vitalstatistix's wife, ->took me a while for the penny to drop on that one, though)

Not forgetting some of the people they encounter on their journeys.....to me that was (is?) one of the charms of the Asterix comics, trying to decipher what the names of the characters actually meant.....
DeMan u too?

Savage
Jun 10 '07 #24

AdrianH
Expert 100+
P: 1,251
DeMan u too?

Savage
We are ganging up on ya. ;) Though we are WAY OT.


Adrian
Jun 10 '07 #25

Savage
Expert 100+
P: 1,764
We are ganging up on ya. ;) Though we are WAY OT.


Adrian

Conspiracy!!

Savage
Jun 10 '07 #26

AdrianH
Expert 100+
P: 1,251
Conspiracy!!

Savage
You just want to get your points up past mine. :p


Adrian
Jun 10 '07 #27

Savage
Expert 100+
P: 1,764
You just want to get your points up past mine. :p


Adrian
And u just want to keep me down.

:P

Savage
Jun 10 '07 #28

DeMan
100+
P: 1,806
No TV in my house 'til I was 13 - I was virtually brought up by Asterix & Tintin - now both available in DVD format (although I think only about 6 Asterix's have been released)
Jun 11 '07 #29

Savage
Expert 100+
P: 1,764
No TV in my house 'til I was 13 - I was virtually brought up by Asterix & Tintin - now both available in DVD format (although I think only about 6 Asterix's have been released)
U are a big fan,aren't u?

Savage
Jun 11 '07 #30

Post your reply

Sign in to post your reply or Sign up for a free account.