What does Accelerated C++ exercise 5-5 mean?

L

Lambda

I'm trying to complete all the exercises of Accelerated C++.

I'm not sure what does the exercise 5-5 mean. And how about 5-9?

Thanks
 
U

utab

I'm trying to complete all the exercises of Accelerated C++.

I'm not sure what does the exercise 5-5 mean. And how about 5-9?

Thanks

That is quite obvious from the text I guess ;)

Let me explain, there are some functions given in chapter 5 to frame
and concatenate some text, this is an extension of those functions.

+ You should write the text centered in the frame. Hint: think about
how can a text can be centered in a frame. And this will also answer
the question if this is possible or not.

+ for 5.9 lets say you keep the words in a vector:

try
TRY
accelerated
ACCELERATED

so the new order should be

accelerated
try
TRY
ACCELERATED

Hint you might use a function "isupper" or "islower" from cctype

HTH,
 
L

Lambda

That is quite obvious from the text I guess ;)

Let me explain, there are some functions given in chapter 5 to frame
and concatenate some text, this is an extension of those functions.

+ You should write the text centered in the frame. Hint: think about
how can a text can be centered in a frame. And this will also answer
the question if this is possible or not.

Does that mean convert
**************
* this is an *
* example *
* to *
* illustrate *
* framing *
**************
to
**************
* this is an *
* example *
* to *
* illustrate *
* framing *
**************
?
It's always possible except for strings that is too long,
for example, more than 80 characters.
+ for 5.9 lets say you keep the words in a vector:

try
TRY
accelerated
ACCELERATED

so the new order should be

accelerated
try
TRY
ACCELERATED

Hint you might use a function "isupper" or "islower" from cctype

The question does not mention the order inside the upper and lower
groups.
I think I just need to separate the input to two groups, right?

I can always get usefull information from this group, thank you utab.
 
U

utab

Does that mean convert
**************
* this is an *
* example *
* to *
* illustrate *
* framing *
**************
to
**************
* this is an *
* example *
* to *
* illustrate *
* framing *
**************
?
It's always possible except for strings that is too long,
for example, more than 80 characters.

Ok of course it is limited. a sample output which also gives
indications if the lines could be centered or not:

Info for the lines whether they can be centered or not
Line 1 can be centered
Line 2 can be centered
Line 3 can not be centered
Line 4 can not be centered
Line 5 can not be centered
*********************************************************************************************
* this is a good this is a good this is a good this is a good this is
a good this is a good *
*
example *
*
to *
*
illustrate *
* centered
framing *
*********************************************************************************************

Ok you are done. Concerning its feasibility for evenness: there are
things to check there are two '*' chararacters
on the text part of the picture. So a simple algebra should lead to
somewhere right, for instance;

Lets say: the string is "Hello lambda, how are you?" consists of 26
chars.

If this is the longest one in the whole text you are using, then the
adjustment should be done to accommodate this fact, which you solved
above. To adjust a string of length, say 14 chars, what do you do?

How many spacings should be on the right and left?
if you have a string of 15 chars, then is it possible? (This was meant
I guess by the feasibility ;) )
The question does not mention the order inside the upper and lower
groups.
I think I just need to separate the input to two groups, right?

That was what I understood but Andrew Koenig also sometimes seems to
post and answer questions on his book, if you are lucky or I am lucky,
he can leave a message ;)
 
U

utab

Ok of course it is limited. a sample output which also gives
indications if the lines could be centered or not:

Info for the lines whether they can be centered or not
Line 1 can be centered
Line 2 can be centered
Line 3 can not be centered
Line 4 can not be centered
Line 5 can not be centered
*********************************************************************************************
* this is a good this is a good this is a good this is a good this is
a good this is a good *
*
example *
*
to *
*
illustrate *
* centered
framing *
*********************************************************************************************

Ok you are done. Concerning its feasibility for evenness: there are
things to check there are two '*' chararacters
on the text part of the picture. So a simple algebra should lead to
somewhere right, for instance;

Lets say: the string is "Hello lambda, how are you?" consists of 26
chars.

If this is the longest one in the whole text you are using, then the
adjustment should be done to accommodate this fact, which you solved
above. To adjust a string of length, say 14 chars, what do you do?

How many spacings should be on the right and left?
if you have a string of 15 chars, then is it possible? (This was meant
I guess by the feasibility ;) )







That was what I understood but Andrew Koenig also sometimes seems to
post and answer questions on his book, if you are lucky or I am lucky,
he can leave a message ;)






You are welcome !

Sorry for the output it can still be used for relatively long strings.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top