473,388 Members | 1,215 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,388 software developers and data experts.

String Streams

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
29 1767
DeMan
1,806 1GB
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
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
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
1,275 Expert 1GB
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
1,806 1GB
try here (cleverly titled something about asterix so you would automatically assume Goscinny and Udzero ;))
Jun 8 '07 #6
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
1,764 Expert 1GB
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
9,208 Expert Mod 8TB
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
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
9,208 Expert Mod 8TB
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
1,806 1GB
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
1,764 Expert 1GB
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
1,251 Expert 1GB
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
1,251 Expert 1GB
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
1,764 Expert 1GB
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
1,251 Expert 1GB
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
1,764 Expert 1GB
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
1,251 Expert 1GB
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
1,764 Expert 1GB
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
1,251 Expert 1GB
Oo moving up to higher level..

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


Adrian
Jun 9 '07 #21
Savage
1,764 Expert 1GB
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
1,806 1GB
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
1,764 Expert 1GB
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
1,251 Expert 1GB
DeMan u too?

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


Adrian
Jun 10 '07 #25
Savage
1,764 Expert 1GB
We are ganging up on ya. ;) Though we are WAY OT.


Adrian

Conspiracy!!

Savage
Jun 10 '07 #26
AdrianH
1,251 Expert 1GB
Conspiracy!!

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


Adrian
Jun 10 '07 #27
Savage
1,764 Expert 1GB
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
1,806 1GB
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
1,764 Expert 1GB
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

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

Similar topics

3
by: Michael Weir | last post by:
I'm sure this is a very simple thing to do, once you know how to do it, but I am having no fun at all trying to write utf-8 strings to a unicode file. Does anyone have a couple of lines of code...
0
by: Eugene | last post by:
I'm working on a program which needs to convert a string to various data types. I created a function using string streams and templates to do just that: template<typename T> bool...
5
by: Steve | last post by:
Hi, How can I convert a C++ string to an integer and then an integer back to a string? Is there built-in support for this? Thanks, Steve
5
by: ferran | last post by:
Hi, I'm trying to convert a string to a long double using streams but for some reasing seems to give the wrong values, the idea is to do a precise textual conversion without roundings or...
3
by: Tron Thomas | last post by:
What does binary mode for an ofstream object do anyway? Despite which mode the stream uses, operator << writes numeric value as their ASCII representation. I read on the Internet that it is...
4
by: rainmaker1234 | last post by:
Its very simple in VC++. In the followeing code I have declared a String, and a double than I am taking the string and converting it into Double. getch() at the end is only to pause the screen so...
1
by: Chris | last post by:
I'm reading up on streams and I have two articles that seem to conflict with each other. One article describes streams and lists a few of the major ones (FileStream, Memory Stream, Network...
25
by: electrixnow | last post by:
in MS VC++ Express I need to know how to get from one comma delimited text string to many strings. from this: main_string = "onE,Two,Three , fouR,five, six " to these: string1 =...
28
by: v4vijayakumar | last post by:
#include <string> #include <iostream> using namespace std; int main() { string str; str.resize(5); str = 't';
23
by: KIRAN | last post by:
Hi all, can i split a C string like this? char * p = "Hello \ World\n\r"; is this according to standard? Any help or link to standard regarding the above doubt is aprreciated... Regards, Kiran
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.