[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Please solve this question

reepakmajhi.com@gmail.com

9/28/2008 1:36:00 PM

Write a c++ program to display the following?

# # # # #

K V Jharsuguda

# # # # #
8 Answers

Bo Persson

9/28/2008 3:26:00 PM

0

reepakmajhi.com@gmail.com wrote:
> Write a c++ program to display the following?
>
> # # # # #
>
> K V Jharsuguda
>
> # # # # #

#include <iostream>

int main()
{
std::cout << "the following?";
}


Bo Persson


Juha Nieminen

9/28/2008 6:39:00 PM

0

reepakmajhi.com@gmail.com wrote:
> Write a c++ program to display the following?
>
> # # # # #
>
> K V Jharsuguda
>
> # # # # #

int main()
{
const char* str =
"# # # # #\n"
"\n"
" K V Jharsuguda\n"
"\n"
"# # # # #\n";

std::cout << str;
}

jt

9/28/2008 6:43:00 PM

0

On Sun, 28 Sep 2008 06:36:15 -0700, reepakmajhi.com@gmail.com wrote:

> Write a c++ program to display the following?
>
> # # # # #
>
> K V Jharsuguda
>
> # # # # #

Ok, I've done that.

--
Lionel B

blargg.h4g

9/28/2008 7:34:00 PM

0

In article
<35856232-b85e-41d3-8e58-bd565264a56a@k36g2000pri.googlegroups.com>,
"reepakmajhi.com@gmail.com" <reepakmajhi.com@gmail.com> wrote:

> Write a c++ program to display the following?
>
> # # # # #
>
> K V Jharsuguda
>
> # # # # #

No.

red floyd

9/28/2008 11:06:00 PM

0

reepakmajhi.com@gmail.com wrote:
> [blatant do my homework request redacted]
Your answer can be found at

http://www.parashift.com/c++-faq-lite/how-to-post.ht...

osmium

9/29/2008 12:48:00 AM

0

<reepakmajhi.com@gmail.com> wrote:

> Write a c++ program to display the following?
>
> # # # # #

Look at the output; it prints a blob of characters, then prints another blob
and does this exactly 5 times. Since the number is constant and known when
the program is written, it strongly suggests a for loop. Now look at the
individual blobs. Each blob starts with a # and is followed by
approximately 11 spaces. We can't tell for sure about the last blob, but
assuming it is will not violate anything in the problem statement. again,
everything is known in advance, which suggests another for loop. You could
use nested for loops or have the outermost for call a function. The latter
approach will "hide" the nested aspect and may be easier to understand.


Jeff Schwab

9/29/2008 2:16:00 AM

0

reepakmajhi.com@gmail.com wrote:
> Write a c++ program to display the following?
>
> # # # # #
>
> K V Jharsuguda
>
> # # # # #

#include <algorithm>
#include <iostream>
#include <iterator>
#include <sstream>

int main() {

std::istringstream input_stream(
"23 20 20 20 20 20 20 20 20 20 20 20 23 20 20 20"
"20 20 20 20 20 20 20 20 20 23 20 20 20 20 20 20"
"20 20 20 20 20 23 20 20 20 20 20 20 20 20 20 20"
"20 23 0a 0a 20 20 20 20 20 20 20 20 20 20 4b 20"
"56 20 4a 68 61 72 73 75 67 75 64 61 0a 0a 23 20"
"20 20 20 20 20 20 20 20 20 23 20 20 20 20 20 20"
"20 20 20 20 20 20 23 20 20 20 20 20 20 20 20 20"
"20 20 23 20 20 20 20 20 20 20 20 20 20 20 23 0a" );

input_stream.flags(std::ios::hex | std::ios::skipws);

copy(
std::istream_iterator<unsigned>( input_stream ),
std::istream_iterator<unsigned>( ),
std::ostream_iterator<char>( std::cout ));

return 0;
}

James Kanze

9/29/2008 8:22:00 AM

0

On Sep 29, 4:15 am, Jeff Schwab <j...@schwabcenter.com> wrote:
> reepakmajhi....@gmail.com wrote:
> > Write a c++ program to display the following?

> > # # # # #

> > K V Jharsuguda

> > # # # # #

> #include <algorithm>
> #include <iostream>
> #include <iterator>
> #include <sstream>

> int main() {
>
> std::istringstream input_stream(
> "23 20 20 20 20 20 20 20 20 20 20 20 23 20 20 20"
> "20 20 20 20 20 20 20 20 20 23 20 20 20 20 20 20"
> "20 20 20 20 20 23 20 20 20 20 20 20 20 20 20 20"
> "20 23 0a 0a 20 20 20 20 20 20 20 20 20 20 4b 20"
> "56 20 4a 68 61 72 73 75 67 75 64 61 0a 0a 23 20"
> "20 20 20 20 20 20 20 20 20 23 20 20 20 20 20 20"
> "20 20 20 20 20 20 23 20 20 20 20 20 20 20 20 20"
> "20 20 23 20 20 20 20 20 20 20 20 20 20 20 23 0a" );

> input_stream.flags(std::ios::hex | std::ios::skipws);

> copy(
> std::istream_iterator<unsigned>( input_stream ),
> std::istream_iterator<unsigned>( ),
> std::ostream_iterator<char>( std::cout ));

> return 0;
> }

Did you actually try it? All you're doing is outputting your
string literal.

The obvious answer is something like:
std::cout
<< "# # # # #\n"
" K V Jharsuguda\n"
"# # # # #"
<< std::endl ;
But the answer is so obvious I suspect that tbe original poster
has some other additional requirements which he's chosen to hide
from us.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34