Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Please solve this question

0 views
Skip to first unread message

reepakm...@gmail.com

unread,
Sep 28, 2008, 9:36:15 AM9/28/08
to
Write a c++ program to display the following?

# # # # #

K V Jharsuguda

# # # # #

Bo Persson

unread,
Sep 28, 2008, 11:26:00 AM9/28/08
to

#include <iostream>

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


Bo Persson


Lionel B

unread,
Sep 28, 2008, 2:43:27 PM9/28/08
to

Ok, I've done that.

--
Lionel B

blargg

unread,
Sep 28, 2008, 3:34:13 PM9/28/08
to

red floyd

unread,
Sep 28, 2008, 7:05:32 PM9/28/08
to
reepakm...@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.html#faq-5.2

osmium

unread,
Sep 28, 2008, 8:47:31 PM9/28/08
to
<reepakm...@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

unread,
Sep 28, 2008, 10:15:33 PM9/28/08
to

#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

unread,
Sep 29, 2008, 4:21:39 AM9/29/08
to
On Sep 29, 4:15 am, Jeff Schwab <j...@schwabcenter.com> wrote:

> > K V Jharsuguda

> 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...@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

Juha Nieminen

unread,
Sep 28, 2008, 2:38:38 PM9/28/08
to

int main()
{
const char* str =
"# # # # #\n"


"\n"
" K V Jharsuguda\n"

"\n"
"# # # # #\n";

std::cout << str;
}

0 new messages